View source
<?php
define('OPIGNO_LMS_COURSE_STUDENT_ROLE', 'course student member');
define('OPIGNO_LMS_COURSE_COACH_ROLE', 'course coach member');
define('OPIGNO_LMS_COURSE_TEACHER_ROLE', 'course teacher member');
define('OPIGNO_LMS_COURSE_ADMIN_ROLE', 'course admin member');
define('OPIGNO_LMS_COURSE_MODERATOR_ROLE', 'course forum moderator');
define('OPIGNO_LMS_STUDENT_MANAGER_ROLE', 'student manager');
define('OPIGNO_LMS_ADMIN_ROLE', 'administrator');
define('OPIGNO_LMS_FORUM_ADMINISTRATOR_ROLE', 'forum administrator');
define('OPIGNO_LMS_VERSION', '1.52.0');
function opigno_lms_init() {
$og_roles = variable_get('opigno_lms_default_og_roles', array());
if (empty($og_roles)) {
module_load_include('install', 'opigno_lms');
$found = FALSE;
foreach (array(
OPIGNO_LMS_COURSE_ADMIN_ROLE => 'manager',
OPIGNO_LMS_COURSE_COACH_ROLE => 'coach',
OPIGNO_LMS_COURSE_TEACHER_ROLE => 'teacher',
OPIGNO_LMS_COURSE_STUDENT_ROLE => 'student',
OPIGNO_LMS_COURSE_MODERATOR_ROLE => 'forum moderator',
) as $role_key => $role_name) {
$rid = _opigno_lms_install_get_role_by_name($role_name, OPIGNO_COURSE_BUNDLE);
if (!empty($rid)) {
$og_roles[$role_key] = $rid;
$found = TRUE;
}
}
if ($found) {
variable_set('opigno_lms_default_og_roles', $og_roles);
variable_set('og_group_manager_default_rids_node_course', array(
$og_roles[OPIGNO_LMS_COURSE_ADMIN_ROLE],
));
$rid = _opigno_lms_install_get_role_by_name('manager', 'class');
if (!empty($rid)) {
variable_set('og_group_manager_default_rids_node_class', array(
$rid,
));
}
}
}
$platform_roles = variable_get('opigno_lms_default_platform_roles', array());
if (empty($platform_roles)) {
module_load_include('install', 'opigno_lms');
$found = FALSE;
foreach (array(
OPIGNO_LMS_STUDENT_MANAGER_ROLE => 'student manager',
OPIGNO_LMS_ADMIN_ROLE => 'administrator',
OPIGNO_LMS_FORUM_ADMINISTRATOR_ROLE => 'forum administrator',
) as $role_key => $role_name) {
$role = user_role_load_by_name($role_name);
if (!empty($role->rid)) {
$platform_roles[$role_key] = $role->rid;
$found = TRUE;
}
}
if ($found) {
variable_set('opigno_lms_default_platform_roles', $platform_roles);
}
}
}
function opigno_lms_form_node_form_alter(&$form, $form_state) {
if (!(module_exists('entity_translation') || module_exists('translation'))) {
$form['language']['#value'] = LANGUAGE_NONE;
}
}
function opigno_lms_install_tasks(&$install_state) {
drupal_add_css(drupal_get_path('profile', 'opigno_lms') . '/css/opigno_lms.css');
$tasks = array();
$tasks['opigno_lms_install_task_post_install'] = array();
$tasks['opigno_lms_verify_requirements'] = array(
'display_name' => st('Check Opigno requirements'),
'type' => 'form',
);
if (!empty($install_state['parameters']['opigno_requirements_finished'])) {
$tasks['opigno_lms_verify_requirements']['run'] = INSTALL_TASK_SKIP;
}
$needs_translations = count($install_state['locales']) > 1 && !empty($install_state['parameters']['locale']) && $install_state['parameters']['locale'] != 'en';
$tasks['opigno_lms_install_import_translation'] = array(
'display_name' => st('Set up translations'),
'display' => $needs_translations,
'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
'type' => 'batch',
);
return $tasks;
}
function opigno_lms_install_import_translation(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
$install_locale = $install_state['parameters']['locale'];
locale_add_language($install_locale, NULL, NULL, NULL, '', NULL, 1, TRUE);
$old_cache = variable_get('cache_class_cache');
variable_set('cache_class_cache', 'DrupalDatabaseCache');
module_load_include('fetch.inc', 'l10n_update');
$options = _l10n_update_default_update_options();
$last_checked = variable_get('l10n_update_last_check');
if ($last_checked < REQUEST_TIME - L10N_UPDATE_STATUS_TTL) {
l10n_update_clear_status();
$batch = l10n_update_batch_update_build(array(), array(
$install_locale,
), $options);
}
else {
$batch = l10n_update_batch_fetch_build(array(), array(
$install_locale,
), $options);
}
$batch['operations'][] = array(
'variable_set',
array(
'cache_class_cache',
$old_cache,
),
);
return $batch;
}
function opigno_lms_install_tasks_alter(&$tasks, $install_state) {
if (isset($tasks['opigno_lms_verify_requirements'])) {
$pos = array_search('opigno_lms_verify_requirements', array_keys($tasks));
if ($pos == '11') {
$save = $tasks['opigno_lms_verify_requirements'];
unset($tasks['opigno_lms_verify_requirements']);
$first_array = array_splice($tasks, 0, 4);
$tasks = array_merge($first_array, array(
'opigno_lms_verify_requirements' => $save,
), $tasks);
}
}
if ($install_state['active_task'] == "install_import_locales") {
drupal_get_messages('status');
drupal_get_messages('warning');
}
unset($tasks['install_import_locales']);
unset($tasks['install_import_locales_remaining']);
}
function opigno_lms_verify_requirements($form, &$form_state, &$install_state) {
$form = array();
$error = FALSE;
$warnings = FALSE;
$t = get_t();
$available_memory = ini_get("memory_limit");
if ($available_memory == -1) {
$available_memory = 2048;
}
$available_memory = preg_replace('/\\D/', '', $available_memory);
if ($available_memory < 256) {
drupal_set_message($t("The minimum memory requirement for Opigno installation is 256M, you only have %available_memory. Please change the memory_limit in your php.ini settings file or using ini_set in the settings.php file before continuing", array(
'%available_memory' => $available_memory,
)), 'error', $repeat = FALSE);
$error = TRUE;
}
$xdebug_max_nesting_level = ini_get("xdebug.max_nesting_level");
if (!empty($xdebug_max_nesting_level) && $xdebug_max_nesting_level < 200 && $xdebug_max_nesting_level != -1) {
drupal_set_message($t("Your system has Zend Xdebug enabled. In order to install Opigno with Xdebug enabled please set xdebug.max_nesting_level to at least 200 in your php.ini settings file or using ini_set in the settings.php file before continuing. Currently it is set as %xdebug_max_nesting_level.", array(
'%xdebug_max_nesting_level' => $xdebug_max_nesting_level,
)), "error", $repeat = FALSE);
$error = TRUE;
}
$max_execution_time = ini_get("max_execution_time");
if ($max_execution_time < 30 && !($max_execution_time <= 0)) {
drupal_set_message($t("Your system has the max_execution_time as %max_execution_time. Minimum required for Opigno installation is 30. If your machine is old and depending on its current load you may want to raise it even higher (120). Please change the max_execution_time in your php.ini settings file or using ini_set in the settings.php file before continuing.", array(
'%max_execution_time' => $max_execution_time,
)), "error", $repeat = FALSE);
$error = TRUE;
}
if ($max_execution_time < 120 && !($max_execution_time <= 0)) {
$warnings[] = $t("Your system has the max_execution_time as %max_execution_time. Minimum required for Opigno installation is 30. But depending on your system performance and current load you may want to raise this setting above (120). You can change the max_execution_time in your php.ini settings file or using ini_set in the settings.php file.", array(
'%max_execution_time' => $max_execution_time,
));
}
$max_input_time = ini_get("max_input_time");
if ($max_input_time < 60 && $max_input_time != -1) {
drupal_set_message($t("Your system has the max_input_time as %max_input_time. Minimum required for Opigno installation is 60. If your machine is old and depending on its current load you may want to raise it even higher (120). Please change the max_input_time in your php.ini settings file or using ini_set in the settings.php file before continuing", array(
'%max_input_time' => $max_input_time,
)), "error", $repeat = FALSE);
$error = TRUE;
}
if ($max_input_time < 120 && $max_input_time != -1) {
$warnings[] = $t("Your system has the max_input_time as %max_input_time. Minimum required for Opigno installation is 60. But depending on your system performance and current load you may want to raise this setting above (120). You can change the max_input_time in your php.ini settings file or using ini_set in the settings.php file.", array(
'%max_input_time' => $max_input_time,
));
}
if ($error == FALSE) {
drupal_set_message($t("Your system has passed Opigno requirements, you may proceed"), 'status', $repeat = FALSE);
if ($warnings != FALSE) {
foreach ($warnings as $warning) {
drupal_set_message($warning, 'warning', $repeat = FALSE);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Continue'),
);
$form_state['build_info']['args']['install_state'] =& $install_state;
}
return $form;
}
function opigno_lms_verify_requirements_submit($form, &$form_state) {
$install_state =& $form_state['build_info']['args']['install_state'];
$install_state['parameters']['opigno_requirements_finished'] = TRUE;
}
function opigno_lms_form_install_configure_form_alter(&$form, $form_state) {
drupal_get_messages('status');
drupal_get_messages('warning');
drupal_set_message(st("Please note that Opigno ships with the !dompdf library for generating certificates in PDF format. This works fine, but we strongly recommend to use !wkhtml instead, if you can. !wkhtml is much more powerful, and will allow you to make nicer certificates. However, !wkhtml requires manual installation, and your server might not be compatible. Please refer to these <a href='!url' target='_blank'>instructions</a> for more information, or visit our support forums.", array(
'!dompdf' => '<a href="https://github.com/dompdf/dompdf" target="_blank">DomPDF</a>',
'!wkhtml' => '<a href="https://code.google.com/p/wkhtmltopdf/" target="_blank">WKHTML</a>',
'!url' => 'https://drupal.org/node/306882',
)), 'warning');
drupal_set_message(st("Please note that Opigno ships with the pdf module that allows users to view pdf files inside slides. In order to use this functionality you need to manually download the pdfjs library. <a href='!url' target='_blank'>Instructions on our forum</a>", array(
'!url' => 'https://www.opigno.org/node/820',
)), 'warning');
$form['site_information']['site_name']['#default_value'] = st('Opigno LMS');
$form['admin_account']['account']['name']['#default_value'] = 'admin';
$form['update_notifications']['#access'] = FALSE;
$form['update_notifications']['#default_value'] = TRUE;
if (valid_email_address('admin@' . $_SERVER['HTTP_HOST'])) {
$form['site_information']['site_mail']['#default_value'] = 'admin@' . $_SERVER['HTTP_HOST'];
$form['admin_account']['account']['mail']['#default_value'] = 'admin@' . $_SERVER['HTTP_HOST'];
}
$form['#submit'][] = 'opigno_lms_form_install_configure_form_alter_submit';
}
function opigno_lms_form_install_configure_form_alter_submit($form, $form_state) {
}
function opigno_lms_update_status_alter(&$projects) {
$make_filepath = drupal_get_path('profile', 'opigno_lms') . '/drupal-org.make';
if (!file_exists($make_filepath)) {
return;
}
$make_info = drupal_parse_info_file($make_filepath);
foreach ($projects as $project_name => $project_info) {
if ($project_name == 'opigno_lms') {
continue;
}
if (strpos($project_name, 'opigno_features_') !== FALSE) {
unset($projects[$project_name]);
}
elseif (isset($make_info['projects'][$project_name]['version'])) {
$version = $make_info['projects'][$project_name]['version'];
if (strpos($version, 'dev') !== FALSE || DRUPAL_CORE_COMPATIBILITY . '-' . $version == $project_info['info']['version']) {
unset($projects[$project_name]);
}
}
}
}
function opigno_lms_form_update_manager_update_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['projects']['#options']) && isset($form['projects']['#options']['opigno_lms'])) {
if (count($form['projects']['#options']) > 1) {
unset($form['projects']['#options']['opigno_lms']);
}
else {
unset($form['projects']);
if (!isset($form['disabled_projects'])) {
$form['actions']['#access'] = FALSE;
}
$form['message']['#markup'] = t('All of your projects are up to date.');
}
}
}
function opigno_lms_form_og_ui_add_users_alter(&$form, $form_state) {
$gid = $form['gid']['#value'];
$node = node_load($gid);
_opigno_lms_hide_coach_checkbox($node);
}
function opigno_lms_form_og_ui_edit_membership_alter(&$form, $form_state) {
$gid = $form['gid']['#value'];
$node = node_load($gid);
_opigno_lms_hide_coach_checkbox($node);
}
function opigno_lms_form_og_massadd_massadd_form_alter(&$form, $form_state) {
$gid = current($form['group_ids']['#value']);
$node = node_load($gid);
_opigno_lms_hide_coach_checkbox($node);
}
function opigno_lms_block_info() {
return array(
'version' => array(
'info' => t("Opigno version information"),
'cache' => DRUPAL_CACHE_GLOBAL,
),
);
}
function opigno_lms_block_view($delta = '') {
return array(
'subject' => '<none>',
'content' => t("Opigno LMS !version", array(
'!version' => OPIGNO_LMS_VERSION,
)),
);
}
function _opigno_lms_hide_coach_checkbox($node) {
if (module_exists('opigno_simple_ui') && !empty($node->nid) && $node->type === OPIGNO_COURSE_BUNDLE) {
$rid = opigno_lms_get_role_id(OPIGNO_LMS_COURSE_COACH_ROLE);
if (!empty($rid)) {
drupal_add_css(".form-type-checkbox.form-item-roles-{$rid} { display: none; }", array(
'type' => 'inline',
));
}
}
}
function opigno_lms_install_task_post_install() {
module_invoke_all('opigno_lms_post_install');
}
function opigno_lms_get_role_id($key) {
return opigno_lms_get_og_role_id($key);
}
function opigno_lms_get_og_role_id($key) {
$roles =& drupal_static(__FUNCTION__);
if (empty($roles)) {
$roles = variable_get('opigno_lms_default_og_roles', array());
}
return !empty($roles[$key]) ? $roles[$key] : 0;
}
function opigno_lms_get_platform_role_id($key) {
$roles =& drupal_static(__FUNCTION__);
if (empty($roles)) {
$roles = variable_get('opigno_lms_default_platform_roles', array());
}
return !empty($roles[$key]) ? $roles[$key] : 0;
}
function opigno_lms_set_og_permissions($bundle, $permissions) {
foreach ($permissions as $role_key => $role_permissions) {
$rid = opigno_lms_get_og_role_id($role_key);
og_role_grant_permissions($rid, $role_permissions);
}
}
function opigno_lms_set_platform_permissions($permissions) {
foreach ($permissions as $role_key => $role_permissions) {
$rid = opigno_lms_get_platform_role_id($role_key);
user_role_grant_permissions($rid, $role_permissions);
}
}