/** * Class constructor */ function HTML_QuickForm_Select_Language($elementName = null, $elementLabel = null, $options = null, $attributes = null) { if (!isset($attributes['class'])) { $attributes['class'] = 'chzn-select'; } parent::HTML_QuickForm_Select($elementName, $elementLabel, $options, $attributes); // Get all languages $languages = api_get_languages(); $this->_options = array(); $this->_values = array(); $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']); } } }
/** * Gets language isocode column from the language table, taking the given language as a query parameter. * @param string $language This is the name of the folder containing translations for the corresponding language (e.g arabic, english). * @param string $default_code This is the value to be returned if there was no code found corresponding to the given language. * If $language is omitted, interface language is assumed then. * @return string The found isocode or null on error. * Returned codes are according to the following standards (in order of preference): * - ISO 639-1 : Alpha-2 code (two-letters code - en, fr, es, ...) * - RFC 4646 : five-letter code based on the ISO 639 two-letter language codes * and the ISO 3166 two-letter territory codes (pt-BR, ...) * - ISO 639-2 : Alpha-3 code (three-letters code - ast, fur, ...) */ function api_get_language_isocode($language = null, $default_code = 'en') { return Container::getTranslator()->getLocale(); }
$group = array(); $group[] = $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1); $group[] = $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0); $form->addGroup($group, '', get_lang('Subscription'), '<br />'); $group = array(); $group[] = $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1); $group[] = $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0); $form->addGroup($group, '', get_lang('Unsubscription'), '<br />'); $form->addElement('text', 'disk_quota', array(get_lang('CourseQuota'), null, get_lang('MB'))); $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric'); $obj = new GradeModel(); $obj->fill_grade_model_select_in_form($form); $form->add_progress_bar(); $form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"'); // Set some default values. $values['course_language'] = Container::getTranslator()->getLocale(); // api_get_setting('platformLanguage'); $values['disk_quota'] = round(api_get_setting('document.default_document_quotum') / 1024 / 1024, 1); $default_course_visibility = api_get_setting('course.courses_default_creation_visibility'); if (isset($default_course_visibility)) { $values['visibility'] = api_get_setting('course.courses_default_creation_visibility'); } else { $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM; } $values['subscribe'] = 1; $values['unsubscribe'] = 0; $form->setDefaults($values); /* // Validate the form if ($form->validate()) { $course = $form->exportValues();
/** * Gets current language iso code * * @return string */ function api_get_language_isocode() { return Container::getTranslator()->getLocale(); }
function api_get_user_language() { $user_language = null; if (!api_is_anonymous()) { $userInfo = api_get_user_info(); if (isset($userInfo['language'])) { $user_language = $userInfo['language']; } } // When this is use? /* if (isset($_POST['language_list']) && !empty($_POST['language_list'])) { if (in_array($_GET['language'], $valid_languages)) { $user_language = str_replace('index.php?language=', '', $_POST['language_list']); } }*/ if (isset($_REQUEST['language']) && !empty($_REQUEST['language'])) { api_set_login_language($_REQUEST['language']); } // Last chance we get the platform language if (empty($user_language)) { $user_language = Container::getTranslator()->getLocale(); } return $user_language; }
/** * function register_course to create a record in the course table of the main database * @param string $course_sys_code * @param string $course_screen_code * @param string $course_repository * @param string $course_db_name * @param string $tutor_name * @param string $category * @param string $title complete name of course * @param string $course_language lang for this course * @param string $uid uid of owner * @param integer Expiration date in unix time representation * @param array Optional array of teachers' user ID * @return int 0 * @todo use an array called $params instead of lots of params */ static function register_course($params) { global $error_msg, $firstExpirationDelay; $title = $params['title']; $code = $params['code']; $visual_code = $params['visual_code']; $directory = isset($params['directory']) ? $params['directory'] : null; $tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null; $category_code = isset($params['category_code']) ? $params['category_code'] : null; $defaultLanguage = Container::getTranslator()->getLocale(); $course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : $defaultLanguage; $user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']); $department_name = isset($params['department_name']) ? $params['department_name'] : null; $department_url = isset($params['department_url']) ? $params['department_url'] : null; $disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null; if (!isset($params['visibility'])) { $default_course_visibility = api_get_setting('course.courses_default_creation_visibility'); if (isset($default_course_visibility)) { $visibility = $default_course_visibility; } else { $visibility = COURSE_VISIBILITY_OPEN_PLATFORM; } } else { $visibility = $params['visibility']; } $subscribe = isset($params['subscribe']) ? intval($params['subscribe']) : ($visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0); $unsubscribe = isset($params['unsubscribe']) ? intval($params['unsubscribe']) : 0; $expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null; $teachers = isset($params['teachers']) ? $params['teachers'] : null; $status = isset($params['status']) ? $params['status'] : null; $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE); $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER); $ok_to_register_course = true; // Check whether all the needed parameters are present. if (empty($code)) { $error_msg[] = 'courseSysCode is missing'; $ok_to_register_course = false; } if (empty($visual_code)) { $error_msg[] = 'courseScreenCode is missing'; $ok_to_register_course = false; } if (empty($directory)) { $error_msg[] = 'courseRepository is missing'; $ok_to_register_course = false; } if (empty($title)) { $error_msg[] = 'title is missing'; $ok_to_register_course = false; } if (empty($expiration_date)) { $expiration_date = api_get_utc_datetime(time() + $firstExpirationDelay); } else { $expiration_date = api_get_utc_datetime($expiration_date); } if ($visibility < 0 || $visibility > 3) { $error_msg[] = 'visibility is invalid'; $ok_to_register_course = false; } if (empty($disk_quota)) { $disk_quota = api_get_setting('document.default_document_quotum'); } $time = api_get_utc_datetime(); if (stripos($department_url, 'http://') === false && stripos($department_url, 'https://') === false) { $department_url = 'http://' . $department_url; } //just in case if ($department_url == 'http://') { $department_url = ''; } $course_id = 0; if ($ok_to_register_course) { /** @var Course $course */ $course = self::getCourseManager()->create(); $course->setCode($code)->setDirectory($directory)->setCourseLanguage($course_language)->setTitle($title)->setDescription(get_lang('CourseDescription'))->setCategoryCode($category_code)->setVisibility($visibility)->setShowScore(1)->setDiskQuota($disk_quota)->setCreationDate(new \DateTime())->setExpirationDate(new \DateTime($expiration_date))->setDepartmentName($department_name)->setDepartmentUrl($department_url)->setSubscribe($subscribe)->setUnsubscribe($unsubscribe)->setVisualCode($visual_code); self::getCourseManager()->save($course, true); $course_id = $course->getId(); /*// Here we must add 2 fields. $sql = "INSERT INTO ".$TABLECOURSE . " SET code = '".Database :: escape_string($code) . "', directory = '".Database :: escape_string($directory) . "', course_language = '".Database :: escape_string($course_language) . "', title = '".Database :: escape_string($title) . "', description = '".Database::escape_string(get_lang('CourseDescription')) . "', category_code = '".Database :: escape_string($category_code) . "', visibility = '".$visibility . "', show_score = '1', disk_quota = '".intval($disk_quota) . "', creation_date = '$time', expiration_date = '".$expiration_date . "', last_edit = '$time', last_visit = NULL, tutor_name = '".Database :: escape_string($tutor_name) . "', department_name = '".Database :: escape_string($department_name) . "', department_url = '".Database :: escape_string($department_url) . "', subscribe = '".intval($subscribe) . "', unsubscribe = '".intval($unsubscribe) . "', visual_code = '".Database :: escape_string($visual_code) . "'"; Database::query($sql); $course_id = Database::insert_id();*/ //$course->addUsers() if ($course_id) { $settingsManager = Container::getCourseSettingsManager(); $schemas = $settingsManager->getSchemas(); $schemas = array_keys($schemas); /** * @var string $key * @var \Sylius\Bundle\SettingsBundle\Schema\SchemaInterface $schema */ foreach ($schemas as $schema) { $settings = $settingsManager->loadSettings($schema); $settingsManager->setCourse($course); $settingsManager->saveSettings($schema, $settings); } $sort = api_max_sort_value('0', api_get_user_id()); $i_course_sort = CourseManager::userCourseSort($user_id, $code); if (!empty($user_id)) { $sql = "INSERT INTO " . $TABLECOURSUSER . " SET\n c_id = '" . Database::escape_string($course_id) . "',\n user_id = '" . intval($user_id) . "',\n status = '1',\n tutor_id = '0',\n sort = '" . $i_course_sort . "',\n user_course_cat = '0'"; Database::query($sql); } if (!empty($teachers)) { if (!is_array($teachers)) { $teachers = array($teachers); } foreach ($teachers as $key) { //just in case if ($key == $user_id) { continue; } if (empty($key)) { continue; } $sql = "INSERT INTO " . $TABLECOURSUSER . " SET\n c_id = '" . Database::escape_string($course_id) . "',\n user_id = '" . Database::escape_string($key) . "',\n status = '1',\n role = '',\n tutor_id = '0',\n sort = '" . ($sort + 1) . "',\n user_course_cat = '0'"; Database::query($sql); } } // Adding the course to an URL if (api_is_multiple_url_enabled()) { $url_id = 1; if (api_get_current_access_url_id() != -1) { $url_id = api_get_current_access_url_id(); } UrlManager::add_course_to_url($course_id, $url_id); } else { UrlManager::add_course_to_url($course_id, 1); } // Add event to the system log. $user_id = api_get_user_id(); Event::addEvent(LOG_COURSE_CREATE, LOG_COURSE_CODE, $code, api_get_utc_datetime(), $user_id, $code); $send_mail_to_admin = api_get_setting('course.send_email_to_admin_when_create_course'); // @todo Improve code to send to all current portal administrators. if ($send_mail_to_admin == 'true') { $siteName = api_get_setting('platform.site_name'); $recipient_email = api_get_setting('platform.administrator_email'); $recipient_name = api_get_person_name(api_get_setting('platform.administrator_name'), api_get_setting('platform.administrator_surname')); $iname = api_get_setting('platform.institution'); $subject = get_lang('NewCourseCreatedIn') . ' ' . $siteName . ' - ' . $iname; $body = get_lang('Dear') . ' ' . $recipient_name . ",\n\n" . get_lang('MessageOfNewCourseToAdmin') . ' ' . $siteName . ' - ' . $iname . "\n"; $body .= get_lang('CourseName') . ' ' . $title . "\n"; $body .= get_lang('Category') . ' ' . $category_code . "\n"; $body .= get_lang('Tutor') . ' ' . $tutor_name . "\n"; $body .= get_lang('Language') . ' ' . $course_language; //api_mail_html($recipient_name, $recipient_email, $subject, $message, $siteName, $recipient_email); $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($recipient_email)->setTo($recipient_email)->setBody(Container::getTemplate()->render('ChamiloCoreBundle:Mailer:Course/new_course.html.twig', array('recipient_name' => $recipient_name, 'sitename' => $siteName, 'institution' => $iname, 'course_name' => $title, 'category' => $category_code, 'tutor' => $tutor_name, 'language' => $course_language))); Container::getMailer()->send($message); } } } return $course_id; }
/** * Gets language isocode column from the language table, taking the given language as a query parameter. * @param string $language This is the name of the folder containing translations for the corresponding language (e.g arabic, english). * @param string $default_code This is the value to be returned if there was no code found corresponding to the given language. * If $language is omitted, interface language is assumed then. * @return string The found isocode or null on error. * Returned codes are according to the following standards (in order of preference): * - ISO 639-1 : Alpha-2 code (two-letters code - en, fr, es, ...) * - RFC 4646 : five-letter code based on the ISO 639 two-letter language codes * and the ISO 3166 two-letter territory codes (pt-BR, ...) * - ISO 639-2 : Alpha-3 code (three-letters code - ast, fur, ...) */ function api_get_language_isocode($language = null, $default_code = 'en') { return Container::getTranslator()->getLocale(); static $iso_code = array(); if (empty($language)) { $language = api_get_interface_language(false, true); } if (!isset($iso_code[$language])) { if (!class_exists('Database')) { return $default_code; // This might happen, in case of calling this function early during the global initialization. } $sql_result = Database::query("SELECT isocode FROM " . Database::get_main_table(TABLE_MAIN_LANGUAGE) . " WHERE dokeos_folder = '{$language}'"); if (Database::num_rows($sql_result)) { $result = Database::fetch_array($sql_result); $iso_code[$language] = trim($result['isocode']); } else { $language_purified_id = api_purify_language_id($language); $iso_code[$language] = isset($iso_code[$language_purified_id]) ? $iso_code[$language_purified_id] : null; } if (empty($iso_code[$language])) { $iso_code[$language] = $default_code; } } return $iso_code[$language]; }
/** * Update user information with all the parameters passed to this function * @param int The ID of the user to be updated * @param string The user's firstname * @param string The user's lastname * @param string The user's username (login) * @param string The user's password * @param string The authentication source (default: "platform") * @param string The user's e-mail address * @param int The user's status * @param string The user's official code (usually just an internal institutional code) * @param string The user's phone number * @param string The user's picture URL (internal to the Chamilo directory) * @param int The user ID of the person who registered this user (optional, defaults to null) * @param int The department of HR in which the user is registered (optional, defaults to 0) * @param array A series of additional fields to add to this user as extra fields (optional, defaults to null) * @return boolean true if the user information was updated * @assert (false) === false */ public static function update_user($user_id, $firstname, $lastname, $username, $password = null, $auth_source = null, $email = null, $status = STUDENT, $official_code = null, $phone = null, $picture_uri = null, $expiration_date = null, $active = 1, $creator_id = null, $hr_dept_id = 0, $extra = null, $language = 'english', $encrypt_method = '', $send_email = false, $reset_password = 0) { global $_configuration; $original_password = $password; $user_info = api_get_user_info($user_id, false, true); if ($reset_password == 0) { $password = null; $auth_source = $user_info['auth_source']; } elseif ($reset_password == 1) { $original_password = $password = api_generate_password(); $auth_source = PLATFORM_AUTH_SOURCE; } elseif ($reset_password == 2) { $password = $password; $auth_source = PLATFORM_AUTH_SOURCE; } elseif ($reset_password == 3) { $password = $password; $auth_source = $auth_source; } if ($user_id != strval(intval($user_id))) { return false; } if ($user_id === false) { return false; } // Checking the user language. $languages = api_get_platform_isocodes(); if (!in_array($language, $languages)) { $language = Container::getTranslator()->getLocale(); } if (!is_null($password)) { if ($encrypt_method == '') { $password = api_get_encrypted_password($password); } else { if ($_configuration['password_encryption'] === $encrypt_method) { if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) { return api_set_failure('encrypt_method invalid'); } else { if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) { return api_set_failure('encrypt_method invalid'); } } } else { return api_set_failure('encrypt_method invalid'); } } } $em = Database::getManager(); /** @var Chamilo\UserBundle\Entity\User $user */ $user = $em->getRepository('ChamiloUserBundle:User')->find($user_id); if (is_array($extra) && count($extra) > 0) { $res = true; foreach ($extra as $name => $value) { //$userField = $em->getRepository('ChamiloUserBundle:UserField')->findOneByName($name); $res = $res && self::update_extra_field_value($user_id, $name, $value); } } if ($user_info['active'] != $active) { self::change_active_state($user_id, $active); } // Updating user $user->setLastname($lastname)->setFirstname($firstname)->setUsername($username)->setAuthSource($auth_source)->setLanguage($language)->setEmail($email)->setOfficialCode($official_code)->setPhone($phone)->setPictureUri($picture_uri)->setExpirationDate($expiration_date)->setActive($active)->setHrDeptId($hr_dept_id); if (!empty($original_password)) { $user->setPlainPassword($original_password); } if (is_array($status)) { foreach ($status as $groupId) { $group = $em->getRepository('ChamiloUserBundle:Group')->find($groupId); $user->addGroup($group); } } else { $group = $em->getRepository('ChamiloUserBundle:Group')->find($status); $user->addGroup($group); } Container::getUserManager()->updateUser($user, true); if (!empty($email) && $send_email) { $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS); $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('platform.administrator_name'), api_get_setting('platform.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS); $email_admin = api_get_setting('platform.administrator_email'); $emailbody = null; /*api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);*/ } $user_info = api_get_user_info($user_id); Event::addEvent(LOG_USER_UPDATED, LOG_USER_ID, $user_id, api_get_utc_datetime(), api_get_user_id()); Event::addEvent(LOG_USER_UPDATED, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), api_get_user_id()); return $user_id; }