Example #1
0
 /**
  * Returns an HTML block with the notice, as found in the
  * home/home_notice_[lang].html file
  * @return string HTML <div> block
  * @assert () != ''
  */
 public function returnNotice()
 {
     $sys_path = api_get_path(SYS_PATH);
     $user_selected_language = api_get_interface_language();
     $home = api_get_home_path();
     // Notice
     $home_notice = @(string) file_get_contents($sys_path . $home . 'home_notice_' . $user_selected_language . '.html');
     if (empty($home_notice)) {
         $home_notice = @(string) file_get_contents($sys_path . $home . 'home_notice.html');
     }
     if (!empty($home_notice)) {
         $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
         $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
         $this->show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
     }
 }
        echo 'Error in database with email ' . $mail . "\n";
    }
    if (Database::num_rows($res) == 0) {
        echo '[Error] Email not found in database: ' . $row['email'] . "\n";
    } else {
        $row = Database::fetch_assoc($res);
        $pass = api_substr($row['username'], 0, 4) . rand(0, 9) . rand(0, 9);
        if ($user) {
            /** @var User $user */
            $user = $repository->find($row['user_id']);
            $user->setPlainPassword($pass);
            $userManager->updateUser($user, true);
        } else {
            echo "[Error] Error updating password. Skipping {$mail}\n";
            continue;
        }
        $user = array('FirstName' => $row['firstname'], 'LastName' => $row['lastname'], 'UserName' => $row['username'], 'Password' => $pass, 'Email' => $mail);
        $l = api_get_interface_language();
        if (!empty($row['language'])) {
            $l = $row['language'];
        }
        //This comes from main/admin/user_import.php::save_data() slightly modified
        $recipient_name = api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS);
        $emailsubject = '[' . api_get_setting('siteName') . '] ' . get_lang('YourReg', null, $l) . ' ' . api_get_setting('siteName');
        $emailbody = get_lang('Dear', null, $l) . ' ' . api_get_person_name($user['FirstName'], $user['LastName']) . ",\n\n" . get_lang('YouAreReg', null, $l) . " " . api_get_setting('siteName') . " " . get_lang('WithTheFollowingSettings', null, $l) . "\n\n" . get_lang('Username', null, $l) . " : " . $user['UserName'] . "\n" . get_lang('Pass', null, $l) . " : " . $user['Password'] . "\n\n" . get_lang('Address', null, $l) . " " . api_get_setting('siteName') . " " . get_lang('Is', null, $l) . " : " . api_get_path(WEB_PATH) . " \n\n" . get_lang('Problem', null, $l) . "\n\n" . get_lang('Formula', null, $l) . ",\n\n" . api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')) . "\n" . get_lang('Manager', null, $l) . " " . api_get_setting('siteName') . "\nT. " . api_get_setting('administratorTelephone') . "\n" . get_lang('Email', null, $l) . " : " . api_get_setting('emailAdministrator') . "";
        $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');
        @api_mail_html($recipient_name, $user['Email'], $emailsubject, $emailbody, $sender_name, $email_admin);
        echo "[OK] Sent to {$mail} with new password {$pass} (encrypted:{$crypass})... w/ subject: {$emailsubject}\n";
    }
}
 /**
  * Displays announcements as an slideshow
  * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
  * @param int $id The identifier of the announcement to display
  */
 public static function display_announcements_slider($visible, $id = null)
 {
     $user_selected_language = Database::escape_string(api_get_interface_language());
     $table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
     $cut_size = 500;
     $now = api_get_utc_datetime();
     $sql = "SELECT * FROM " . $table . "\n\t\t\t\tWHERE ( lang = '{$user_selected_language}' OR lang IS NULL) AND ( '{$now}' >= date_start AND '{$now}' <= date_end) ";
     switch ($visible) {
         case self::VISIBLE_GUEST:
             $sql .= " AND visible_guest = 1 ";
             break;
         case self::VISIBLE_STUDENT:
             $sql .= " AND visible_student = 1 ";
             break;
         case self::VISIBLE_TEACHER:
             $sql .= " AND visible_teacher = 1 ";
             break;
     }
     if (isset($id) && !empty($id)) {
         $id = intval($id);
         $sql .= " AND id = {$id} ";
     }
     if (api_is_multiple_url_enabled()) {
         $current_url_id = api_get_current_access_url_id();
         $sql .= " AND access_url_id IN ('1', '{$current_url_id}') ";
     }
     $sql .= " ORDER BY date_start DESC";
     $announcements = Database::query($sql);
     $html = '';
     if (Database::num_rows($announcements) > 0) {
         $html .= Display::page_header(get_lang('SystemAnnouncements'));
         $html .= '<div id="container-slider" class="span6"><ul id="slider">';
         while ($announcement = Database::fetch_object($announcements)) {
             $content = $announcement->content;
             $url = api_get_path(WEB_PUBLIC_PATH) . 'news/' . $announcement->id;
             if (empty($id)) {
                 if (api_strlen(strip_tags($content)) > $cut_size) {
                     $content = Text::cut($announcement->content, $cut_size) . ' ' . Display::url(get_lang('More'), $url);
                 }
             }
             $html .= '<li><h2>' . $announcement->title . '</h2>' . $content . '</li>';
         }
         $html .= '</ul></div>';
     }
     return $html;
 }
