function pluginconfig_submit(Pieform $form, $values) { $success = false; global $plugintype, $pluginname, $classname; try { call_static_method($classname, 'save_config_options', $form, $values); $success = true; } catch (Exception $e) { $success = false; } if ($success) { clear_menu_cache(); $form->json_reply(PIEFORM_OK, get_string('settingssaved')); } else { $form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed'))); } }
function institution_submit(Pieform $form, $values) { global $SESSION, $institution, $add, $instancearray, $USER, $authinstances, $customthemedefaults; db_begin(); // Update the basic institution record... if ($add) { $newinstitution = new Institution(); $newinstitution->initialise($values['name'], $values['displayname']); $institution = $newinstitution->name; } else { $newinstitution = new Institution($institution); $newinstitution->displayname = $values['displayname']; $oldinstitution = get_record('institution', 'name', $institution); // Clear out any cached menus for this institution clear_menu_cache($institution); } $newinstitution->showonlineusers = !isset($values['showonlineusers']) ? 2 : $values['showonlineusers']; if (get_config('usersuniquebyusername')) { // Registering absolutely not allowed when this setting is on, it's a // security risk. See the documentation for the usersuniquebyusername // setting for more information $newinstitution->registerallowed = 0; } else { $newinstitution->registerallowed = $values['registerallowed'] ? 1 : 0; $newinstitution->registerconfirm = $values['registerconfirm'] ? 1 : 0; } if (!empty($values['lang'])) { if ($values['lang'] == 'sitedefault') { $newinstitution->lang = null; } else { $newinstitution->lang = $values['lang']; } } $newinstitution->theme = empty($values['theme']) || $values['theme'] == 'sitedefault' ? null : $values['theme']; $newinstitution->dropdownmenu = !empty($values['dropdownmenu']) ? 1 : 0; $newinstitution->skins = !empty($values['skins']) ? 1 : 0; require_once get_config('docroot') . 'artefact/comment/lib.php'; $commentoptions = ArtefactTypeComment::get_comment_options(); $newinstitution->commentsortorder = empty($values['commentsortorder']) ? $commentoptions->sort : $values['commentsortorder']; $newinstitution->commentthreaded = !empty($values['commentthreaded']) ? 1 : 0; if ($newinstitution->theme == 'custom') { if (!empty($oldinstitution->style)) { $styleid = $oldinstitution->style; delete_records('style_property', 'style', $styleid); } else { $record = (object) array('title' => get_string('customstylesforinstitution', 'admin', $newinstitution->displayname)); $styleid = insert_record('style', $record, 'id', true); } $properties = array(); $record = (object) array('style' => $styleid); foreach (array_keys($customthemedefaults) as $name) { $record->field = $name; $record->value = $values[$name]; insert_record('style_property', $record); $properties[$name] = $values[$name]; } // Cache the css $smarty = smarty_core(); $smarty->assign('data', $properties); set_field('style', 'css', $smarty->fetch('customcss.tpl'), 'id', $styleid); $newinstitution->style = $styleid; } else { $newinstitution->style = null; } if (get_config('licensemetadata')) { $newinstitution->licensemandatory = !empty($values['licensemandatory']) ? 1 : 0; $newinstitution->licensedefault = isset($values['licensedefault']) ? $values['licensedefault'] : ''; } if (!empty($values['resetcustom']) && !empty($oldinstitution->style)) { $newinstitution->style = null; } if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) { if (!empty($values['updateuserquotas']) && !empty($values['defaultquota'])) { execute_sql("UPDATE {usr} SET quota = ? WHERE id IN (SELECT usr FROM {usr_institution} WHERE institution = ?)", array($values['defaultquota'], $institution)); // get all the users from the institution and make sure that they are still below // their quota threshold if ($users = get_records_sql_array('SELECT * FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr AND ui.institution = ?', array($institution))) { $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit'); if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) { $quotanotifylimit = 100; } foreach ($users as $user) { $user->quota = $values['defaultquota']; // check if the user has gone over the quota notify limit $user->quotausedpercent = $user->quotaused / $user->quota * 100; $overlimit = false; if ($quotanotifylimit <= $user->quotausedpercent) { $overlimit = true; } $notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id); if ($overlimit && '1' !== $notified) { require_once get_config('docroot') . 'artefact/file/lib.php'; ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false); // no need to email admin as we can alert them right now $SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user))); } else { if ($notified && !$overlimit) { set_account_preference($user->id, 'quota_exceeded_notified', false); } } } } } $newinstitution->defaultquota = empty($values['defaultquota']) ? get_config_plugin('artefact', 'file', 'defaultquota') : $values['defaultquota']; } if ($institution != 'mahara') { $newinstitution->defaultmembershipperiod = $values['defaultmembershipperiod'] ? intval($values['defaultmembershipperiod']) : null; if ($USER->get('admin')) { $newinstitution->maxuseraccounts = $values['maxuseraccounts'] ? intval($values['maxuseraccounts']) : null; $newinstitution->expiry = db_format_timestamp($values['expiry']); } } $newinstitution->allowinstitutionpublicviews = isset($values['allowinstitutionpublicviews']) && $values['allowinstitutionpublicviews'] ? 1 : 0; // TODO: Move handling of authentication instances within the Institution class as well? if (!empty($values['authplugin'])) { $allinstances = array_merge($values['authplugin']['instancearray'], $values['authplugin']['deletearray']); if (array_diff($allinstances, $instancearray)) { throw new ConfigException('Attempt to delete or update another institution\'s auth instance'); } if (array_diff($instancearray, $allinstances)) { throw new ConfigException('One of your instances is unaccounted for in this transaction'); } foreach ($values['authplugin']['instancearray'] as $priority => $instanceid) { if (in_array($instanceid, $values['authplugin']['deletearray'])) { // Should never happen: throw new SystemException('Attempt to update AND delete an auth instance'); } $record = new StdClass(); $record->priority = $priority; $record->id = $instanceid; update_record('auth_instance', $record, array('id' => $instanceid)); } foreach ($values['authplugin']['deletearray'] as $instanceid) { // If this authinstance is the only xmlrpc authinstance that references a host, delete the host record. $hostwwwroot = null; foreach ($authinstances as $ai) { if ($ai->id == $instanceid && $ai->authname == 'xmlrpc') { $hostwwwroot = get_field_sql("SELECT \"value\" FROM {auth_instance_config} WHERE \"instance\" = ? AND field = 'wwwroot'", array($instanceid)); if ($hostwwwroot && count_records_select('auth_instance_config', "field = 'wwwroot' AND \"value\" = ?", array($hostwwwroot)) == 1) { // Unfortunately, it's possible that this host record could belong to a different institution, // so specify the institution here. delete_records('host', 'wwwroot', $hostwwwroot, 'institution', $institution); // We really need to fix this, either by removing the institution from the host table, or refusing to allow the // institution to be changed in the host record when another institution's authinstance is still pointing at it. } break; } } delete_records('auth_remote_user', 'authinstance', $instanceid); delete_records('auth_instance_config', 'instance', $instanceid); delete_records('auth_instance', 'id', $instanceid); // Make it no longer be the parent authority to any auth instances delete_records('auth_instance_config', 'field', 'parent', 'value', $instanceid); } } // Store plugin settings. plugin_institution_prefs_submit($form, $values, $newinstitution); // Save the changes to the DB $newinstitution->commit(); if ($add) { // Automatically create an internal authentication authinstance $authinstance = (object) array('instancename' => 'internal', 'priority' => 0, 'institution' => $newinstitution->name, 'authname' => 'internal'); insert_record('auth_instance', $authinstance); // We need to add the default lines to the site_content table for this institution // We also need to set the institution to be using default static pages to begin with // so that using custom institution pages is an opt-in situation $pages = site_content_pages(); $now = db_format_timestamp(time()); foreach ($pages as $name) { $page = new stdClass(); $page->name = $name; $page->ctime = $now; $page->mtime = $now; $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install')); $page->institution = $newinstitution->name; insert_record('site_content', $page); $institutionconfig = new stdClass(); $institutionconfig->institution = $newinstitution->name; $institutionconfig->field = 'sitepages_' . $name; $institutionconfig->value = 'mahara'; insert_record('institution_config', $institutionconfig); } } if (is_null($newinstitution->style) && !empty($oldinstitution->style)) { delete_records('style_property', 'style', $oldinstitution->style); delete_records('style', 'id', $oldinstitution->style); } // Set the logo after updating the institution, because the institution // needs to exist before it can own the logo artefact. if (!empty($values['logo'])) { safe_require('artefact', 'file'); // Entry in artefact table $data = (object) array('institution' => $institution, 'title' => 'logo', 'description' => 'Institution logo', 'note' => $values['logo']['name'], 'size' => $values['logo']['size']); $imageinfo = getimagesize($values['logo']['tmp_name']); $data->width = $imageinfo[0]; $data->height = $imageinfo[1]; $data->filetype = $imageinfo['mime']; $artefact = new ArtefactTypeProfileIcon(0, $data); if (preg_match("/\\.([^\\.]+)\$/", $values['logo']['name'], $saved)) { $artefact->set('oldextension', $saved[1]); } $artefact->commit(); $id = $artefact->get('id'); // Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . $id % 256 . '/'; check_dir_exists($directory); move_uploaded_file($values['logo']['tmp_name'], $directory . $id); // Delete the old logo if (!empty($oldinstitution->logo)) { $oldlogo = new ArtefactTypeProfileIcon($oldinstitution->logo); $oldlogo->delete(); } set_field('institution', 'logo', $id, 'name', $institution); } if (!empty($values['deletelogo'])) { execute_sql("UPDATE {institution} SET logo = NULL WHERE name = ?", array($institution)); } delete_records('institution_locked_profile_field', 'name', $institution); foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) { if ($values[$field]) { $profilefield = new StdClass(); $profilefield->name = $institution; $profilefield->profilefield = $field; insert_record('institution_locked_profile_field', $profilefield); } } db_commit(); if ($add) { if (!$newinstitution->registerallowed) { // If registration is not allowed, then an authinstance will not // have been created, and thus cause the institution page to add // its own error message on the next page load $SESSION->add_ok_msg(get_string('institutionaddedsuccessfully2', 'admin')); } $nexturl = '/admin/users/institutions.php?i=' . urlencode($institution); } else { $message = get_string('institutionupdatedsuccessfully', 'admin'); if (isset($values['theme'])) { $changedtheme = $oldinstitution->theme != $values['theme'] && (!empty($oldinstitution->theme) || $values['theme'] != 'sitedefault'); if ($changedtheme || $values['theme'] == 'custom') { $message .= ' ' . get_string('usersseenewthemeonlogin', 'admin'); } $USER->reset_institutions(); } $SESSION->add_ok_msg($message); $nexturl = '/admin/users/institutions.php'; } redirect($nexturl); }
function siteoptions_submit(Pieform $form, $values) { $fields = array('sitename', 'lang', 'theme', 'dropdownmenu', 'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap', 'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm', 'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock', 'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes', 'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources', 'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure', 'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers', 'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg', 'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay', 'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic', 'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs'); $count = 0; $where_sql = " WHERE admin = 0 AND id != 0"; // if default account lifetime expiry has no end date if (empty($values['defaultaccountlifetime'])) { if ($values['defaultaccountlifetimeupdate'] == 'all') { // need to remove user expiry db_begin(); $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); execute_sql("UPDATE {usr} SET expiry = NULL {$where_sql}"); db_commit(); } else { // make the 'some' option the same as 'none' as it is meaningless to // update existing users without expiry date to having 'no end date' $values['defaultaccountlifetimeupdate'] = 'none'; } } else { // fetch all the users that are not siteadmins $user_expiry = mktime(0, 0, 0, date('n'), date('j'), date('Y')) + (int) $values['defaultaccountlifetime']; if ($values['defaultaccountlifetimeupdate'] == 'some') { // and the user's expiry is not set $where_sql .= " AND expiry IS NULL"; $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); db_begin(); execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry))); db_commit(); } else { if ($values['defaultaccountlifetimeupdate'] == 'all') { // and the user's expiry is set db_begin(); $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry))); db_commit(); } } } // if public views are disabled, sitemap generation must also be disabled. if ($values['allowpublicviews'] == false) { $values['generatesitemap'] = false; } else { // Ensure allowpublicprofiles is set as well $values['allowpublicprofiles'] = 1; } $oldsearchplugin = get_config('searchplugin'); $oldlanguage = get_config('lang'); $oldtheme = get_config('theme'); foreach ($fields as $field) { if (!set_config($field, $values[$field])) { siteoptions_fail($form, $field); } } if ($oldlanguage != $values['lang']) { safe_require('artefact', 'file'); ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']); } save_notification_settings($values, null, true); if ($oldsearchplugin != $values['searchplugin']) { // Call the old search plugin's sitewide cleanup method safe_require('search', $oldsearchplugin); call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide'); // Call the new search plugin's sitewide initialize method safe_require('search', $values['searchplugin']); $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide'); if (!$initialize) { $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php')); } } // Call the new search plugin's can connect safe_require('search', $values['searchplugin']); $connect = call_static_method(generate_class_name('search', $values['searchplugin']), 'can_connect'); if (!$connect) { $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php')); } // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) { siteoptions_fail($form, 'sessionlifetime'); } // Submitted value is on/off; database entry should be 1/0 foreach (array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) { if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) { siteoptions_fail($form, $checkbox); } } if ($values['viruschecking'] == 'on') { $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam'))); if (!$pathtoclam) { $form->reply(PIEFORM_ERR, array('message' => get_string('clamnotset', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php')); } else { if (!file_exists($pathtoclam) && !is_executable($pathtoclam)) { $form->reply(PIEFORM_ERR, array('message' => get_string('clamlost', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php')); } } } if (get_config('recaptchaonregisterform') && !(get_config('recaptchapublickey') && get_config('recaptchaprivatekey'))) { $form->reply(PIEFORM_ERR, array('message' => get_string('recaptchakeysmissing1', 'admin'), 'goto' => '/admin/site/options.php')); } // Need to clear the cached menus in case site config changes effect them. clear_menu_cache(); $message = get_string('siteoptionsset', 'admin'); if ($oldtheme != $values['theme']) { global $USER; $message .= ' ' . get_string('usersseenewthemeonlogin', 'admin'); $USER->reset_institutions(); } if ($count) { $message .= ' ' . get_string('numberusersupdated', 'admin', $count); } $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php')); }
// Update local version $config = new StdClass(); require get_config('docroot') . 'local/version.php'; set_config('localversion', $config->version); set_config('localrelease', $config->release); // Installation is finished set_config('installed', true); log_info('Installation complete.'); $USER->login('admin', 'mahara'); } } json_reply(false, $data); } if (!empty($upgrade)) { // clear out menu cache to allow upgraded site to remake cached menus clear_menu_cache(); if (!empty($upgrade->errormsg)) { $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')'; $data['install'] = false; $data['error'] = false; $data['message'] = get_string('notinstalled', 'admin') . ': ' . $upgrade->errormsg; json_reply('local', $data); } $data['newversion'] = $upgrade->torelease . ' (' . $upgrade->to . ')'; if ($name == 'core') { $funname = 'upgrade_core'; } else { if ($name == 'local') { $funname = 'upgrade_local'; } else { $funname = 'upgrade_plugin';