public function dump_export_data() { if ($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS && $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) { // Dont' care about profile information in this case return; } $smarty = $this->exporter->get_smarty('../../', 'internal'); $smarty->assign('page_heading', get_string('profilepage', 'artefact.internal')); // Profile page $profileviewid = $this->exporter->get('user')->get_profile_view()->get('id'); foreach ($this->exporter->get('views') as $viewid => $view) { if ($profileviewid == $viewid) { $smarty->assign('breadcrumbs', array(array('text' => 'Profile page', 'path' => 'profilepage.html'))); $view = $this->exporter->get('user')->get_profile_view(); $outputfilter = new HtmlExportOutputFilter('../../'); $smarty->assign('view', $outputfilter->filter($view->build_columns())); $content = $smarty->fetch('export:html/internal:profilepage.tpl'); if (!file_put_contents($this->fileroot . 'profilepage.html', $content)) { throw new SystemException("Unable to write profile page"); } $this->profileviewexported = true; break; } } // Generic profile information $smarty->assign('page_heading', get_string('profileinformation', 'artefact.internal')); $smarty->assign('breadcrumbs', array(array('text' => 'Profile information', 'path' => 'index.html'))); // Organise profile information by sections, ordered how it's ordered // on the 'edit profile' page $sections = array('aboutme' => array(), 'contact' => array(), 'messaging' => array(), 'general' => array()); $elementlist = call_static_method('ArtefactTypeProfile', 'get_all_fields'); $elementlistlookup = array_flip(array_keys($elementlist)); $profilefields = get_column_sql('SELECT id FROM {artefact} WHERE owner=? AND artefacttype IN (' . join(",", array_map(create_function('$a', 'return db_quote($a);'), array_keys($elementlist))) . ")", array($this->exporter->get('user')->get('id'))); foreach ($profilefields as $id) { $artefact = artefact_instance_from_id($id); $rendered = $artefact->render_self(array('link' => true)); if ($artefact->get('artefacttype') == 'introduction') { $outputfilter = new HtmlExportOutputFilter('../../'); $rendered['html'] = $outputfilter->filter($rendered['html']); } $sections[$this->get_category_for_artefacttype($artefact->get('artefacttype'))][$artefact->get('artefacttype')] = array('html' => $rendered['html'], 'weight' => $elementlistlookup[$artefact->get('artefacttype')]); } // Sort the data and then drop the weighting information foreach ($sections as &$section) { uasort($section, create_function('$a, $b', 'return $a["weight"] > $b["weight"];')); foreach ($section as &$data) { $data = $data['html']; } } $smarty->assign('sections', $sections); $iconid = $this->exporter->get('user')->get('profileicon'); if ($iconid) { $icon = artefact_instance_from_id($iconid); $smarty->assign('icon', '<img src="../../static/profileicons/200px-' . PluginExportHtml::sanitise_path($icon->get('title')) . '" alt="Profile Icon">'); } $content = $smarty->fetch('export:html/internal:index.tpl'); if (!file_put_contents($this->fileroot . 'index.html', $content)) { throw new SystemException("Unable to write profile information page"); } }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $viewid = $instance->get('view'); $wwwroot = get_config('wwwroot'); $files = array(); if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $file = array('id' => $artefactid, 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'size' => $artefact->get('size'), 'ctime' => $artefact->get('ctime'), 'artefacttype' => $artefact->get('artefacttype'), 'iconsrc' => call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', array('id' => $artefactid, 'viewid' => $viewid)), 'downloadurl' => $wwwroot); if ($artefact instanceof ArtefactTypeProfileIcon) { $file['downloadurl'] .= 'thumb.php?type=profileiconbyid&id=' . $artefactid; } else { if ($artefact instanceof ArtefactTypeFile) { $file['downloadurl'] .= 'artefact/file/download.php?file=' . $artefactid . '&view=' . $viewid; } } $file['is_image'] = $artefact instanceof ArtefactTypeImage ? true : false; $files[] = $file; } } $smarty = smarty_core(); $smarty->assign('viewid', $instance->get('view')); $smarty->assign('files', $files); return $smarty->fetch('blocktype:filedownload:filedownload.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $result = ''; if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $icondata = array('id' => $artefactid, 'viewid' => $instance->get('view')); $detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); if ($artefact instanceof ArtefactTypeProfileIcon) { require_once 'file.php'; $downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid)); } else { if ($artefact instanceof ArtefactTypeFile) { $downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid']; $size = $artefact->get('size'); } } $result .= '<div title="' . hsc($artefact->get('title')) . '">'; $result .= '<div class="fl"><a href="' . hsc($downloadurl) . '">'; $result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata)) . '" alt=""></a></div>'; $result .= '<div style="margin-left: 30px;">'; $result .= '<h4><a href="' . hsc($detailsurl) . '">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>'; $description = $artefact->get('description'); if ($description) { $result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>'; } $result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'), $artefact->get('ctime')); $result .= '</div>'; $result .= '</div>'; } } return $result; }
/** * constructor. overrides the parent class * to set up smarty and the attachment directory */ public function __construct(User $user, $views, $artefacts, $progresshandler = null) { parent::__construct($user, $views, $artefacts, $progresshandler); $this->smarty = smarty_core(); if (!check_dir_exists($this->exportdir . '/' . $this->filedir)) { throw new SystemException("Couldn't create the temporary export directory {$this->exportdir}"); } $this->zipfile = 'mahara-export-leap-user' . $this->get('user')->get('id') . '-' . date('Y-m-d_H-i', $this->exporttime) . '_' . get_random_key() . '.zip'; // some plugins might want to do their own special thing foreach (plugins_installed('artefact', true) as $plugin) { $plugin = $plugin->name; if (safe_require('export', 'leap/' . $plugin, 'lib.php', 'require_once', true)) { $classname = 'LeapExport' . ucfirst($plugin); if (class_exists($classname) && call_static_method($classname, 'override_entire_export')) { $this->specialcases[$plugin] = array(); } } } $outputfilter = LeapExportOutputFilter::singleton(); $outputfilter->set_artefactids(array_keys($this->artefacts)); $this->notify_progress_callback(5, get_string('setupcomplete', 'export')); }
/** * Convert a Mahara plugin template file path into a normal template file path with extra search paths. * * @param string $pluginfile The plugintype, name, and name of file, e.g. "blocktype:clippy:index.tpl" * @param int $cacheTime Not used. * @param int $cacheId Not used. * @param int $compileId Not used. * @param array $includePath The paths to look in. * @throws MaharaException */ public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = null) { global $THEME; $parts = explode(':', $file, 3); if (count($parts) !== 3) { throw new SystemException("Invalid template path \"{$file}\""); } // Keep the original string for logging purposes $dwooref = $file; list($plugintype, $pluginname, $file) = $parts; // Since we use $plugintype as part of a file path, we should whitelist it $plugintype = strtolower($plugintype); if (!in_array($plugintype, plugin_types())) { throw new SystemException("Invalid plugintype in Dwoo template \"{$dwooref}\""); } // Get the relative path for this particular plugin require_once get_config('docroot') . $plugintype . '/lib.php'; $pluginpath = call_static_method(generate_class_name($plugintype), 'get_theme_path', $pluginname); // Because this is a plugin template file, we don't want to include any accidental matches against // core template files with the same name. $includePath = array(); // First look for a local override. $includePath[] = get_config('docroot') . "local/theme/{$pluginpath}/templates"; // Then look for files in a custom theme foreach ($THEME->inheritance as $theme) { $includePath[] = get_config('docroot') . "theme/{$theme}/{$pluginpath}/templates"; } // Lastly look for files in the plugin itself foreach ($THEME->inheritance as $theme) { $includePath[] = get_config('docroot') . "{$pluginpath}/theme/{$theme}/templates"; // For legacy purposes also look for the template file loose under the theme directory. $includePath[] = get_config('docroot') . "{$pluginpath}/theme/{$theme}"; } // Now, we instantiate this as a standard Dwoo_Template_File class. // We're passing in $file, which is the relative path to the file, and // $includePath, which is an array of directories to search for $file in. // We let Dwoo figure out which one actually has it. parent::__construct($file, null, null, null, $includePath); }
/** * Builds the pieform for the search field in the page header */ function header_search_form() { $plugin = get_config('searchplugin'); safe_require('search', $plugin); return call_static_method(generate_class_name('search', $plugin), 'header_search_form'); }
/** * Optional method. If specified, allows the blocktype class to munge the * artefactchooser element data before it's templated */ public static function artefactchooser_get_element_data($artefact) { $folderdata = ArtefactTypeFileBase::artefactchooser_folder_data($artefact); $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); $artefact->hovertitle = $artefact->description; $path = $artefact->parent ? ArtefactTypeFileBase::get_full_path($artefact->parent, $folderdata->data) : ''; $artefact->description = str_shorten_text($folderdata->ownername . $path . $artefact->title, 30); return $artefact; }
// If some other cron instance ran the job while we were messing around, // skip it. $nextrun = get_field_sql(' SELECT ' . db_format_tsfield('nextrun') . ' FROM {' . $table . '} WHERE plugin = ? AND callfunction = ?', array($job->plugin, $job->callfunction)); if ($nextrun != $job->nextrun) { log_info("Too late to run {$plugintype} {$job->plugin} {$job->callfunction}; skipping."); cron_free($job, $start, $plugintype); continue; } $classname = generate_class_name($plugintype, $job->plugin); log_info("Running {$classname}::" . $job->callfunction); safe_require($plugintype, $job->plugin, 'lib.php', 'require_once'); try { call_static_method($classname, $job->callfunction); } catch (Exception $e) { log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace()); $output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage(); echo "{$output}\n"; // Don't call handle_exception; try to update next run time and free the lock } $nextrun = cron_next_run_time($start, (array) $job); // update next run time set_field($plugintype . '_cron', 'nextrun', db_format_timestamp($nextrun), 'plugin', $job->plugin, 'callfunction', $job->callfunction); cron_free($job, $start, $plugintype); $now = $fake ? time() - ($realstart - $start) : time(); } } } // and now the core ones (much simpler)
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')); }
public static function artefactchooser_get_element_data($artefact) { $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id)); return $artefact; }
function right_nav() { global $USER, $THEME; safe_require('notification', 'internal'); $unread = call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')); $menu = array(array('path' => 'settings', 'wwwroot' => get_config('httpswwwroot'), 'url' => 'account/', 'title' => get_string('settings'), 'icon' => $THEME->get_url('images/settings.png'), 'alt' => get_string('settings'), 'weight' => 10), array('path' => 'inbox', 'url' => 'account/activity', 'icon' => $THEME->get_url('images/email.gif'), 'alt' => get_string('inbox'), 'count' => $unread, 'countclass' => 'unreadmessagecount', 'weight' => 20), array('path' => 'settings/account', 'url' => 'account/', 'title' => get_string('account'), 'weight' => 10), array('path' => 'settings/notifications', 'url' => 'account/activity/preferences/', 'title' => get_string('notifications'), 'weight' => 30), array('path' => 'settings/institutions', 'url' => 'account/institutions.php', 'title' => get_string('institutionmembership'), 'weight' => 40)); $menu_structure = find_menu_children($menu, ''); return $menu_structure; }
public function get_data($key, $id) { if (!isset($this->temp[$key][$id])) { $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); if (!isset($this->temp[$key])) { $this->temp[$key] = array(); } $this->temp[$key][$id] = call_static_method($blocktypeclass, 'get_instance_' . $key, $id); } return $this->temp[$key][$id]; }
/** * Submit plugin account form values. * * @param Pieform $form * @param array $values * @return bool is page need to be refreshed */ function plugin_account_prefs_submit(Pieform $form, $values) { $reload = false; $elements = array(); $installed = plugin_all_installed(); foreach ($installed as $i) { if (!safe_require_plugin($i->plugintype, $i->name)) { continue; } $reload = call_static_method(generate_class_name($i->plugintype, $i->name), 'accountprefs_submit', $form, $values) || $reload; } return $reload; }
public function get_goals_and_skills($type = '') { global $USER; switch ($type) { case 'goals': $artefacts = array('personalgoal', 'academicgoal', 'careergoal'); break; case 'skills': $artefacts = array('personalskill', 'academicskill', 'workskill'); break; default: $artefacts = array('personalgoal', 'academicgoal', 'careergoal', 'personalskill', 'academicskill', 'workskill'); } $data = array(); foreach ($artefacts as $artefact) { $record = get_record('artefact', 'artefacttype', $artefact, 'owner', $USER->get('id')); if ($record) { $record->exists = 1; // Add attachments $files = ArtefactType::attachments_from_id_list(array($record->id)); if ($files) { safe_require('artefact', 'file'); foreach ($files as &$file) { $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', array('id' => $file->attachment)); $record->files[] = $file; } $record->count = count($files); } else { $record->count = 0; } } else { $record = new stdClass(); $record->artefacttype = $artefact; $record->exists = 0; $record->count = 0; } $data[] = $record; } return $data; }
$userid = param_integer('user'); define('GROUP', $groupid); $group = group_current_group(); $user = get_record('usr', 'id', $userid, 'deleted', 0); if (!$user) { throw new UserNotFoundException(get_string('usernotfound', 'group', $userid)); } if ($group->jointype != 'invite' || group_user_access($groupid) != 'admin') { throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group')); } if (record_exists('group_member', 'group', $groupid, 'member', $userid) || record_exists('group_member_invite', 'group', $groupid, 'member', $userid)) { throw new UserException(get_string('useralreadyinvitedtogroup', 'group')); } define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name)); $roles = group_get_role_info($groupid); foreach ($roles as $k => &$v) { $v = $v->display; } safe_require('grouptype', $group->grouptype); $form = pieform(array('name' => 'invitetogroup', 'autofocus' => false, 'method' => 'post', 'elements' => array('reason' => array('type' => 'textarea', 'cols' => 50, 'rows' => 4, 'title' => get_string('reason')), 'role' => array('type' => 'select', 'options' => $roles, 'title' => get_string('Role', 'group'), 'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role')), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('invite', 'group'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'user/view.php?id=' . $userid)))); $smarty = smarty(); $smarty->assign('subheading', TITLE); $smarty->assign('form', $form); $smarty->display('group/invite.tpl'); function invitetogroup_submit(Pieform $form, $values) { global $SESSION, $USER, $group, $user; group_invite_user($group, $user->id, $USER, $values['role']); $SESSION->add_ok_msg(get_string('userinvited', 'group')); redirect('/user/view.php?id=' . $user->id); }
function auth_config_submit(Pieform $form, $values) { global $SESSION; $plugin = $values['authname']; $classname = 'PluginAuth' . ucfirst(strtolower($plugin)); safe_require('auth', strtolower($plugin)); try { $values = call_static_method($classname, 'save_config_options', $values, $form); } catch (Exception $e) { log_info($e->getMessage()); log_info($e->getTrace()); $SESSION->add_error_msg("An error occurred while processing this form: " . $e->getMessage()); redirect('/admin/users/addauthority.php?' . $_SERVER['QUERY_STRING']); } if (array_key_exists('create', $values) && $values['create']) { execute_javascript_and_close('window.opener.addAuthority(' . $values['instance'] . ', "' . addslashes($values['instancename']) . '", "' . $values['authname'] . '");'); } else { execute_javascript_and_close(); } exit; }
$plugins[$plugin]['installed'][$key]['types'] = array(); safe_require('artefact', $key); if ($types = call_static_method(generate_class_name('artefact', $i->name), 'get_artefact_types')) { foreach ($types as $t) { $classname = generate_artefact_class_name($t); if ($collapseto = call_static_method($classname, 'collapse_config')) { $plugins[$plugin]['installed'][$key]['types'][$collapseto] = true; } else { $plugins[$plugin]['installed'][$key]['types'][$t] = call_static_method($classname, 'has_config'); } } } } else { $classname = generate_class_name($plugin, $i->name); safe_require($plugin, $key); if (call_static_method($classname, 'has_config')) { $plugins[$plugin]['installed'][$key]['config'] = true; } } } } $dirhandle = opendir(get_config('docroot') . $plugin); while (false !== ($dir = readdir($dirhandle))) { $installed = false; // reinitialise if (strpos($dir, '.') === 0) { continue; } if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) { continue; }
/** * Builds data for the artefact chooser. * * This builds three pieces of information: * * - HTML containing table rows * - Pagination HTML and Javascript * - The total number of artefacts found * - Artefact fields to return */ public static function build_artefactchooser_data($data, $group = null, $institution = null) { global $USER; // If lazyload is set, immediately return an empty resultset // In the case of forms using lazyload, lazyload is set to false by subsequent requests via ajax, // for example in views/artefactchooser.json.php, at which time the full resultset is returned. if (isset($data['lazyload']) && $data['lazyload']) { $result = ''; $pagination = build_pagination(array('id' => $data['name'] . '_pagination', 'class' => 'ac-pagination', 'url' => View::make_base_url() . (param_boolean('s') ? '&s=1' : ''), 'count' => 0, 'limit' => 0, 'offset' => 0, 'datatable' => $data['name'] . '_data', 'jsonscript' => 'view/artefactchooser.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'extradata' => array('value' => $data['defaultvalue'], 'blocktype' => $data['blocktype'], 'group' => $group, 'institution' => $institution))); return array($result, $pagination, 0, 0, array()); } $search = ''; if (!empty($data['search']) && param_boolean('s')) { $search = param_variable('search', ''); // Maybe later, depending on performance - don't search if there's // not enough characters. Prompts should be added to the UI too. //if (strlen($search) < 3) { // $search = ''; //} } $data['search'] = $search; $data['offset'] -= $data['offset'] % $data['limit']; safe_require('blocktype', $data['blocktype']); $blocktypeclass = generate_class_name('blocktype', $data['blocktype']); $data['sortorder'] = array(array('fieldname' => 'title', 'order' => 'ASC')); if (method_exists($blocktypeclass, 'artefactchooser_get_sort_order')) { $data['sortorder'] = call_static_method($blocktypeclass, 'artefactchooser_get_sort_order'); } list($artefacts, $totalartefacts) = self::get_artefactchooser_artefacts($data, $USER, $group, $institution); $selectone = $data['selectone']; $value = $data['defaultvalue']; $elementname = $data['name']; $template = $data['template']; $returnfields = isset($data['returnfields']) ? $data['returnfields'] : null; $returnartefacts = array(); $result = ''; if ($artefacts) { if (!empty($data['ownerinfo'])) { require_once get_config('docroot') . 'artefact/lib.php'; $userid = $group || $institution ? null : $USER->get('id'); foreach (artefact_get_owner_info(array_keys($artefacts)) as $k => $v) { if ($artefacts[$k]->owner !== $userid || $artefacts[$k]->group !== $group || $artefacts[$k]->institution !== $institution) { $artefacts[$k]->ownername = $v->name; $artefacts[$k]->ownerurl = $v->url; } } } foreach ($artefacts as &$artefact) { safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $artefact->artefacttype)); if (method_exists($blocktypeclass, 'artefactchooser_get_element_data')) { $artefact = call_static_method($blocktypeclass, 'artefactchooser_get_element_data', $artefact); } // Build the radio button or checkbox for the artefact $formcontrols = ''; if ($selectone) { $formcontrols .= '<input type="radio" class="radio" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '" value="' . hsc($artefact->id) . '"'; if ($value == $artefact->id) { $formcontrols .= ' checked="checked"'; } $formcontrols .= '>'; } else { $formcontrols .= '<input type="checkbox" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '[' . hsc($artefact->id) . ']"'; if ($value && in_array($artefact->id, $value)) { $formcontrols .= ' checked="checked"'; } $formcontrols .= ' class="artefactid-checkbox checkbox">'; $formcontrols .= '<input type="hidden" name="' . hsc($elementname) . '_onpage[]" value="' . hsc($artefact->id) . '" class="artefactid-onpage">'; } $smarty = smarty_core(); $smarty->assign('artefact', $artefact); $smarty->assign('elementname', $elementname); $smarty->assign('formcontrols', $formcontrols); $result .= $smarty->fetch($template) . "\n"; if ($returnfields) { $returnartefacts[$artefact->id] = array(); foreach ($returnfields as $f) { if ($f == 'safedescription') { $returnartefacts[$artefact->id]['safedescription'] = clean_html($artefact->description); continue; } if ($f == 'attachments') { // Check if the artefact has attachments - we need to update the instance config form // to have those attachments selected. $attachment_ids = get_column('artefact_attachment', 'attachment', 'artefact', $artefact->id); $returnartefacts[$artefact->id]['attachments'] = $attachment_ids; continue; } $returnartefacts[$artefact->id][$f] = $artefact->{$f}; } } } if ($returnfields && !empty($data['getblocks'])) { // Get ids of the blocks containing these artefacts $blocks = get_records_select_array('view_artefact', 'artefact IN (' . join(',', array_fill(0, count($artefacts), '?')) . ')', array_keys($artefacts)); if (!empty($blocks)) { // For each artefact, attach a list of block ids of all the blocks // that contain it. foreach ($blocks as $block) { if (empty($returnartefacts[$block->artefact]['blocks'])) { $returnartefacts[$block->artefact]['blocks'] = array(); } $returnartefacts[$block->artefact]['blocks'][] = $block->block; } } } } $pagination = build_pagination(array('id' => $elementname . '_pagination', 'class' => 'ac-pagination', 'url' => View::make_base_url() . (param_boolean('s') ? '&s=1' : ''), 'count' => $totalartefacts, 'limit' => $data['limit'], 'offset' => $data['offset'], 'datatable' => $elementname . '_data', 'jsonscript' => 'view/artefactchooser.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'extradata' => array('value' => $value, 'blocktype' => $data['blocktype'], 'group' => $group, 'institution' => $institution))); return array($result, $pagination, $totalartefacts, $data['offset'], $returnartefacts); }
/** * Does a bulk_delete on a list of artefacts, grouping artefacts of * the same type. * * Currently only tested for folders and their contents. */ public static function delete_by_artefacttype($artefactids) { if (empty($artefactids)) { return; } db_begin(); artefact_watchlist_notification($artefactids); // Delete comments first safe_require('artefact', 'comment'); ArtefactTypeComment::delete_comments_onartefacts($artefactids); $records = get_records_select_assoc('artefact', 'id IN (' . join(',', array_map('intval', $artefactids)) . ')', null, 'artefacttype', 'id,parent,artefacttype,container'); $containers = array(); $leaves = array(); foreach ($records as $r) { if ($r->container) { $containers[$r->artefacttype][] = (int) $r->id; } else { $leaves[$r->artefacttype][] = $r->id; } } // Delete non-containers grouped by artefacttype foreach ($leaves as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); call_static_method($classname, 'bulk_delete', $ids); } // Delete containers grouped by artefacttype foreach ($containers as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); if (is_mysql()) { set_field_select('artefact', 'parent', null, 'id IN (' . join(',', $ids) . ')', array()); } call_static_method($classname, 'bulk_delete', $ids); } handle_event('deleteartefacts', $artefactids); db_commit(); }
function xmldb_blocktype_externalfeed_upgrade($oldversion = 0) { if ($oldversion < 2008042101) { // We hit the 255 character limit for feed URLs if (is_postgres()) { execute_sql('ALTER TABLE {blocktype_externalfeed_data} ALTER COLUMN url TYPE TEXT'); } else { if (is_mysql()) { // If 2 URLs > 255 chars have the same first 255 characters then mahara will error - this is a MySQL issue though, their unique key length limit is to blame execute_sql('ALTER TABLE {blocktype_externalfeed_data} DROP KEY {blocextedata_url_uix}'); // We have to remove then add the constraint again else the change will make MySQL cry execute_sql('ALTER TABLE {blocktype_externalfeed_data} MODIFY COLUMN "url" text'); execute_sql('ALTER TABLE {blocktype_externalfeed_data} add unique {blocextedata_url_uix} (url(255))'); } } } if ($oldversion < 2009121600) { if (is_mysql()) { // Make content column wider (TEXT is only 65kb in mysql) $table = new XMLDBTable('blocktype_externalfeed_data'); $field = new XMLDBField('content'); $field->setAttributes(XMLDB_TYPE_TEXT, "big", null, null); change_field_precision($table, $field); } } if ($oldversion < 2010073000) { execute_sql(' UPDATE {blocktype_cron} SET minute = ? WHERE minute = ? AND hour = ? AND plugin = ? AND callfunction = ?', array('30', '0', '3', 'externalfeed', 'cleanup_feeds')); } if ($oldversion < 2011091400) { // Add columns for HTTP basic auth $table = new XMLDBTable('blocktype_externalfeed_data'); $field1 = new XMLDBField('authuser'); $field1->setAttributes(XMLDB_TYPE_TEXT); $field2 = new XMLDBField('authpassword'); $field2->setAttributes(XMLDB_TYPE_TEXT); add_field($table, $field1); add_field($table, $field2); // Change unique constraint that's no longer valid $table = new XMLDBTable('blocktype_externalfeed_data'); $index = new XMLDBIndex('url_uix'); $index->setAttributes(XMLDB_INDEX_UNIQUE, array('url')); drop_index($table, $index); if (is_postgres()) { $index = new XMLDBIndex('urlautautix'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('url', 'authuser', 'authpassword')); add_index($table, $index); } else { if (is_mysql()) { // MySQL needs size limits when indexing text fields execute_sql('ALTER TABLE {blocktype_externalfeed_data} ADD INDEX {blocextedata_urlautaut_ix} (url(255), authuser(255), authpassword(255))'); } } } if ($oldversion < 2011091401) { // Add columns for insecure SSL mode $table = new XMLDBTable('blocktype_externalfeed_data'); $field = new XMLDBField('insecuresslmode'); $field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0); add_field($table, $field); } if ($oldversion < 2012090700) { // Reset all feeds to reset themselves set_field('blocktype_externalfeed_data', 'lastupdate', db_format_timestamp('0')); safe_require('blocktype', 'externalfeed'); call_static_method('PluginBlocktypeExternalfeed', 'refresh_feeds'); } if ($oldversion < 2014041500) { log_debug('Cleaning up duplicate feeds in the externalfeed blocktype'); log_debug('1. Find the duplicate feed urls'); // Setting these to be empty strings instead of NULL will make our SQL a lot simpler in the next section execute_sql("update {blocktype_externalfeed_data} set authuser='' where authuser is null"); execute_sql("update {blocktype_externalfeed_data} set authpassword='' where authpassword is null"); if ($duplicatefeeds = get_records_sql_array("SELECT COUNT(url), url, authuser, authpassword FROM {blocktype_externalfeed_data} GROUP BY url, authuser, authpassword HAVING COUNT(url) > 1 ORDER BY url, authuser, authpassword", array())) { log_debug('2. Get all feed ids for the duplicated feed urls'); // Use the 1st one found to be the feed id for the block instances that need updating $feedstoupdate = array(); foreach ($duplicatefeeds as $feed) { $feedids = get_column('blocktype_externalfeed_data', 'id', 'url', $feed->url, 'authuser', $feed->authuser, 'authpassword', $feed->authpassword); $feedstoupdate[$feed->url] = $feedids; } log_debug('3. Updating blocks to use correct feed id'); // Find the block instances using external feeds. Check to see if they are not using the 'true' id and update them accordingly require_once get_config('docroot') . 'blocktype/lib.php'; $blockids = get_records_array('block_instance', 'blocktype', 'externalfeed', 'id ASC', 'id'); foreach ($blockids as $blockid) { $blockinstance = new BlockInstance($blockid->id); $configdata = $blockinstance->get('configdata'); if (!empty($configdata['feedid'])) { foreach ($feedstoupdate as $url => $ids) { foreach ($ids as $key => $id) { if ($id == $configdata['feedid'] && $key != '0') { $configdata['feedid'] = $ids[0]; $blockinstance->set('configdata', $configdata); $blockinstance->set('dirty', true); $blockinstance->commit(); break; } } } } } log_debug('4. Removing orphaned feed rows'); foreach ($feedstoupdate as $url => $ids) { foreach ($ids as $key => $id) { if ($key != '0') { execute_sql("DELETE FROM {blocktype_externalfeed_data} WHERE id = ?", array($id)); } } } } } return true; }
function install_blocktype_viewtypes_for_plugin($blocktype) { safe_require('blocktype', $blocktype); $blocktype = blocktype_namespaced_to_single($blocktype); db_begin(); delete_records('blocktype_installed_viewtype', 'blocktype', $blocktype); if ($viewtypes = call_static_method(generate_class_name('blocktype', $blocktype), 'get_viewtypes')) { foreach ($viewtypes as $vt) { insert_record('blocktype_installed_viewtype', (object) array('blocktype' => $blocktype, 'viewtype' => $vt)); } } db_commit(); }
/** * Gets the new/edit activities pieform * */ public static function get_form($parent, $activity = null) { require_once get_config('libroot') . 'pieforms/pieform.php'; $elements = call_static_method(generate_artefact_class_name('activity'), 'get_activityform_elements', $parent, $activity); $elements['submit'] = array('type' => 'submitcancel', 'class' => 'btn-primary', 'value' => array(get_string('saveactivity', 'artefact.cpds'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/cpds/cpd.php?id=' . (int) $parent); $activityform = array('name' => empty($activity) ? 'addactivities' : 'editactivity', 'plugintype' => 'artefact', 'pluginname' => 'activity', 'validatecallback' => array(generate_artefact_class_name('activity'), 'validate'), 'successcallback' => array(generate_artefact_class_name('activity'), 'submit'), 'elements' => $elements); return pieform($activityform); }
public function notify_user($user) { $changes = new stdClass(); $userdata = $this->to_stdclass(); // some stuff gets overridden by user specific stuff if (!empty($user->url)) { $userdata->url = $user->url; } if (empty($user->lang) || $user->lang == 'default') { $user->lang = get_config('lang'); } if (empty($user->method)) { // If method is not set then either the user has selected 'none' or their setting has not been set (so use default). if ($record = get_record('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) { $user->method = $record->method; if (empty($user->method)) { // The user specified 'none' as their notification type. return; } } else { $user->method = $this->get_default_method(); if (empty($user->method)) { // The default notification type is 'none' for this activity type. return; } } } // always do internal foreach (PluginNotificationInternal::$userdata as &$p) { $function = 'get_' . $p; $userdata->{$p} = $this->{$function}($user); } $userdata->internalid = PluginNotificationInternal::notify_user($user, $userdata); if ($this->update_url($userdata->internalid)) { $changes->url = $userdata->url = $this->url; } if ($user->method != 'internal' || isset($changes->url)) { // OVERWRITE 1: replacement, changed from: //$changes->read = (int) ($user->method != 'internal'); $changes->read = 0; // END OVERWRITE 1 $changes->id = $userdata->internalid; update_record('notification_internal_activity', $changes); } if ($user->method != 'internal') { $method = $user->method; safe_require('notification', $method); $notificationclass = generate_class_name('notification', $method); $classvars = get_class_vars($notificationclass); if (!empty($classvars['userdata'])) { foreach ($classvars['userdata'] as &$p) { $function = 'get_' . $p; if (!isset($userdata->{$p}) && method_exists($this, $function)) { $userdata->{$p} = $this->{$function}($user); } } } try { call_static_method($notificationclass, 'notify_user', $user, $userdata); } catch (MaharaException $e) { static $badnotification = false; static $adminnotified = array(); // We don't mind other notification methods failing, as it'll // go into the activity log as 'unread' $changes->read = 0; update_record('notification_internal_activity', $changes); if (!$badnotification && !($e instanceof EmailDisabledException || $e instanceof InvalidEmailException)) { // Admins should probably know about the error, but to avoid sending too many similar notifications, // save an initial prefix of the message being sent and throw away subsequent exceptions with the // same prefix. To cut down on spam, it's worth missing out on a few similar messages. $k = substr($e, 0, 60); if (!isset($adminnotified[$k])) { $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminnotificationerror', 'activity'), 'message' => $e); $adminnotified[$k] = 1; $badnotification = true; activity_occurred('maharamessage', $message); $badnotification = false; } } } } // The user's unread message count does not need to be updated from $changes->read // because of the db trigger on notification_internal_activity. }
/** * Returns a datastructure describing the tabs that appear on a group page * * @param object $group Database record of group to get tabs for * @return array */ function group_get_menu_tabs() { static $menu; $group = group_current_group(); if (!$group) { return null; } $role = group_user_access($group->id); $menu = array('info' => array('path' => 'groups/info', 'url' => group_homepage_url($group, false), 'title' => get_string('About', 'group'), 'weight' => 20)); if (group_can_list_members($group, $role)) { $menu['members'] = array('path' => 'groups/members', 'url' => 'group/members.php?id=' . $group->id, 'title' => get_string('Members', 'group'), 'weight' => 30); } if ($interactionplugins = plugins_installed('interaction')) { foreach ($interactionplugins as $plugin) { safe_require('interaction', $plugin->name); $plugin_menu = call_static_method(generate_class_name('interaction', $plugin->name), 'group_menu_items', $group); $menu = array_merge($menu, $plugin_menu); } } $menu['views'] = array('path' => 'groups/views', 'url' => 'view/groupviews.php?group=' . $group->id, 'title' => get_string('Views', 'group'), 'weight' => 50); $menu['collections'] = array('path' => 'groups/collections', 'url' => 'collection/index.php?group=' . $group->id, 'title' => get_string('Collections', 'group'), 'weight' => 60); if (group_role_can_edit_views($group, $role)) { $menu['share'] = array('path' => 'groups/share', 'url' => 'group/shareviews.php?group=' . $group->id, 'title' => get_string('share', 'view'), 'weight' => 70); } if ($role) { safe_require('grouptype', $group->grouptype); $artefactplugins = call_static_method('GroupType' . $group->grouptype, 'get_group_artefact_plugins'); if ($plugins = plugins_installed('artefact')) { foreach ($plugins as &$plugin) { if (!in_array($plugin->name, $artefactplugins)) { continue; } safe_require('artefact', $plugin->name); $plugin_menu = call_static_method(generate_class_name('artefact', $plugin->name), 'group_tabs', $group->id); $menu = array_merge($menu, $plugin_menu); } } } if (group_role_can_access_report($group, $role)) { $menu['report'] = array('path' => 'groups/report', 'url' => 'group/report.php?group=' . $group->id, 'title' => get_string('report', 'group'), 'weight' => 70); } if (defined('MENUITEM')) { $key = substr(MENUITEM, strlen('groups/')); if ($key && isset($menu[$key])) { $menu[$key]['selected'] = true; } } return $menu; }
function get_search_plugins() { $searchpluginoptions = array(); if ($searchplugins = plugins_installed('search')) { foreach ($searchplugins as $plugin) { safe_require_plugin('search', $plugin->name, 'lib.php'); if (!call_static_method(generate_class_name('search', $plugin->name), 'is_available_for_site_setting')) { continue; } $searchpluginoptions[$plugin->name] = $plugin->name; $config_path = get_config('docroot') . 'search/' . $plugin->name . '/version.php'; if (is_readable($config_path)) { $config = new stdClass(); require_once $config_path; if (isset($config->name)) { $searchpluginoptions[$plugin->name] = $config->name; } } } } return $searchpluginoptions; }
function build_portfolio_search_html(&$data) { global $THEME; $artefacttypes = get_records_assoc('artefact_installed_type'); require_once 'view.php'; require_once 'collection.php'; foreach ($data->data as &$item) { $item->ctime = format_date($item->ctime); if ($item->type == 'view') { $item->typestr = get_string('view'); $item->icon = $THEME->get_image_url('page'); $v = new View(0, (array) $item); $v->set('dirty', false); $item->url = $v->get_url(); } else { if ($item->type == 'collection') { $item->typestr = get_string('Collection', 'collection'); $item->icon = $THEME->get_image_url('collection'); $c = new Collection(0, (array) $item); $item->url = $c->get_url(); } else { // artefact safe_require('artefact', $artefacttypes[$item->artefacttype]->plugin); $links = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_links', $item->id); $item->url = $links['_default']; $item->icon = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_icon', array('id' => $item->id)); if ($item->artefacttype == 'task') { $item->typestr = get_string('Task', 'artefact.plans'); } else { $item->typestr = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin); } } } } $data->baseurl = get_config('wwwroot') . 'tags.php' . (is_null($data->tag) ? '' : '?tag=' . urlencode($data->tag)); $data->sortcols = array('name', 'date'); $data->filtercols = array('all' => get_string('tagfilter_all'), 'file' => get_string('tagfilter_file'), 'image' => get_string('tagfilter_image'), 'text' => get_string('tagfilter_text'), 'view' => get_string('tagfilter_view'), 'collection' => get_string('tagfilter_collection')); $smarty = smarty_core(); $smarty->assign_by_ref('data', $data->data); $smarty->assign('owner', $data->owner->id); $data->tablerows = $smarty->fetch('portfoliosearchresults.tpl'); $pagination = build_pagination(array('id' => 'results_pagination', 'class' => 'center', 'url' => $data->baseurl . ($data->sort == 'name' ? '' : '&sort=' . $data->sort) . ($data->filter == 'all' ? '' : '&type=' . $data->filter), 'jsonscript' => 'json/tagsearch.php', 'datatable' => 'results', 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('result'), 'resultcounttextplural' => get_string('results'))); $data->pagination = $pagination['html']; $data->pagination_js = $pagination['javascript']; }
function auth_generate_registration_form($formname, $authname = 'internal', $goto) { require_once get_config('libroot') . 'antispam.php'; $elements = array('firstname' => array('type' => 'text', 'title' => get_string('firstname'), 'rules' => array('required' => true)), 'lastname' => array('type' => 'text', 'title' => get_string('lastname'), 'rules' => array('required' => true)), 'email' => array('type' => 'text', 'title' => get_string('emailaddress'), 'rules' => array('required' => true, 'email' => true))); $sql = 'SELECT i.* FROM {institution} i, {auth_instance} ai WHERE ai.authname = ? AND ai.institution = i.name AND i.registerallowed = 1'; $institutions = get_records_sql_array($sql, array($authname)); $registerconfirm = array(); $reason = false; if (count($institutions) > 0) { $options = array(); foreach ($institutions as $institution) { $options[$institution->name] = $institution->displayname; if ($registerconfirm[$institution->name] = get_config('requireregistrationconfirm') || $institution->registerconfirm) { if ($authname != 'internal') { $authinstance = get_record('auth_instance', 'institution', $institution->name, 'authname', $authname); $auth = AuthFactory::create($authinstance->id); $registerconfirm[$institution->name] = !$auth->weautocreateusers; } if ($registerconfirm[$institution->name]) { $options[$institution->name] .= ' (' . get_string('approvalrequired') . ')'; $reason = true; } } } natcasesort($options); if (count($institutions) > 1) { array_unshift($options, get_string('chooseinstitution', 'mahara')); } $elements['institution'] = array('type' => 'select', 'title' => get_string('institution'), 'options' => $options, 'rules' => array('required' => true)); } else { return; } if ($reason) { $elements['reason'] = array('type' => 'textarea', 'title' => get_string('registrationreason', 'auth.internal'), 'description' => get_string('registrationreasondesc1', 'auth.internal'), 'class' => 'js-hidden', 'rows' => 4, 'cols' => 60); } $registerterms = get_config('registerterms'); if ($registerterms) { $elements['tandc'] = array('type' => 'radio', 'title' => get_string('iagreetothetermsandconditions', 'auth.internal'), 'options' => array('yes' => get_string('yes'), 'no' => get_string('no')), 'defaultvalue' => 'no', 'rules' => array('required' => true), 'separator' => ' '); } if (call_static_method('Auth' . ucfirst($authname), 'can_use_registration_captcha')) { $elements['captcha'] = array('type' => 'captcha'); } $elements['submit'] = array('type' => 'submit', 'value' => get_string('register')); $elements['goto'] = array('type' => 'hidden', 'value' => $goto); // swap the name and email fields at random if (rand(0, 1)) { $emailelement = $elements['email']; unset($elements['email']); $elements = array('email' => $emailelement) + $elements; } $form = array('name' => $formname, 'validatecallback' => 'auth_' . $formname . '_validate', 'successcallback' => 'auth_' . $formname . '_submit', 'method' => 'post', 'action' => '', 'showdescriptiononerror' => false, 'renderer' => 'table', 'elements' => $elements, 'spam' => array('secret' => get_config('formsecret'), 'mintime' => 5, 'hash' => array('firstname', 'lastname', 'email', 'institution', 'reason', 'tandc', 'submit'))); if ($authname == 'internal') { $form['plugintype'] = 'core'; $form['pluginname'] = 'register'; } return array($form, $registerconfirm); }
function pluginconfig_validate(PieForm $form, $values) { global $plugintype, $pluginname, $classname; if (is_callable($classname . '::validate_config_options')) { call_static_method($classname, 'validate_config_options', $form, $values); } }
$user = get_record('usr', 'id', $userid, 'deleted', 0); if (!$user) { throw new UserNotFoundException(get_string('usernotfound', 'group', $userid)); } $role = group_user_access($groupid); if ($role != 'admin' && !group_user_can_assess_submitted_views($group->id, $USER->get('id'))) { if (!$group->invitefriends || !is_friend($user->id, $USER->get('id'))) { throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group')); } } if (record_exists('group_member', 'group', $groupid, 'member', $userid) || record_exists('group_member_invite', 'group', $groupid, 'member', $userid)) { throw new UserException(get_string('useralreadyinvitedtogroup', 'group')); } define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name)); $roles = group_get_role_info($groupid); foreach ($roles as $k => &$v) { $v = $v->display; } safe_require('grouptype', $group->grouptype); $form = pieform(array('name' => 'invitetogroup', 'autofocus' => false, 'method' => 'post', 'elements' => array('reason' => array('type' => 'textarea', 'cols' => 50, 'rows' => 4, 'title' => get_string('reason')), 'role' => array('type' => 'select', 'options' => $roles, 'title' => get_string('Role', 'group'), 'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role'), 'ignore' => $role != 'admin'), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('invite', 'group'), get_string('cancel')), 'goto' => profile_url($user))))); $smarty = smarty(); $smarty->assign('subheading', TITLE); $smarty->assign('form', $form); $smarty->display('group/invite.tpl'); function invitetogroup_submit(Pieform $form, $values) { global $SESSION, $USER, $group, $user; group_invite_user($group, $user->id, $USER, isset($values['role']) ? $values['role'] : null); $SESSION->add_ok_msg(get_string('userinvited', 'group')); redirect(profile_url($user)); }
/** * creates the information for the interaction_sideblock * * @param int $groupid the group the sideblock is for * @param boolean (optional) $membership whether the user is a member * @return array containing indices 'name', 'weight', 'data' */ function interaction_sideblock($groupid, $membership = true) { $interactiontypes = array_flip(array_map(create_function('$a', 'return $a->name;'), plugins_installed('interaction'))); if (!($interactions = get_records_select_array('interaction_instance', '"group" = ? AND deleted = ?', array($groupid, 0), 'plugin, ctime', 'id, plugin, title'))) { $interactions = array(); } foreach ($interactions as $i) { if (!is_array($interactiontypes[$i->plugin])) { $interactiontypes[$i->plugin] = array(); } $interactiontypes[$i->plugin][] = $i; } // Sort them according to how the plugin wants them sorted if ($interactiontypes) { foreach ($interactiontypes as $plugin => &$interactions) { safe_require('interaction', $plugin); $classname = generate_class_name('interaction', $plugin); if (method_exists($classname, 'sideblock_sort')) { $interactions = call_static_method($classname, 'sideblock_sort', $interactions); } } } $data = array('group' => $groupid, 'interactiontypes' => $interactiontypes, 'membership' => $membership); // Add a sideblock for group interactions return array('name' => 'groupinteractions', 'weight' => -5, 'data' => $data); }