Example #4
0
function custompages_get_lang($variable)
{
    return get_lang($variable, null, $_SESSION['user_language_choice']);
}
$language_file = array('courses', 'index', 'registration', 'admin', 'userInfo');
$available_langs = array('en', 'fr', 'es');
$chamilo_langs = array(null => 'english', 'en' => 'english', 'fr' => 'french', 'nl' => 'dutch', 'de' => 'german', 'es' => 'spanish');
$lang_match = $chamilo_langs[get_preferred_language($available_langs)];
// recover previous value ...
if (isset($_SESSION['user_language_choice'])) {
    $lang_match = $_SESSION['user_language_choice'];
}
// Chamilo parameter, on logout
if (isset($_REQUEST['language']) && !empty($_REQUEST['language']) && in_array($_REQUEST['language'], $chamilo_langs)) {
    $lang_match = $_REQUEST['language'];
}
// Incoming link parameter
if (isset($_REQUEST['lang']) && !empty($_REQUEST['lang']) && in_array($_REQUEST['lang'], $available_langs)) {
    $lang_match = $chamilo_langs[$_REQUEST['lang']];
}
global $_configuration;
if (isset($_configuration['auto_detect_language_custom_pages']) && $_configuration['auto_detect_language_custom_pages'] == true) {
    // Auto detect
    $_user['language'] = $lang_match;
    $_SESSION['user_language_choice'] = $lang_match;
} else {
    // Chamilo default platform.
    $defaultLanguage = api_get_interface_language();
    $_user['language'] = $defaultLanguage;
    $_SESSION['user_language_choice'] = $defaultLanguage;
}
/**
 * Returns isocode (see api_get_language_isocode()) which is purified accordingly to
 * be used by the php intl extension (ICU library).
 * @param string $language (optional)	This is the name of the folder containing translations for the corresponding language.
 * If $language is omitted, interface language is assumed then.
 * @return string						The found language locale id or null on error. Examples: bg, en, pt_BR, ...
 */
function _api_get_locale_from_language($language = null)
{
    static $locale = array();
    if (empty($language)) {
        $language = api_get_interface_language();
    }
    if (!isset($locale[$language])) {
        $locale[$language] = str_replace('-', '_', api_get_language_isocode($language));
    }
    return $locale[$language];
}
Example #6
0
 // Moved here to include extra fields when creating a user. Formerly placed after user creation
 // Register extra fields
 $extras = array();
 foreach ($values as $key => $value) {
     if (substr($key, 0, 6) == 'extra_') {
         //an extra field
         $extras[substr($key, 6)] = $value;
     } elseif (strpos($key, 'remove_extra_') !== false) {
         $extra_value = Security::filter_filename(urldecode(key($value)));
         // To remove from user_field_value and folder
         UserManager::update_extra_field_value($user_id, substr($key, 13), $extra_value);
     }
 }
 $status = isset($values['status']) ? $values['status'] : STUDENT;
 $phone = isset($values['phone']) ? $values['phone'] : null;
 $values['language'] = isset($values['language']) ? $values['language'] : api_get_interface_language();
 // Creates a new user
 $user_id = UserManager::create_user($values['firstname'], $values['lastname'], $status, $values['email'], $values['username'], $values['pass1'], $values['official_code'], $values['language'], $phone, null, PLATFORM_AUTH_SOURCE, null, 1, 0, $extras, null, true);
 //update the extra fields
 $count_extra_field = count($extras);
 if ($count_extra_field > 0) {
     foreach ($extras as $key => $value) {
         // For array $value -> if exists key 'tmp_name' then must not be empty
         // This avoid delete from user field value table when doesn't upload a file
         if (is_array($value)) {
             if (array_key_exists('tmp_name', $value) && empty($value['tmp_name'])) {
                 //Nothing to do
             } else {
                 if (array_key_exists('tmp_name', $value)) {
                     $value['tmp_name'] = Security::filter_filename($value['tmp_name']);
                 }
 /**
  * Get the HTML code for an announcement
  * @param int $announcementId The announcement ID
  * @param int $visibility The announcement visibility
  * @return string The HTML code
  */
 public static function displayAnnouncement($announcementId, $visibility)
 {
     $selectedUserLanguage = Database::escape_string(api_get_interface_language());
     $announcementTable = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
     $now = api_get_utc_datetime();
     $whereConditions = ["(lang = ? OR lang IS NULL) " => $selectedUserLanguage, "AND (? >= date_start AND ? <= date_end) " => [$now, $now], "AND id = ? " => intval($announcementId)];
     switch ($visibility) {
         case self::VISIBLE_GUEST:
             $whereConditions["AND visible_guest = ? "] = 1;
             break;
         case self::VISIBLE_STUDENT:
             $whereConditions["AND visible_student = ? "] = 1;
             break;
         case self::VISIBLE_TEACHER:
             $whereConditions["AND visible_teacher = ? "] = 1;
             break;
     }
     if (api_is_multiple_url_enabled()) {
         $whereConditions["AND access_url_id IN (1, ?) "] = api_get_current_access_url_id();
     }
     $announcement = Database::select("*", $announcementTable, ["where" => $whereConditions, "order" => "date_start"], 'first');
     $template = new Template(null, false, false);
     $template->assign('announcement', $announcement);
     return $template->fetch('default/announcement/view.tpl');
 }
Example #8
0
        $emailForm = $_SERVER['SERVER_ADMIN'];
    }
    $email_parts = explode('@', $emailForm);
    if (isset($email_parts[1]) && $email_parts[1] == 'localhost') {
        $emailForm .= '.localdomain';
    }
    $adminLastName = get_lang('DefaultInstallAdminLastname');
    $adminFirstName = get_lang('DefaultInstallAdminFirstname');
    $loginForm = 'admin';
    $passForm = api_generate_password();
    $campusForm = 'My campus';
    $educationForm = 'Albert Einstein';
    $adminPhoneForm = '(000) 001 02 03';
    $institutionForm = 'My Organisation';
    $institutionUrlForm = 'http://www.chamilo.org';
    $languageForm = api_get_interface_language();
    $checkEmailByHashSent = 0;
    $ShowEmailNotCheckedToStudent = 1;
    $userMailCanBeEmpty = 1;
    $allowSelfReg = 1;
    $allowSelfRegProf = 1;
    $encryptPassForm = 'sha1';
    $session_lifetime = 360000;
    if (!empty($_GET['profile'])) {
        $installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES);
    }
} else {
    foreach ($_POST as $key => $val) {
        $magic_quotes_gpc = ini_get('magic_quotes_gpc');
        if (is_string($val)) {
            if ($magic_quotes_gpc) {
 /**
  * Constructs a SQL clause about default character set and default collation for newly created databases and tables.
  * Example: Database::make_charset_clause('UTF-8', 'bulgarian') returns
  *  DEFAULT CHARACTER SET `utf8` DEFAULT COLLATE `utf8_general_ci`
  * @param string $encoding (optional)	The default database/table encoding (a system conventional id) to be used.
  * @param string $language (optional)	Language (a system conventional id) used for choosing language sensitive collation (if it is possible).
  * @return string						Returns the constructed SQL clause or empty string if $encoding is not correct or is not supported.
  * @author Ivan Tcholakov
  */
 public static function make_charset_clause($encoding = null, $language = null)
 {
     if (empty($encoding)) {
         $encoding = api_get_system_encoding();
     }
     if (empty($language)) {
         $language = api_get_interface_language();
     }
     $charset_clause = '';
     if (self::is_encoding_supported($encoding)) {
         $db_encoding = Database::to_db_encoding($encoding);
         $charset_clause .= " DEFAULT CHARACTER SET `" . $db_encoding . "`";
         $db_collation = Database::to_db_collation($encoding, $language);
         if (!empty($db_collation)) {
             $charset_clause .= " DEFAULT COLLATE `" . $db_collation . "`";
         }
     }
     return $charset_clause;
 }
Example #10
0
     foreach ($_languages['name'] as $key => $value) {
         $english_name = $_languages['folder'][$key];
         if ($language == $english_name) {
             $html .= '<option value="' . $english_name . '" selected="selected">' . $value . '</option>';
         } else {
             $html .= '<option value="' . $english_name . '">' . $value . '</option>';
         }
     }
     $html .= '</select></td></tr>';
     $form->addElement('html', $html);
 }
 $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
 $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
 $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
 $form->addElement('html', '<table id="table_langs" style="margin-left:5px;"><tr>');
 $currentLanguage = api_get_interface_language();
 $i = 0;
 foreach ($_languages['name'] as $key => $value) {
     $lang_name = $_languages['folder'][$key];
     $i++;
     $checked = null;
     if ($languageGet == $lang_name) {
         $checked = "checked";
     }
     $html_langs = '<td width="300">';
     $html_langs .= '<label><input type="checkbox" ' . $checked . ' id="lang" name="' . $lang_name . '" />&nbsp;' . $value . '<label/>';
     $html_langs .= '</td>';
     if ($i % 5 == 0) {
         $html_langs .= '</tr><tr>';
     }
     $form->addElement('html', $html_langs);
    echo api_get_interface_language();
    ?>
">
                    <?php 
    echo custompages_get_lang('Registration');
    ?>
                </a><br />
                <?php 
}
?>

                <a href="<?php 
echo api_get_path(WEB_PATH);
?>
main/auth/lostPassword.php?language=<?php 
echo api_get_interface_language();
?>
">
                    <?php 
echo custompages_get_lang('LostPassword');
?>
                </a>
			</div>
		</div> <!-- #form -->
		<div id="footer">
			<img src="<?php 
echo api_get_path(WEB_PATH);
?>
/custompages/images/footer.png" />
		</div> <!-- #footer -->
	</div> <!-- #wrapper -->
Example #12
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    function toHtml()
    {
        $html = api_get_js('select2/select2.js');
        $iso = api_get_language_isocode(api_get_interface_language());
        $localeFile = 'select2_locale_' . $iso . '.js';
        if (file_exists(api_get_path(LIBRARY_PATH) . 'javascript/select2/' . $localeFile)) {
            $html .= api_get_js('select2/' . $localeFile);
        }
        $html .= api_get_css(api_get_path(WEB_LIBRARY_PATH) . 'javascript/select2/select2.css');
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                formatResult : ' . $formatResult . ',
                formatSelection : ' . $formatResult . ',';
        }
        $defaultValues = $this->getAttribute('defaults');
        $dataCondition = null;
        $tags = null;
        if (!empty($defaultValues)) {
            $result = json_encode($defaultValues);
            $result = str_replace('"id"', 'id', $result);
            $result = str_replace('"text"', 'text', $result);
            $dataCondition = '$("#' . $this->getAttribute('name') . '").select2("data", ' . $result . ')';
            $tags = ', tags : function() { return ' . $result . '} ';
        }
        $width = 'element';
        $givenWidth = $this->getAttribute('width');
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $html .= '<script>
                $(function() {
                    $("#' . $this->getAttribute('name') . '").select2({
                        placeholder: "' . $plHolder . '",
                        allowClear: true,
                        width: "' . $width . '",
                        minimumInputLength: ' . $minimumInputLength . ',
                        // instead of writing the function to execute the request we use Select2s convenient helper
                        ajax: {
                            url: "' . $this->getAttribute('url') . '",
                            dataType: "json",
                            data: function (term, page) {
                                return {
                                    q: term, // search term
                                    page_limit: 10,
                                };
                            },
                            results: function (data, page) { // parse the results into the format expected by Select2.
                                // since we are using custom formatting functions we do not need to alter remote JSON data
                                return {
                                    results: data
                                };
                            }
                        }
                        ' . $tags . '
                        ' . $formatCondition . '
                    });
                    ' . $dataCondition . '

                });

        </script>';
        $html .= '<input id="' . $this->getAttribute('name') . '" name="' . $this->getAttribute('name') . '" />';
        return $html;
    }
Example #13
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    function toHtml()
    {
        $html = api_get_asset('select2/dist/js/select2.min.js');
        $iso = api_get_language_isocode(api_get_interface_language());
        $languageCondition = '';
        if (file_exists(api_get_path(SYS_PATH) . "web/assets/select2/dist/js/i18n/{$iso}.js")) {
            $html .= api_get_asset("select2/dist/js/i18n/{$iso}.js");
            $languageCondition = "language: '{$iso}',";
        }
        $html .= api_get_css(api_get_path(WEB_PATH) . 'web/assets/select2/dist/css/select2.min.css');
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $width = 'element';
        $givenWidth = '100%';
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $id = $this->getAttribute('id');
        if (empty($id)) {
            $id = $this->getAttribute('name');
            $this->setAttribute('id', $id);
        }
        $html .= <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('id')}').select2({
                        {$languageCondition}
                        placeholder: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        ajax: {
                            url: '{$this->getAttribute('url')}',
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $this->removeAttribute('formatResult');
        $this->removeAttribute('minimumInputLength');
        $this->removeAttribute('placeholder');
        $this->removeAttribute('class');
        $this->removeAttribute('url');
        $this->setAttribute('style', 'width: 100%;');
        return parent::toHtml() . $html;
    }
 /**
  * Creates a username using person's names, i.e. creates jmontoya from Julio Montoya.
  * @param string $firstname                The first name of the user.
  * @param string $lastname                The last name of the user.
  * @param string $language (optional)    The language in which comparison is to be made. If language is omitted, interface language is assumed then.
  * @param string $encoding (optional)    The character encoding for the input names. If it is omitted, the platform character set will be used by default.
  * @return string                        Suggests a username that contains only ASCII-letters and digits, without check for uniqueness within the system.
  * @author Julio Montoya Armas
  * @author Ivan Tcholakov, 2009 - rework about internationalization.
  * @assert ('','') === false
  * @assert ('a','b') === 'ab'
  */
 public static function create_username($firstname, $lastname, $language = null, $encoding = null)
 {
     if (is_null($encoding)) {
         $encoding = api_get_system_encoding();
     }
     if (is_null($language)) {
         $language = api_get_interface_language();
     }
     $firstname = api_substr(preg_replace(USERNAME_PURIFIER, '', api_transliterate($firstname, '', $encoding)), 0, 1);
     // The first letter only.
     //Looking for a space in the lastname
     $pos = api_strpos($lastname, ' ');
     if ($pos !== false) {
         $lastname = api_substr($lastname, 0, $pos);
     }
     $lastname = preg_replace(USERNAME_PURIFIER, '', api_transliterate($lastname, '', $encoding));
     //$username = api_is_western_name_order(null, $language) ? $firstname.$lastname : $lastname.$firstname;
     $username = $firstname . $lastname;
     if (empty($username)) {
         $username = '******';
     }
     return strtolower(substr($username, 0, USERNAME_MAX_LENGTH - 3));
 }
Example #15
0
/**
 * This function displays a language dropdown box so that the installatioin
 * can be done in the language of the user
 */
function display_language_selection()
{
    ?>
<h2><?php 
    translate('WelcomeToTheDokeosInstaller');
    ?>
</h2>
<div class="RequirementHeading">
    <h2><?php 
    echo display_step_sequence();
    echo translate('InstallationLanguage');
    ?>
</h2>

    <p><?php 
    echo translate('PleaseSelectInstallationProcessLanguage');
    ?>
:</p>

    <form id="lang_form" method="post" action="<?php 
    echo api_get_self();
    ?>
">
        <?php 
    display_language_selection_box('language_list', api_get_interface_language());
    ?>
        <button type="submit" name="step1" class="btn next" autofocus="autofocus"
                value="<?php 
    echo translate('Next');
    ?>
"><?php 
    echo translate('Next');
    ?>
</button>
        <input type="hidden" name="is_executable" id="is_executable" value="-"/>
    </form>
</div>
<?php 
}
Example #16
0
 */
if (api_is_anonymous()) {
    // Only available in the index.php page
    $loginAccepted = isset($_SESSION['before_login_accepted']) ? $_SESSION['before_login_accepted'] : null;
    $parsedUrl = parse_url($_SERVER['REQUEST_URI']);
    $currentPage = str_replace('index.php', '', $parsedUrl['path']);
    if (api_get_path(REL_PATH) !== $currentPage) {
        return null;
    }
    // Hide only if the before_login_accepted session was set to ON.
    if ($loginAccepted) {
        return null;
    }
    // Only available for the selected language.
    $languageToActivate = api_get_plugin_setting('before_login', 'language');
    if (api_get_interface_language() != $languageToActivate) {
        return null;
    }
    $option1 = api_get_plugin_setting('before_login', 'option1');
    $urlOption1 = api_get_plugin_setting('before_login', 'option1_url');
    $option2 = api_get_plugin_setting('before_login', 'option2');
    $urlOption2 = api_get_plugin_setting('before_login', 'option2_url');
    $form = new FormValidator('form');
    $renderer =& $form->defaultRenderer();
    $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
    $renderersetCustomElementTemplate->setCustomElementTemplate('<tr><td>{element}</td></tr>');
    $form->addElement('html', $option1);
    $form->addElement('checkbox', 'left', null, get_lang('Yes'));
    $form->addElement('button', 'submit', get_lang('Confirm'), array('class' => 'btn btn-primary'));
    $formHtml = $form->return_form();
    if ($form->validate()) {
Example #17
0
/**
 * This function displays a language dropdown box so that the installatioin
 * can be done in the language of the user
 */
function display_language_selection()
{
    ?>
    <h2><?php 
    get_lang('WelcomeToTheChamiloInstaller');
    ?>
</h2>
    <div class="RequirementHeading">
        <h2><?php 
    echo display_step_sequence();
    ?>
            <?php 
    echo get_lang('InstallationLanguage');
    ?>
        </h2>
        <p><?php 
    echo get_lang('PleaseSelectInstallationProcessLanguage');
    ?>
:</p>
        <form id="lang_form" method="post" action="<?php 
    echo api_get_self();
    ?>
">
        <div class="form-group">
            <div class="col-sm-4">
                <?php 
    echo display_language_selection_box('language_list', api_get_interface_language());
    ?>
            </div>
            <div class="col-sm-6">
                <button type="submit" name="step1" class="btn btn-success" value="<?php 
    echo get_lang('Next');
    ?>
">
                    <i class="fa fa-forward"> </i>
                    <?php 
    echo get_lang('Next');
    ?>
</button>
            </div>
        </div>

        <input type="hidden" name="is_executable" id="is_executable" value="-" />
        </form>

    </div>
    <div class="RequirementHeading">
        <?php 
    echo get_lang('YourLanguageNotThereContactUs');
    ?>
    </div>
<?php 
}
 /**
  * Checks if a message in a language exists, if the event is activated
  * and if "manage event" is checked in admin panel.
  * If yes to three, we can use this class, else we still use api_mail.
  *
  * @param string $event_name
  * @return boolean
  */
 public static function check_if_using_class($event_name)
 {
     if (api_get_setting('activate_email_template') === 'false') {
         return false;
     }
     $current_language = api_get_interface_language();
     $sql = 'SELECT COUNT(*) as total FROM ' . Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE) . ' em
     INNER JOIN ' . Database::get_main_table(TABLE_MAIN_LANGUAGE) . ' l on em.language_id = l.id
     WHERE em.event_type_name = "' . $event_name . '" and l.dokeos_folder = "' . $current_language . '" and em.activated = 1';
     $exists = Database::store_result(Database::query($sql), 'ASSOC');
     if ($exists[0]["total"]) {
         return true;
     } else {
         return false;
     }
 }
/**
 * Returns an array of translated week days and months, short and normal names.
 * @param string $language (optional)	Language indentificator. If it is omited, the current interface language is assumed.
 * @return array						Returns a multidimensional array with translated week days and months.
 */
function &_api_get_day_month_names($language = null)
{
    static $date_parts = array();
    if (empty($language)) {
        $language = api_get_interface_language();
    }
    if (!isset($date_parts[$language])) {
        $week_day = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
        $month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
        for ($i = 0; $i < 7; $i++) {
            $date_parts[$language]['days_short'][] = get_lang($week_day[$i] . 'Short', '', $language);
            $date_parts[$language]['days_long'][] = get_lang($week_day[$i] . 'Long', '', $language);
        }
        for ($i = 0; $i < 12; $i++) {
            $date_parts[$language]['months_short'][] = get_lang($month[$i] . 'Short', '', $language);
            $date_parts[$language]['months_long'][] = get_lang($month[$i] . 'Long', '', $language);
        }
    }
    return $date_parts[$language];
}
    function return_help() {
        $user_selected_language = api_get_interface_language();
        $sys_path               = api_get_path(SYS_PATH);
        $platformLanguage       = api_get_setting('platformLanguage');

        // Help section.
        /* Hide right menu "general" and other parts on anonymous right menu. */

        if (!isset($user_selected_language)) {
            $user_selected_language = $platformLanguage;
        }

        $html = null;
        $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
        if (!empty($home_menu)) {
            $home_menu_content = '<ul class="nav nav-list">';
            $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
            $home_menu_content .= '</ul>';
            $html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content, 'help_block');
        }
        return $html;
    }
Example #21
0
    /**
     * The ajax call must contain an array of id and text
     * @return string
     */
    function toHtml()
    {
        $html = api_get_asset('select2/dist/js/select2.min.js');
        $iso = api_get_language_isocode(api_get_interface_language());
        $languageCondition = '';
        if (file_exists(api_get_path(SYS_PATH) . "web/assets/select2/dist/js/i18n/{$iso}.js")) {
            $html .= api_get_asset("select2/dist/js/i18n/{$iso}.js");
            $languageCondition = "language: '{$iso}',";
        }
        $html .= api_get_css(api_get_path(WEB_PATH) . 'web/assets/select2/dist/css/select2.min.css');
        $formatResult = $this->getAttribute('formatResult');
        $formatCondition = null;
        if (!empty($formatResult)) {
            $formatCondition = ',
                templateResult : ' . $formatResult . ',
                templateSelection : ' . $formatResult;
        }
        $defaultValues = $this->getAttribute('defaults');
        $defaultValues = empty($defaultValues) ? [] : $defaultValues;
        $width = 'element';
        $givenWidth = $this->getAttribute('width');
        if (!empty($givenWidth)) {
            $width = $givenWidth;
        }
        //Get the minimumInputLength for select2
        $minimumInputLength = $this->getAttribute('minimumInputLength') > 3 ? $this->getAttribute('minimumInputLength') : 3;
        $plHolder = $this->getAttribute('placeholder');
        if (empty($plHolder)) {
            $plHolder = get_lang('SelectAnOption');
        }
        $html .= <<<JS
            <script>
                \$(function(){
                    \$('#{$this->getAttribute('name')}').select2({
                        {$languageCondition}
                        placeholder_: '{$plHolder}',
                        allowClear: true,
                        width: '{$width}',
                        minimumInputLength: '{$minimumInputLength}',
                        // instead of writing the function to execute the request we use Select2s convenient helper
                        ajax: {
                            url: '{$this->getAttribute('url')}',
                            dataType: 'json',
                            data: function(params) {
                                return {
                                    q: params.term, // search term
                                    page_limit: 10,
                                };
                            },
                            processResults: function (data, page) {
                                //parse the results into the format expected by Select2
                                return {
                                    results: data.items
                                };
                            }
                            {$formatCondition}
                        }
                    });
                });
            </script>
JS;
        $html .= Display::select($this->getAttribute('name'), $defaultValues, array_keys($defaultValues), ['id' => $this->getAttribute('name'), 'style' => 'width: 100%;'], false);
        return $html;
    }
 /**
  * @param $visible
  * @param null $id
  * @param string $type
  * @param bool $getCount
  * @param int $cutSize
  * @return string
  */
 public static function getAnnouncements($visible, $id = null, $type = 'resumed', $getCount = false, $cutSize = 800)
 {
     $user_selected_language = Database::escape_string(api_get_interface_language());
     $table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
     $now = api_get_utc_datetime();
     $select = '*';
     if ($getCount) {
         $select = 'count(*) as count';
     }
     $sql = "SELECT {$select}\n                FROM {$table}\n\t\t\t\tWHERE\n\t\t\t\t( lang = '{$user_selected_language}' OR lang IS NULL) AND\n\t\t\t\t( '{$now}' >= date_start AND '{$now}' <= date_end) ";
     switch ($visible) {
         case self::VISIBLE_GUEST:
             $sql .= " AND visible_guest = 1 ";
             break;
         case self::VISIBLE_STUDENT:
             $sql .= " AND visible_student = 1 ";
             break;
         case self::VISIBLE_TEACHER:
             $sql .= " AND visible_teacher = 1 ";
             break;
     }
     if (isset($id) && !empty($id)) {
         $id = intval($id);
         $sql .= " AND id = {$id} ";
     }
     if (api_is_multiple_url_enabled()) {
         $current_url_id = api_get_current_access_url_id();
         $sql .= " AND access_url_id IN ('1', '{$current_url_id}') ";
     }
     $sql .= " ORDER BY date_start DESC";
     $announcements = Database::query($sql);
     if ($getCount) {
         $announcement = Database::fetch_array($announcements);
         return $announcement['count'];
     }
     $options = array();
     if (Database::num_rows($announcements) > 0) {
         while ($announcement = Database::fetch_object($announcements)) {
             $content = $announcement->content;
             $url = api_get_path(WEB_PUBLIC_PATH) . 'news/' . $announcement->id;
             if (empty($id)) {
                 if ($type == 'resumed') {
                     if (api_strlen(strip_tags($content)) > $cutSize) {
                         $content = Security::remove_XSS(Text::cut($announcement->content, $cutSize)) . ' ' . Display::url(get_lang('More'), $url);
                     }
                 } else {
                     $content = $announcement->content;
                 }
             }
             $announcement->title = Text::cut($announcement->title, $cutSize);
             $options[] = array('title' => $announcement->title, 'content' => $content);
         }
     }
     return $options;
 }
Example #23
0
            <label for="activated" style="display:inline;"><?php 
echo get_lang('ActivateEvent');
?>
</label>
        </span>
    <br />
    <select id="languages" name="languages" style="margin-top:20px;" onclick='confirmMessage(this.name); return false;'>
<?php 
foreach ($languages["name"] as $key => $value) {
    $english_name = $languages['folder'][$key];
    ?>
            <option value="<?php 
    echo $english_name;
    ?>
" <?php 
    echo $english_name == api_get_interface_language() ? "selected=selected" : "";
    ?>
><?php 
    echo $value;
    ?>
</option>
<?php 
}
?>
    </select>

    <input type="hidden" name="action" value="modEventType" />
    <input type="hidden" name="eventId" id="eventId"  />
    <input type="hidden" name="eventUsers" id="eventUsers" />
    <input type="hidden" id="eventName" value="<?php 
echo $event_name;
/**
 * Returns in an array the most-probably used non-UTF-8 encoding for the given language.
 * The first (leading) value is actually used by the system at the moment.
 * @param string $language (optional)	The specified language, the default value is the user intrface language.
 * @return string						The correspondent encoding to the specified language.
 * Note: See the file chamilo/main/inc/lib/internationalization_database/non_utf8_encodings.php
 * if you wish to revise the leading non-UTF-8 encoding for your language.
 */
function api_get_non_utf8_encoding($language = null)
{
    $language_is_supported = api_is_language_supported($language);
    if (!$language_is_supported || empty($language)) {
        $language = api_get_interface_language(false, true);
    }
    $language = api_purify_language_id($language);
    $encodings =& _api_non_utf8_encodings();
    if (is_array($encodings[$language])) {
        if (!empty($encodings[$language][0])) {
            return $encodings[$language][0];
        }
        return null;
    }
    return null;
}