Пример #1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     global $CFG;
     $default = array('opname' => get_string('pluginname', 'auth.oidc'));
     $storedconfig = array('clientid' => '', 'clientsecret' => '', 'redirecturi' => trim($CFG->wwwroot, '/') . '/auth/oidc/redirect.php', 'resource' => '', 'authendpoint' => '', 'tokenendpoint' => '');
     foreach ($storedconfig as $key => $value) {
         $saved = get_config_plugin('auth', 'oidc', $key);
         if ($saved !== null) {
             $storedconfig[$key] = $saved;
         }
     }
     $this->config = (object) array_merge($default, $storedconfig);
 }
Пример #2
0
function groupquotasform_submit(Pieform $form, $values)
{
    global $SESSION;
    $oldquota = get_field('group', 'quota', 'id', $values['groupid']);
    $group = new StdClass();
    $group->id = $values['groupid'];
    $group->quota = $values['quota'];
    update_record('group', $group);
    if (!empty($values['quota']) && $values['quota'] != $oldquota) {
        // We need to alert group admins that the group may now be over the threshold
        $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
        $sqlwhere = " ((g.quotaused / g.quota) * 100) ";
        if (is_postgres()) {
            $sqlwhere = " ((CAST(g.quotaused AS float) / CAST(g.quota AS float)) * 100) ";
        }
        if ($groups = get_records_sql_assoc("SELECT g.id, g.name, g.quota, " . $sqlwhere . " AS quotausedpercent FROM {group} g WHERE " . $sqlwhere . " >= ? AND id = ?", array($quotanotifylimit, $values['groupid']))) {
            require_once get_config('docroot') . 'artefact/file/lib.php';
            ArtefactTypeFile::notify_groups_threshold_exceeded($groups);
        }
    }
    $SESSION->add_ok_msg(get_string('groupquotaupdated', 'admin'));
    redirect(get_config('wwwroot') . 'admin/groups/groups.php');
}
Пример #3
0
 private static function get_allowed_filetypes()
 {
     if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
         return unserialize($data);
     }
     return array();
 }
Пример #4
0
function pieform_element_filebrowser_upload(Pieform $form, $element, $data)
{
    global $USER;
    $parentfolder = $data['uploadfolder'] ? (int) $data['uploadfolder'] : null;
    $institution = !empty($element['institution']) ? $element['institution'] : $form->get_property('institution');
    $group = !empty($element['group']) ? $element['group'] : $form->get_property('group');
    if (get_config('licensemetadata')) {
        $license = $data['license'];
        $licensor = $data['licensor'];
        $licensorurl = $data['licensorurl'];
    }
    $uploadnumber = (int) $data['uploadnumber'];
    $editable = (int) $element['config']['edit'];
    $selectable = (int) $element['config']['select'];
    $querybase = $element['page'] . (strpos($element['page'], '?') === false ? '?' : '&');
    $prefix = $form->get_name() . '_' . $element['name'];
    $userfileindex = isset($data['userfileindex']) ? $data['userfileindex'] : null;
    $resizeonuploadenable = get_config_plugin('artefact', 'file', 'resizeonuploadenable');
    $resizeonuploaduseroption = get_config_plugin('artefact', 'file', 'resizeonuploaduseroption');
    $resizeonuploaduserenable = (int) $data['resizeonuploaduserenable'];
    $result = array('error' => false, 'uploadnumber' => $uploadnumber);
    if ($parentfolder == 0) {
        $parentfolder = null;
    }
    $data = new StdClass();
    $data->parent = $parentfolder;
    $data->owner = $data->group = $data->institution = null;
    if (get_config('licensemetadata')) {
        $data->license = $license;
        $data->licensor = $licensor;
        $data->licensorurl = $licensorurl;
    }
    if ($parentfolder) {
        $parentartefact = artefact_instance_from_id($parentfolder);
        if (!$USER->can_edit_artefact($parentartefact)) {
            $result['error'] = true;
            $result['message'] = get_string('cannoteditfolder', 'artefact.file');
            return $result;
        } else {
            if ($parentartefact->get('locked')) {
                $result['error'] = true;
                $result['message'] = get_string('cannoteditfoldersubmitted', 'artefact.file');
                return $result;
            }
        }
        $parentfoldername = $parentartefact->get('title');
    } else {
        $parentfoldername = null;
    }
    if ($institution) {
        if (!$USER->can_edit_institution($institution)) {
            $result['error'] = true;
            $result['message'] = get_string('notadminforinstitution', 'admin');
            return $result;
        }
        $data->institution = $institution;
    } else {
        if ($group) {
            if (!group_within_edit_window($group)) {
                return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
            }
            if (!$parentfolder) {
                if (!pieform_element_filebrowser_edit_group_folder($group, 0)) {
                    return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
                }
            }
            $data->group = $group;
        } else {
            $data->owner = $USER->get('id');
        }
    }
    $data->container = 0;
    if (isset($userfileindex)) {
        $originalname = $_FILES['userfile']['name'][$userfileindex];
    } else {
        $originalname = $_FILES['userfile']['name'];
    }
    $originalname = $originalname ? basename($originalname) : get_string('file', 'artefact.file');
    $data->title = ArtefactTypeFileBase::get_new_file_title($originalname, $parentfolder, $data->owner, $group, $institution);
    // Overwrite image file with resized version if required
    $resized = false;
    $resizeattempted = false;
    // resize specified if (resizing is enabled AND user has enabled resizing) OR (resizing is enabled AND user is not given an option to enable/disable)
    if ($resizeonuploadenable && $resizeonuploaduserenable || $resizeonuploadenable && !$resizeonuploaduseroption) {
        require_once 'file.php';
        require_once 'imageresizer.php';
        $file = $_FILES['userfile'];
        if (isset($userfileindex)) {
            $tmpname = $file['tmp_name'][$userfileindex];
        } else {
            $tmpname = $file['tmp_name'];
        }
        if (is_image_file($tmpname)) {
            $imageinfo = getimagesize($tmpname);
            $mimetype = $imageinfo['mime'];
            $width = $imageinfo[0];
            $height = $imageinfo[1];
            $bmptypes = array('image/bmp', 'image/x-bmp', 'image/ms-bmp', 'image/x-ms-bmp');
            // resize image if necessary
            $resizeonuploadmaxwidth = get_config_plugin('artefact', 'file', 'resizeonuploadmaxwidth');
            $resizeonuploadmaxheight = get_config_plugin('artefact', 'file', 'resizeonuploadmaxheight');
            // Don't support bmps for now
            if (($width > $resizeonuploadmaxwidth || $height > $resizeonuploadmaxheight) && !in_array($mimetype, $bmptypes)) {
                $resizeattempted = true;
                $imgrs = new ImageResizer($tmpname, $mimetype);
                $img = $imgrs->get_image();
                if (!empty($img)) {
                    $imgrs->resize_image(array('w' => $resizeonuploadmaxwidth, 'h' => $resizeonuploadmaxheight), $mimetype);
                    //auto
                    $saveresize = $imgrs->save_image($tmpname, $mimetype, 85);
                    if (!$saveresize) {
                        return array('error' => true, 'message' => get_string('problemresizing', 'artefact.file'));
                    }
                    $resized = true;
                }
            }
        }
    }
    try {
        $newid = ArtefactTypeFile::save_uploaded_file('userfile', $data, $userfileindex, $resized);
    } catch (QuotaExceededException $e) {
        prepare_upload_failed_message($result, $e, $parentfoldername, $originalname);
        // update the file listing
        if (defined('GROUP')) {
            $group = group_current_group();
            $result['quota'] = $group->quota;
            $result['quotaused'] = $group->quotaused;
        } else {
            $result['quota'] = $USER->get('quota');
            $result['quotaused'] = $USER->get('quotaused');
        }
        $result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, null, $data->owner, $data->group, $data->institution);
        return $result;
    } catch (UploadException $e) {
        prepare_upload_failed_message($result, $e, $parentfoldername, $originalname);
        if (defined('GROUP')) {
            $group = group_current_group();
            $result['quota'] = $group->quota;
            $result['quotaused'] = $group->quotaused;
        }
        return $result;
    }
    // Upload succeeded
    if (isset($element['filters'])) {
        $artefacttypes = isset($element['filters']['artefacttype']) ? $element['filters']['artefacttype'] : null;
        $filetypes = isset($element['filters']['filetype']) ? $element['filters']['filetype'] : null;
        if (!empty($artefacttypes) || !empty($filetypes)) {
            // Need to check the artefacttype or filetype (mimetype) of the uploaded file.
            $file = artefact_instance_from_id($newid);
            if (is_array($artefacttypes) && !in_array($file->get('artefacttype'), $artefacttypes) || is_array($filetypes) && !in_array($file->get('filetype'), $filetypes)) {
                $result['error'] = true;
                $result['uploaded'] = true;
                $result['message'] = get_string('wrongfiletypeforblock', 'artefact.file');
                return $result;
            }
        }
    }
    if ($parentfoldername) {
        if ($data->title == $originalname) {
            $result['message'] = get_string('uploadoffiletofoldercomplete', 'artefact.file', $originalname, $parentfoldername);
        } else {
            $result['message'] = get_string('fileuploadedtofolderas', 'artefact.file', $originalname, $parentfoldername, $data->title);
        }
    } else {
        if ($data->title == $originalname) {
            $result['message'] = get_string('uploadoffilecomplete', 'artefact.file', $originalname);
        } else {
            $result['message'] = get_string('fileuploadedas', 'artefact.file', $originalname, $data->title);
        }
    }
    if ($resizeattempted && !$resized) {
        $result['message'] .= get_string('insufficientmemoryforresize', 'artefact.file');
    }
    $result['highlight'] = $newid;
    $artefact = artefact_instance_from_id($newid);
    $result['artefacttype'] = $artefact->get('artefacttype');
    $result['uploaded'] = true;
    $result['newlist'] = pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $newid, $data->owner, $data->group, $data->institution);
    if (defined('GROUP')) {
        $group = group_current_group(false);
        $result['quota'] = $group->quota;
        $result['quotaused'] = $group->quotaused;
    } else {
        $result['quota'] = $USER->get('quota');
        $result['quotaused'] = $USER->get('quotaused');
    }
    $result['maxuploadsize'] = display_size(get_max_upload_size(!$institution && !$group));
    return $result;
}
Пример #5
0
if ($blogobj->get('institution')) {
    $institution = true;
    $institutionname = $blogobj->get('institution');
} else {
    if ($blogobj->get('group')) {
        $groupid = $blogobj->get('group');
    }
}
PluginArtefactBlog::set_blog_nav($institution, $institutionname, $groupid);
$folder = param_integer('folder', 0);
$browse = (int) param_variable('browse', 0);
$highlight = null;
if ($file = param_integer('file', 0)) {
    $highlight = array($file);
}
$form = pieform(array('name' => 'editpost', 'method' => 'post', 'autofocus' => $focuselement, 'jsform' => true, 'newiframeonsubmit' => true, 'jssuccesscallback' => 'editpost_callback', 'jserrorcallback' => 'editpost_callback', 'plugintype' => 'artefact', 'pluginname' => 'blog', 'configdirs' => array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/file/form/'), 'elements' => array('blog' => array('type' => 'hidden', 'value' => $blog), 'blogpost' => array('type' => 'hidden', 'value' => $blogpost), 'title' => array('type' => 'text', 'title' => get_string('posttitle', 'artefact.blog'), 'rules' => array('required' => true), 'defaultvalue' => $title), 'description' => array('type' => 'wysiwyg', 'rows' => 20, 'cols' => 70, 'title' => get_string('postbody', 'artefact.blog'), 'description' => get_string('postbodydesc', 'artefact.blog'), 'rules' => array('maxlength' => 65536, 'required' => true), 'defaultvalue' => $description), 'tags' => array('defaultvalue' => $tags, 'type' => 'tags', 'title' => get_string('tags'), 'description' => get_string('tagsdesc'), 'help' => true), 'license' => license_form_el_basic(isset($blogpostobj) ? $blogpostobj : null), 'licensing_advanced' => license_form_el_advanced(isset($blogpostobj) ? $blogpostobj : null), 'filebrowser' => array('type' => 'filebrowser', 'title' => get_string('attachments', 'artefact.blog'), 'folder' => $folder, 'highlight' => $highlight, 'institution' => $institutionname, 'group' => $groupid, 'browse' => $browse, 'page' => get_config('wwwroot') . 'artefact/blog/post.php?' . ($blogpost ? 'id=' . $blogpost : 'blog=' . $blog) . '&browse=1', 'browsehelp' => 'browsemyfiles', 'config' => array('upload' => true, 'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'), 'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'), 'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'), 'createfolder' => false, 'edit' => false, 'select' => true), 'defaultvalue' => $attachments, 'selectlistcallback' => 'artefact_get_records_by_id', 'selectcallback' => 'add_attachment', 'unselectcallback' => 'delete_attachment'), 'draft' => array('type' => 'switchbox', 'title' => get_string('draft', 'artefact.blog'), 'description' => get_string('thisisdraftdesc', 'artefact.blog'), 'defaultvalue' => $checked, 'help' => true), 'allowcomments' => array('type' => 'switchbox', 'title' => get_string('allowcomments', 'artefact.comment'), 'description' => get_string('allowcommentsonpost', 'artefact.blog'), 'defaultvalue' => $blogpost ? $blogpostobj->get('allowcomments') : 1), 'submitpost' => array('type' => 'submitcancel', 'class' => 'btn-primary', 'value' => array(get_string('savepost', 'artefact.blog'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog))));
/*
 * Javascript specific to this page.  Creates the list of files
 * attached to the blog post.
 */
$wwwroot = get_config('wwwroot');
$noimagesmessage = json_encode(get_string('noimageshavebeenattachedtothispost', 'artefact.blog'));
$javascript = <<<EOF
function editpost_callback(form, data) {
    editpost_filebrowser.callback(form, data);
};
EOF;
$smarty = smarty(array(), array(), array(), array('tinymceconfig' => '
        image_filebrowser: "editpost_filebrowser",
    ', 'sideblocks' => array(array('name' => 'quota', 'weight' => -10, 'data' => array()))));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
Пример #6
0
function adduser_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $TRANSPORTER;
    db_begin();
    raise_time_limit(180);
    // Create user
    $user = (object) array('authinstance' => $values['authinstance'], 'username' => $values['username'], 'firstname' => $values['firstname'] ? $values['firstname'] : 'Imported', 'lastname' => $values['lastname'] ? $values['lastname'] : 'User', 'email' => $values['email'], 'password' => $values['password'], 'passwordchange' => 1);
    if ($USER->get('admin')) {
        // Not editable by institutional admins
        $user->staff = (int) ($values['staff'] == 'on');
        $user->admin = (int) ($values['admin'] == 'on');
    }
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $user->quota = $values['quota'];
    }
    $authinstance = get_record('auth_instance', 'id', $values['authinstance']);
    $remoteauth = false;
    if ($authinstance->authname != 'internal') {
        $remoteauth = true;
    }
    if (!isset($values['remoteusername'])) {
        $values['remoteusername'] = null;
    }
    $user->id = create_user($user, array(), $authinstance->institution, $remoteauth, $values['remoteusername'], $values);
    if (isset($user->admin) && $user->admin) {
        require_once 'activity.php';
        activity_add_admin_defaults(array($user->id));
    }
    if ($values['institutionadmin']) {
        set_field('usr_institution', 'admin', 1, 'usr', $user->id, 'institution', $authinstance->institution);
    }
    if (isset($values['leap2afile'])) {
        // And we're good to go
        $importdata = (object) array('token' => '', 'usr' => $user->id, 'queue' => (int) (!PluginImport::import_immediately_allowed()), 'ready' => 0, 'expirytime' => db_format_timestamp(time() + 60 * 60 * 24), 'format' => 'leap', 'loglevel' => PluginImportLeap::LOG_LEVEL_VERBOSE, 'logtargets' => LOG_TARGET_FILE, 'profile' => true);
        $importer = PluginImport::create_importer(null, $TRANSPORTER, $importdata);
        try {
            $importer->process();
            log_info("Imported user account {$user->id} from Leap2A file, see " . $importer->get('logfile') . ' for a full log');
        } catch (ImportException $e) {
            log_info("Leap2A import failed: " . $e->getMessage());
            die_info(get_string('leap2aimportfailed', 'admin'));
        }
        // Reload the user details, as various fields are changed by the
        // importer when importing (e.g. firstname/lastname)
        $user = get_record('usr', 'id', $user->id);
    }
    db_commit();
    if (!empty($user->email)) {
        try {
            email_user($user, $USER, get_string('accountcreated', 'mahara', get_config('sitename')), get_string('accountcreatedchangepasswordtext', 'mahara', $user->firstname, get_config('sitename'), $user->username, $values['password'], get_config('wwwroot'), get_config('sitename')), get_string('accountcreatedchangepasswordhtml', 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $values['password'], get_config('wwwroot'), get_config('wwwroot'), get_config('sitename')));
        } catch (EmailException $e) {
            $SESSION->add_error_msg(get_string('newuseremailnotsent', 'admin'));
        }
    }
    $SESSION->add_ok_msg(get_string('newusercreated', 'admin'));
    redirect('/admin/users/edit.php?id=' . $user->id);
}
Пример #7
0
 *
 * @package    mahara
 * @subpackage core
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
define('INSTITUTIONALADMIN', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once 'pieforms/pieform/elements/bytes.php';
$instid = param_integer('instid');
$disabled = param_boolean('disabled', false);
$definst = get_field('auth_instance', 'id', 'institution', 'mahara');
$record = get_record_sql('SELECT i.name, i.defaultquota FROM {institution} i JOIN {auth_instance} ai ON (i.name = ai.institution) WHERE ai.id = ?', array($instid));
if (!$USER->get('admin') && !$USER->is_institutional_admin($record->name)) {
    json_reply(true, 'You are not an administrator for institution ' . $record->name);
    return;
}
if ($definst && $instid == $definst) {
    $quota = get_config_plugin('artefact', 'file', 'defaultquota');
} else {
    $quota = $record->defaultquota;
    if (!$quota) {
        $quota = get_config_plugin('artefact', 'file', 'defaultquota');
    }
}
$data = array('data' => $disabled ? display_size($quota) : pieform_element_bytes_get_bytes_from_bytes($quota), 'error' => false, 'message' => null);
json_reply(false, $data);
Пример #8
0
function edituser_site_submit(Pieform $form, $values)
{
    global $USER, $authobj, $SESSION;
    if (!($user = get_record('usr', 'id', $values['id']))) {
        return false;
    }
    if (is_using_probation()) {
        // Value should be between 0 and 10 inclusive
        $user->probation = ensure_valid_probation_points($values['probationpoints']);
    }
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $user->quota = $values['quota'];
        // check if the user has gone over the quota notify limit
        $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
        if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
            $quotanotifylimit = 100;
        }
        $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);
            }
        }
    }
    $unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time());
    $newexpiry = db_format_timestamp($values['expiry']);
    if ($user->expiry != $newexpiry) {
        $user->expiry = $newexpiry;
        if ($unexpire) {
            $user->expirymailsent = 0;
            $user->lastaccess = db_format_timestamp(time());
        }
    }
    // Try to kick the user from any active login sessions, before saving data.
    require_once get_config('docroot') . 'auth/session.php';
    remove_user_sessions($user->id);
    if ($USER->get('admin')) {
        // Not editable by institutional admins
        $user->staff = (int) ($values['staff'] == 'on');
        $user->admin = (int) ($values['admin'] == 'on');
        if ($user->admin) {
            activity_add_admin_defaults(array($user->id));
        }
    }
    if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) {
        // Reset the sent and bounce counts otherwise mail will be disabled
        // on the next send attempt
        $u = new StdClass();
        $u->email = $user->email;
        $u->id = $user->id;
        update_bounce_count($u, true);
        update_send_count($u, true);
    }
    set_account_preference($user->id, 'maildisabled', $values['maildisabled']);
    // process the change of the authinstance and or the remoteuser
    if (isset($values['authinstance']) && isset($values['remoteusername'])) {
        // Authinstance can be changed by institutional admins if both the
        // old and new authinstances belong to the admin's institutions
        $authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance));
        // But don't bother if the auth instance doesn't take a remote username
        $authobj = AuthFactory::create($values['authinstance']);
        if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && ($USER->is_institutional_admin($authinst[$user->authinstance]->institution) || $user->authinstance == 1)) {
            if ($authobj->needs_remote_username()) {
                // determine the current remoteuser
                $current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
                if (!$current_remotename) {
                    $current_remotename = $user->username;
                }
                // if the remoteuser is empty
                if (strlen(trim($values['remoteusername'])) == 0) {
                    delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'localusr', $user->id);
                }
                // what should the new remoteuser be
                $new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                // save the remotename for the target existence check
                $target_remotename = $new_remoteuser;
                if (!$new_remoteuser) {
                    $new_remoteuser = $user->username;
                }
                if (strlen(trim($values['remoteusername'])) > 0) {
                    // value changed on page - use it
                    if ($values['remoteusername'] != $current_remotename) {
                        $new_remoteuser = $values['remoteusername'];
                    }
                }
                // only update remote name if the input actually changed on the page  or it doesn't yet exist
                if ($current_remotename != $new_remoteuser || !$target_remotename) {
                    // only remove the ones related to this traget authinstance as we now allow multiple
                    // for dual login mechanisms
                    delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                    insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $new_remoteuser, 'localusr' => $user->id));
                }
            }
            // update the ai on the user master
            $user->authinstance = $values['authinstance'];
            // update the global $authobj to match the new authinstance
            // this is used by the password/username change methods
            // if either/both has been requested at the same time
            $authobj = AuthFactory::create($user->authinstance);
        }
    }
    // Only change the pw if the new auth instance allows for it
    if (method_exists($authobj, 'change_password')) {
        $user->passwordchange = (int) (isset($values['passwordchange']) && $values['passwordchange'] == 'on' ? 1 : 0);
        if (isset($values['password']) && $values['password'] !== '') {
            $userobj = new User();
            $userobj = $userobj->find_by_id($user->id);
            $user->password = $authobj->change_password($userobj, $values['password']);
            $user->salt = $userobj->salt;
            unset($userobj);
        }
    } else {
        // inform the user that the chosen auth instance doesn't allow password changes
        // but only if they tried changing it
        if (isset($values['password']) && $values['password'] !== '') {
            $SESSION->add_error_msg(get_string('passwordchangenotallowed', 'admin'));
            // Set empty pw with salt
            $user->password = '';
            $user->salt = auth_get_random_salt();
        }
    }
    if (isset($values['username']) && $values['username'] !== '') {
        $userobj = new User();
        $userobj = $userobj->find_by_id($user->id);
        if ($userobj->username != $values['username']) {
            // Only change the username if the auth instance allows for it
            if (method_exists($authobj, 'change_username')) {
                // check the existence of the chosen username
                try {
                    if ($authobj->user_exists($values['username'])) {
                        // set an error message if it is already in use
                        $SESSION->add_error_msg(get_string('usernameexists', 'account'));
                    }
                } catch (AuthUnknownUserException $e) {
                    // update the username otherwise
                    $user->username = $authobj->change_username($userobj, $values['username']);
                }
            } else {
                // inform the user that the chosen auth instance doesn't allow username changes
                $SESSION->add_error_msg(get_string('usernamechangenotallowed', 'admin'));
            }
        }
        unset($userobj);
    }
    // OVERWRITE 4: insert
    if (isset($values['email']) && !empty($values['email']) && $values['email'] != $user->email) {
        global $CFG;
        $user->email = $values['email'];
        $mhr_user = $CFG->current_app->getUserById($user->id);
        $mhr_user->setEmailAddress($values['email']);
    }
    // END OVERWRITE 4
    db_begin();
    update_record('usr', $user);
    delete_records('usr_tag', 'usr', $user->id);
    if (is_array($values['tags'])) {
        $values['tags'] = check_case_sensitive($values['tags'], 'usr_tag');
        foreach (array_unique($values['tags']) as $tag) {
            if (empty($tag)) {
                continue;
            }
            insert_record('usr_tag', (object) array('usr' => $user->id, 'tag' => strtolower($tag)));
        }
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('usersitesettingschanged', 'admin'));
    redirect('/admin/users/edit.php?id=' . $user->id);
}
Пример #9
0
 public static function build_html(&$data, $onview)
 {
     global $USER, $THEME;
     $candelete = $data->canedit || $USER->get('admin');
     $deletedmessage = array();
     foreach (ArtefactTypeAnnotationfeedback::deleted_by_types_description() as $k => $v) {
         $deletedmessage[$k] = get_string($v, 'artefact.annotation');
     }
     $authors = array();
     $lastcomment = self::last_public_annotation_feedback($data->annotation, $data->view, $data->artefact);
     $editableafter = time() - 60 * get_config_plugin('artefact', 'annotation', 'commenteditabletime');
     foreach ($data->data as &$item) {
         $isadminfeedback = $item->admin == 1 || $item->staff == 1 || $item->feedbackinstitutionadmin == 1 || $item->feedbackinstitutionstaff == 1;
         $item->ts = strtotime($item->ctime);
         $item->date = format_date($item->ts, 'strftimedatetime');
         if ($item->ts < strtotime($item->lastcontentupdate)) {
             $item->updated = format_date(strtotime($item->lastcontentupdate), 'strftimedatetime');
         }
         $item->isauthor = $item->author && $item->author == $USER->get('id');
         if ($item->private) {
             $item->pubmessage = get_string('annotationfeedbackisprivate', 'artefact.annotation');
         }
         if (isset($data->showcomment) && $data->showcomment == $item->id) {
             $item->highlight = 1;
         }
         $is_export_preview = param_integer('export', 0);
         if ($item->deletedby) {
             $item->deletedmessage = $deletedmessage[$item->deletedby];
         } else {
             if (($candelete || $item->isauthor) && !$is_export_preview && !$isadminfeedback) {
                 // If the auther was admin/staff and not the owner of the annotation,
                 // the feedback can't be deleted.
                 $item->deleteform = pieform(self::delete_annotation_feedback_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
             }
         }
         // Comment authors can edit recent comments if they're private or if no one has replied yet.
         if (!$item->deletedby && $item->isauthor && !$is_export_preview && ($item->private || $item->id == $lastcomment->id) && $item->ts > $editableafter) {
             $item->canedit = 1;
         }
         // Form to make private comment public, or request that a
         // private comment be made public.
         if (!$item->deletedby && $item->private && $item->author && $data->owner && ($item->isauthor || $data->isowner)) {
             if (empty($item->requestpublic) && $data->isowner || $item->isauthor && $item->requestpublic == 'owner' || $data->isowner && $item->requestpublic == 'author') {
                 if (!$is_export_preview) {
                     $item->makepublicform = pieform(self::make_annotation_feedback_public_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
                 }
             } else {
                 if ($item->isauthor && $item->requestpublic == 'author' || $data->isowner && $item->requestpublic == 'owner') {
                     $item->makepublicrequested = 1;
                 }
             }
         } else {
             if (!$item->deletedby && $item->private && !$item->author && $data->owner && $data->isowner && $item->requestpublic == 'author' && !$is_export_preview) {
                 $item->makepublicform = pieform(self::make_annotation_feedback_public_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
             } else {
                 if (!$item->deletedby && $item->private && !$data->owner && $item->group && $item->requestpublic == 'author') {
                     // no owner as comment is on a group view / artefact
                     if ($item->isauthor) {
                         $item->makepublicrequested = 1;
                     } else {
                         if ($data->artefact && $data->canedit || $data->view && $data->canedit && !$is_export_preview) {
                             $item->makepublicform = pieform(self::make_annotation_feedback_public_form($data->annotation, $data->view, $data->artefact, $data->block, $item->id));
                         } else {
                             $item->makepublicrequested = 1;
                         }
                     }
                 }
             }
         }
         if ($item->author) {
             if (isset($authors[$item->author])) {
                 $item->author = $authors[$item->author];
             } else {
                 $item->author = $authors[$item->author] = (object) array('id' => $item->author, 'username' => $item->username, 'firstname' => $item->firstname, 'lastname' => $item->lastname, 'preferredname' => $item->preferredname, 'email' => $item->email, 'staff' => $item->staff, 'admin' => $item->admin, 'deleted' => $item->deleted, 'profileicon' => $item->profileicon, 'profileurl' => profile_url($item->author));
             }
         }
     }
     $extradata = array('annotation' => $data->annotation, 'view' => $data->view, 'artefact' => !empty($data->artefact) ? $data->artefact : '', 'blockid' => $data->block);
     $data->jsonscript = 'artefact/annotation/annotations.json.php';
     $data->baseurl = get_config('wwwroot') . 'artefact/artefact.php?' . 'artefact=' . $data->annotation . '&view=' . $data->view . (isset($data->block) ? '&block=' . $data->block : '');
     $smarty = smarty_core();
     $smarty->assign_by_ref('data', $data->data);
     $smarty->assign('canedit', $data->canedit);
     $smarty->assign('viewid', $data->view);
     $smarty->assign('position', $data->position);
     $smarty->assign('baseurl', $data->baseurl);
     $data->tablerows = $smarty->fetch('artefact:annotation:annotationlist.tpl');
     $pagination = build_pagination(array('id' => 'annotationfeedback_pagination_' . $data->block, 'class' => 'center', 'url' => $data->baseurl, 'jsonscript' => $data->jsonscript, 'datatable' => 'annotationfeedbacktable_' . $data->block, 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'forceoffset' => isset($data->forceoffset) ? $data->forceoffset : null, 'resultcounttextsingular' => get_string('annotation', 'artefact.annotation'), 'resultcounttextplural' => get_string('annotations', 'artefact.annotation'), 'extradata' => $extradata));
     $data->pagination = $pagination['html'];
     $data->pagination_js = $pagination['javascript'];
 }
Пример #10
0
require dirname(dirname(dirname(__FILE__))) . '/init.php';
define('TITLE', get_string('editannotationfeedback', 'artefact.annotation'));
safe_require('artefact', 'annotation');
$annotationfeedbackid = param_integer('id');
$viewid = param_integer('viewid');
$annotationfeedback = new ArtefactTypeAnnotationFeedback((int) $annotationfeedbackid);
if ($USER->get('id') != $annotationfeedback->get('author')) {
    throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.annotation'));
}
$annotationid = $annotationfeedback->get('onannotation');
$annotation = new ArtefactTypeAnnotation($annotationid);
$onview = $annotation->get('view');
if ($onview && $onview != $viewid) {
    throw new NotFoundException(get_string('annotationfeedbacknotinview', 'artefact.annotation', $annotationfeedbackid, $viewid));
}
$maxage = (int) get_config_plugin('artefact', 'annotation', 'commenteditabletime');
$editableafter = time() - 60 * $maxage;
$goto = $annotation->get_view_url($viewid, false);
if ($annotationfeedback->get('ctime') < $editableafter) {
    $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.annotation', $maxage));
    redirect($goto);
}
$lastcomment = ArtefactTypeAnnotationfeedback::last_public_annotation_feedback($annotationid, $viewid, $annotation->get('artefact'));
if (!$annotationfeedback->get('private') && $annotationfeedbackid != $lastcomment->id) {
    $SESSION->add_error_msg(get_string('cantedithasreplies', 'artefact.annotation'));
    redirect($goto);
}
$elements = array();
$elements['message'] = array('type' => 'wysiwyg', 'title' => get_string('Annotationfeedback', 'artefact.annotation'), 'rows' => 5, 'cols' => 80, 'defaultvalue' => $annotationfeedback->get('description'), 'rules' => array('maxlength' => 8192));
$elements['ispublic'] = array('type' => 'checkbox', 'title' => get_string('makepublic', 'artefact.annotation'), 'defaultvalue' => !$annotationfeedback->get('private'));
// What is this annotation feedback linked to? Store it in hidden fields.
Пример #11
0
/**
 * Creates a group.
 *
 * All group creation should be done through this function, as the
 * implementation of group creation may change over time.
 *
 * @param array $data Data required to create the group. The following
 * key/value pairs can be specified:
 *
 * - name: The group name [required, must be unique]
 * - description: The group description [optional, defaults to empty string]
 * - grouptype: The grouptype for the new group. Must be an installed grouptype.
 * - open (jointype): anyone can join the group
 * - controlled (jointype): admin adds members; members cannot leave the group
 * - request: allows membership requests
 * - ctime: The unix timestamp of the time the group will be recorded as having
 *          been created. Defaults to the current time.
 * - members: Array of users who should be in the group, structured like this:
 *            array(
 *                userid => role,
 *                userid => role,
 *                ...
 *            )
 * @return int The ID of the created group
 */
function group_create($data)
{
    if (!is_array($data)) {
        throw new InvalidArgumentException("group_create: data must be an array, see the doc comment for this " . "function for details on its format");
    }
    if (!isset($data['name'])) {
        throw new InvalidArgumentException("group_create: must specify a name for the group");
    }
    if (get_records_sql_array('SELECT id FROM {group} WHERE LOWER(TRIM(name)) = ?', array(strtolower(trim($data['name']))))) {
        throw new UserException(get_string('groupalreadyexists', 'group') . ': ' . $data['name']);
    }
    if (!isset($data['grouptype']) || !in_array($data['grouptype'], group_get_grouptypes())) {
        throw new InvalidArgumentException("group_create: grouptype specified must be an installed grouptype");
    }
    safe_require('grouptype', $data['grouptype']);
    if (!empty($data['open'])) {
        if (!empty($data['controlled'])) {
            throw new InvalidArgumentException("group_create: a group cannot have both open and controlled membership");
        }
        if (!empty($data['request'])) {
            throw new InvalidArgumentException("group_create: open-membership groups don't accept membership requests");
        }
        $jointype = 'open';
    } else {
        if (!empty($data['controlled'])) {
            $jointype = 'controlled';
        } else {
            $jointype = 'approve';
        }
    }
    if (isset($data['jointype'])) {
        log_warn("group_create: ignoring supplied jointype");
    }
    if (!isset($data['ctime'])) {
        $data['ctime'] = time();
    }
    $data['ctime'] = db_format_timestamp($data['ctime']);
    $data['public'] = isset($data['public']) ? intval($data['public']) : 0;
    $data['hidden'] = isset($data['hidden']) ? intval($data['hidden']) : 0;
    $data['hidemembers'] = isset($data['hidemembers']) ? intval($data['hidemembers']) : 0;
    $data['hidemembersfrommembers'] = isset($data['hidemembersfrommembers']) ? intval($data['hidemembersfrommembers']) : 0;
    $data['groupparticipationreports'] = isset($data['groupparticipationreports']) ? intval($data['groupparticipationreports']) : 0;
    $data['usersautoadded'] = isset($data['usersautoadded']) ? intval($data['usersautoadded']) : 0;
    $data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
    if (!empty($data['invitefriends']) && !empty($data['suggestfriends'])) {
        throw new InvalidArgumentException("group_create: a group cannot enable both invitefriends and suggestfriends");
    }
    $data['invitefriends'] = isset($data['invitefriends']) ? intval($data['invitefriends']) : 0;
    $data['suggestfriends'] = isset($data['suggestfriends']) ? intval($data['suggestfriends']) : 0;
    if (isset($data['shortname']) && strlen($data['shortname'])) {
        // This is a group whose details and membership can be updated automatically, using a
        // webservice api or possibly csv upload.
        // On updates to this group, it will be identified using the institution and shortname
        // which must be unique.
        // The $USER object will be set to someone with at least institutional admin permission.
        global $USER;
        if (empty($data['institution'])) {
            throw new SystemException("group_create: a group with a shortname must have an institution; shortname: " . $data['shortname']);
        }
        if (!$USER->can_edit_institution($data['institution'])) {
            throw new AccessDeniedException("group_create: cannot create a group in this institution");
        }
        if (!preg_match('/^[a-zA-Z0-9_.-]{2,255}$/', $data['shortname'])) {
            $message = get_string('invalidshortname', 'group') . ': ' . $data['shortname'];
            $message .= "\n" . get_string('shortnameformat', 'group');
            throw new UserException($message);
        }
        if (record_exists('group', 'shortname', $data['shortname'], 'institution', $data['institution'])) {
            throw new UserException('group_create: group with shortname ' . $data['shortname'] . ' and institution ' . $data['institution'] . ' already exists');
        }
        if (empty($data['members'])) {
            $data['members'] = array($USER->get('id') => 'admin');
        }
    } else {
        if (!empty($data['institution'])) {
            throw new SystemException("group_create: group institution only available for api-controlled groups");
        }
        $data['shortname'] = null;
    }
    if (get_config('cleanurls') && (!isset($data['urlid']) || strlen($data['urlid']) == 0)) {
        $data['urlid'] = generate_urlid($data['name'], get_config('cleanurlgroupdefault'), 3, 30);
        $data['urlid'] = group_get_new_homepage_urlid($data['urlid']);
    }
    if (!is_array($data['members']) || count($data['members']) == 0) {
        throw new InvalidArgumentException("group_create: at least one member must be specified for adding to the group");
    }
    if (!isset($data['submittableto'])) {
        $data['submittableto'] = $data['grouptype'] != 'standard';
    }
    if (!isset($data['editroles'])) {
        $data['editroles'] = $data['grouptype'] == 'standard' ? 'all' : 'notmember';
    } else {
        if (!in_array($data['editroles'], array_keys(group_get_editroles_options()))) {
            throw new InvalidArgumentException("group_create: invalid option for page editroles setting");
        }
    }
    if (!isset($data['editwindowstart'])) {
        $data['editwindowstart'] = null;
    }
    if (!isset($data['editwindowend'])) {
        $data['editwindowend'] = null;
    }
    if (!isset($data['sendnow'])) {
        $data['sendnow'] = null;
    }
    db_begin();
    $id = insert_record('group', (object) array('name' => $data['name'], 'description' => isset($data['description']) ? $data['description'] : null, 'urlid' => isset($data['urlid']) ? $data['urlid'] : null, 'grouptype' => $data['grouptype'], 'category' => isset($data['category']) ? intval($data['category']) : null, 'jointype' => $jointype, 'ctime' => $data['ctime'], 'mtime' => $data['ctime'], 'public' => $data['public'], 'usersautoadded' => $data['usersautoadded'], 'quota' => $data['quota'], 'institution' => !empty($data['institution']) ? $data['institution'] : null, 'shortname' => $data['shortname'], 'request' => isset($data['request']) ? intval($data['request']) : 0, 'submittableto' => intval($data['submittableto']), 'allowarchives' => !empty($data['submittableto']) && !empty($data['allowarchives']) ? intval($data['allowarchives']) : 0, 'editroles' => $data['editroles'], 'hidden' => $data['hidden'], 'hidemembers' => $data['hidemembers'], 'hidemembersfrommembers' => $data['hidemembersfrommembers'], 'groupparticipationreports' => $data['groupparticipationreports'], 'invitefriends' => $data['invitefriends'], 'suggestfriends' => $data['suggestfriends'], 'editwindowstart' => $data['editwindowstart'], 'editwindowend' => $data['editwindowend'], 'sendnow' => isset($data['sendnow']) ? $data['sendnow'] : null, 'viewnotify' => isset($data['viewnotify']) ? $data['viewnotify'] : null, 'feedbacknotify' => isset($data['feedbacknotify']) ? $data['feedbacknotify'] : null), 'id', true);
    foreach ($data['members'] as $userid => $role) {
        insert_record('group_member', (object) array('group' => $id, 'member' => $userid, 'role' => $role, 'ctime' => $data['ctime']));
    }
    // Copy views for the new group
    $templates = get_column('view_autocreate_grouptype', 'view', 'grouptype', $data['grouptype']);
    $templates = get_records_sql_array("\n        SELECT v.id, v.title, v.description\n        FROM {view} v\n        INNER JOIN {view_autocreate_grouptype} vag ON vag.view = v.id\n        LEFT JOIN {collection_view} cv ON v.id = cv.view\n        WHERE vag.grouptype = 'standard'\n            AND cv.view IS NULL", array());
    if ($templates) {
        require_once get_config('libroot') . 'view.php';
        foreach ($templates as $template) {
            list($view) = View::create_from_template(array('group' => $id, 'title' => $template->title, 'description' => $template->description), $template->id, null, false);
            $view->set_access(array(array('type' => 'group', 'id' => $id, 'startdate' => null, 'stopdate' => null, 'role' => null)));
        }
    }
    // Copy collections for the new group
    $templates = get_records_sql_array("\n        SELECT DISTINCT c.id, c.name\n        FROM {view} v\n        INNER JOIN {view_autocreate_grouptype} vag ON vag.view = v.id\n        INNER JOIN {collection_view} cv ON v.id = cv.view\n        INNER JOIN {collection} c ON cv.collection = c.id\n        WHERE vag.grouptype = ?", array($data['grouptype']));
    if ($templates) {
        require_once 'collection.php';
        foreach ($templates as $template) {
            Collection::create_from_template(array('group' => $id), $template->id, null, false, true);
        }
    }
    $data['id'] = $id;
    // install the homepage
    if ($t = get_record('view', 'type', 'grouphomepage', 'template', 1, 'owner', 0)) {
        require_once 'view.php';
        $template = new View($t->id, (array) $t);
        list($homepage) = View::create_from_template(array('group' => $id, 'title' => $template->get('title'), 'description' => $template->get('description'), 'type' => 'grouphomepage'), $t->id, 0, false);
    }
    insert_record('view_access', (object) array('view' => $homepage->get('id'), 'accesstype' => $data['public'] ? 'public' : 'loggedin', 'ctime' => db_format_timestamp(time())));
    handle_event('creategroup', $data);
    db_commit();
    return $id;
}
Пример #12
0
/**
 * Create user
 *
 * @param object $user stdclass or User object for the usr table
 * @param array  $profile profile field/values to set
 * @param string|object $institution Institution the user should joined to (name or Institution object)
 * @param bool $remoteauth authinstance record for a remote authinstance
 * @param string $remotename username on the remote site
 * @param array $accountprefs user account preferences to set
 * @return integer id of the new user
 */
function create_user($user, $profile = array(), $institution = null, $remoteauth = null, $remotename = null, $accountprefs = array(), $quickhash = false)
{
    db_begin();
    if ($user instanceof User) {
        $user->create();
        $user->quota_init();
        $user->commit();
        $user = $user->to_stdclass();
    } else {
        $user->ctime = db_format_timestamp(time());
        // Ensure this user has a profile urlid
        if (get_config('cleanurls') && (!isset($user->urlid) || is_null($user->urlid))) {
            $user->urlid = generate_urlid($user->username, get_config('cleanurluserdefault'), 3, 30);
            $user->urlid = get_new_profile_urlid($user->urlid);
        }
        if (empty($user->quota)) {
            $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
        }
        if (get_config('defaultaccountlifetime')) {
            // we need to set the user expiry to the site default one
            $user->expiry = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y')) + (int) get_config('defaultaccountlifetime'));
        }
        $user->id = insert_record('usr', $user, 'id', true);
    }
    if (isset($user->email) && $user->email != '') {
        set_profile_field($user->id, 'email', $user->email, TRUE);
    }
    if (isset($user->firstname) && $user->firstname != '') {
        set_profile_field($user->id, 'firstname', $user->firstname, TRUE);
    }
    if (isset($user->lastname) && $user->lastname != '') {
        set_profile_field($user->id, 'lastname', $user->lastname, TRUE);
    }
    foreach ($profile as $k => $v) {
        if (in_array($k, array('firstname', 'lastname', 'email'))) {
            continue;
        }
        set_profile_field($user->id, $k, $v, TRUE);
    }
    if (!empty($institution)) {
        if (is_string($institution)) {
            $institution = new Institution($institution);
        }
        if ($institution->name != 'mahara') {
            $institution->addUserAsMember($user);
            // uses $user->newuser
            if (empty($accountprefs['licensedefault'])) {
                $accountprefs['licensedefault'] = LICENSE_INSTITUTION_DEFAULT;
            }
        }
    }
    $authobj = get_record('auth_instance', 'id', $user->authinstance);
    $authinstance = AuthFactory::create($authobj->id);
    // For legacy compatibility purposes, we'll also put the remote auth on there if it has been
    // specifically requested.
    if ($authinstance->needs_remote_username() || !empty($remoteauth)) {
        if (isset($remotename) && strlen($remotename) > 0) {
            $un = $remotename;
        } else {
            $un = $user->username;
        }
        // remote username must not already exist
        if (record_exists('auth_remote_user', 'remoteusername', $un, 'authinstance', $user->authinstance)) {
            throw new InvalidArgumentException("user_create: remoteusername already exists: ({$un}, {$user->authinstance})");
        }
        insert_record('auth_remote_user', (object) array('authinstance' => $user->authinstance, 'remoteusername' => $un, 'localusr' => $user->id));
    }
    // Set account preferences
    if (!empty($accountprefs)) {
        $expectedprefs = expected_account_preferences();
        foreach ($expectedprefs as $eprefkey => $epref) {
            if (isset($accountprefs[$eprefkey]) && $accountprefs[$eprefkey] != $epref) {
                set_account_preference($user->id, $eprefkey, $accountprefs[$eprefkey]);
            }
        }
    }
    // Copy site views and collections to the new user's profile
    $userobj = new User();
    $userobj->find_by_id($user->id);
    $userobj->copy_site_views_collections_to_new_user();
    reset_password($user, false, $quickhash);
    handle_event('createuser', $user);
    db_commit();
    return $user->id;
}
Пример #13
0
function addpost_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $parentid = param_integer('parent');
    $postid = insert_record('interaction_forum_post', (object) array('topic' => $values['topic'], 'poster' => $USER->get('id'), 'parent' => $parentid, 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time())), 'id', true);
    $delay = get_config_plugin('interaction', 'forum', 'postdelay');
    if (!is_null($delay) && $delay == 0) {
        PluginInteractionForum::interaction_forum_new_post(array($postid));
    }
    $SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
    redirect('/interaction/forum/topic.php?id=' . $values['topic'] . '#post' . $postid);
}
Пример #14
0
 public function wallpost_form(BlockInstance $instance, $replyto = '', $replyuser = '')
 {
     if ($replyuser) {
         $walltoreplyto = self::get_wall_id_for_user($replyuser);
     } else {
         $walltoreplyto = $instance->get('id');
     }
     require_once 'pieforms/pieform.php';
     return pieform(array('name' => 'wallpost_' . $instance->get('id'), 'renderer' => 'maharatable', 'autofocus' => false, 'jsform' => true, 'template' => 'wallpost.php', 'templatedir' => pieform_template_dir('wallpost.php', 'blocktype/wall'), 'successcallback' => array('PluginBlocktypeWall', 'wallpost_submit'), 'jssuccesscallback' => 'wallpost_success', 'elements' => array('text' => array('type' => 'textarea', 'description' => bbcode_format_post_message(), 'rows' => 3, 'cols' => 50, 'defaultvalue' => '', 'width' => '100%', 'rules' => array('required' => true, 'maxlength' => get_config_plugin('blocktype', 'wall', 'defaultpostsizelimit'))), 'postsizelimit' => array('type' => 'html', 'value' => get_string('maxcharacters', 'blocktype.wall', get_config_plugin('blocktype', 'wall', 'defaultpostsizelimit'))), 'private' => array('type' => 'checkbox', 'title' => get_string('makeyourpostprivate', 'blocktype.wall')), 'instance' => array('type' => 'hidden', 'value' => $walltoreplyto), 'replyto' => array('type' => 'hidden', 'value' => $replyto), 'submit' => array('type' => 'submit', 'value' => get_string('Post', 'blocktype.wall')))));
     // TODO if replying here, add select element for replyto other wall or own wall
     // depending on if the user we're replying to has a wall
 }
Пример #15
0
global $CFG, $USER, $SESSION;
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once get_config('docroot') . 'auth/saml/lib.php';
require_once get_config('libroot') . 'institution.php';
// check that the plugin is active
if (get_field('auth_installed', 'active', 'name', 'saml') != 1) {
    redirect();
}
// get the config pointing to the SAML library - and load it
$samllib = get_config_plugin('auth', 'saml', 'simplesamlphplib');
if (!file_exists($samllib . '/lib/_autoload.php')) {
    throw new AuthInstanceException(get_string('errorbadssphplib', 'auth.saml'));
}
require_once $samllib . '/lib/_autoload.php';
// point at the configured config directory
$samlconfig = get_config_plugin('auth', 'saml', 'simplesamlphpconfig');
// get all the things that we will need from the SAML authentication
// and then shutdown the session control
SimpleSAML_Configuration::init($samlconfig);
$saml_session = SimpleSAML_Session::getInstance();
// do we have a logout request?
if (param_variable("logout", false)) {
    // logout the saml session
    $sp = $saml_session->getAuthority();
    if (!$sp) {
        $sp = 'default-sp';
    }
    $as = new SimpleSAML_Auth_Simple($sp);
    $as->logout($CFG->wwwroot);
}
$sp = param_alphanumext('as', 'default-sp');
Пример #16
0
 function create_registered_user($profilefields = array())
 {
     global $registration, $SESSION, $USER;
     require_once get_config('libroot') . 'user.php';
     db_begin();
     // Move the user record to the usr table from the registration table
     $registrationid = $registration->id;
     unset($registration->id);
     unset($registration->expiry);
     if ($expirytime = get_config('defaultregistrationexpirylifetime')) {
         $registration->expiry = db_format_timestamp(time() + $expirytime);
     }
     $registration->lastlogin = db_format_timestamp(time());
     $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', $registration->authtype ? $registration->authtype : 'internal');
     if (false == $authinstance) {
         throw new ConfigException('No ' . ($registration->authtype ? $registration->authtype : 'internal') . ' auth instance for institution');
     }
     if (!empty($registration->extra)) {
         // Additional user settings were added during confirmation
         $extrafields = unserialize($registration->extra);
     }
     $user = new User();
     $user->active = 1;
     $user->authinstance = $authinstance->id;
     $user->firstname = $registration->firstname;
     $user->lastname = $registration->lastname;
     $user->email = $registration->email;
     $user->username = get_new_username($user->firstname . $user->lastname);
     $user->passwordchange = 1;
     // Points that indicate the user is a "new user" who should be restricted from spammy activities.
     // We count these down when they do good things; when they have 0 they're no longer a "new user"
     if (is_using_probation()) {
         $user->probation = get_config('probationstartingpoints');
     } else {
         $user->probation = 0;
     }
     if ($registration->institution != 'mahara') {
         if (count_records_select('institution', "name != 'mahara'") == 1 || $registration->pending == 2) {
             if (get_config_plugin('artefact', 'file', 'institutionaloverride')) {
                 $user->quota = get_field('institution', 'defaultquota', 'name', $registration->institution);
             }
         }
     }
     create_user($user, $profilefields);
     // If the institution is 'mahara' then don't do anything
     if ($registration->institution != 'mahara') {
         $institutions = get_records_select_array('institution', "name != 'mahara'");
         // If there is only one available, join it without requiring approval
         if (count($institutions) == 1) {
             $user->join_institution($registration->institution);
         } else {
             if ($registration->pending == 2) {
                 if (get_config('requireregistrationconfirm') || get_field('institution', 'registerconfirm', 'name', $registration->institution)) {
                     $user->join_institution($registration->institution);
                 }
             } else {
                 if ($registration->authtype && $registration->authtype != 'internal') {
                     $auth = AuthFactory::create($authinstance->id);
                     if ($auth->weautocreateusers) {
                         $user->join_institution($registration->institution);
                     } else {
                         $user->add_institution_request($registration->institution);
                     }
                 } else {
                     $user->add_institution_request($registration->institution);
                 }
             }
         }
         if (!empty($extrafields->institutionstaff)) {
             // If the user isn't a member yet, this does nothing, but that's okay, it'll
             // only be set after successful confirmation.
             set_field('usr_institution', 'staff', 1, 'usr', $user->id, 'institution', $registration->institution);
         }
     }
     if (!empty($registration->lang) && $registration->lang != 'default') {
         set_account_preference($user->id, 'lang', $registration->lang);
     }
     // Delete the old registration record
     delete_records('usr_registration', 'id', $registrationid);
     db_commit();
     // Log the user in and send them to the homepage
     $USER = new LiveUser();
     $USER->reanimate($user->id, $authinstance->id);
     if (function_exists('local_post_register')) {
         local_post_register($registration);
     }
     $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename')));
     $SESSION->set('resetusername', true);
     redirect();
 }
Пример #17
0
function core_install_lastcoredata_defaults()
{
    db_begin();
    $institution = new StdClass();
    $institution->name = 'mahara';
    $institution->displayname = 'No Institution';
    $institution->authplugin = 'internal';
    $institution->theme = 'default';
    insert_record('institution', $institution);
    $auth_instance = new StdClass();
    $auth_instance->instancename = 'Internal';
    $auth_instance->priority = '1';
    $auth_instance->institution = 'mahara';
    $auth_instance->authname = 'internal';
    $auth_instance->id = insert_record('auth_instance', $auth_instance, 'id', true);
    // Insert the root user
    $user = new StdClass();
    $user->id = 0;
    $user->username = '******';
    $user->password = '******';
    $user->salt = '*';
    $user->firstname = 'System';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->authinstance = $auth_instance->id;
    if (is_mysql()) {
        // gratuitous mysql workaround
        $newid = insert_record('usr', $user, 'id', true);
        set_field('usr', 'id', 0, 'id', $newid);
        execute_sql('ALTER TABLE {usr} AUTO_INCREMENT=1');
    } else {
        insert_record('usr', $user);
    }
    install_system_profile_view();
    // Insert the admin user
    $user = new StdClass();
    $user->username = '******';
    $user->password = '******';
    $user->authinstance = $auth_instance->id;
    $user->passwordchange = 1;
    $user->admin = 1;
    $user->firstname = 'Admin';
    $user->lastname = 'User';
    $user->email = '*****@*****.**';
    $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
    $user->id = insert_record('usr', $user, 'id', true);
    set_profile_field($user->id, 'email', $user->email);
    set_profile_field($user->id, 'firstname', $user->firstname);
    set_profile_field($user->id, 'lastname', $user->lastname);
    set_config('installed', true);
    handle_event('createuser', $user->id);
    activity_add_admin_defaults(array($user->id));
    db_commit();
    // if we're installing, set up the block categories here and then poll the plugins.
    // if we're upgrading this happens somewhere else.  This is because of dependency issues around
    // the order of installation stuff.
    install_blocktype_extras();
}
Пример #18
0
function edituser_site_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    if (!($user = get_record('usr', 'id', $values['id']))) {
        return false;
    }
    $maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
    $maxquota = get_config_plugin('artefact', 'file', 'maxquota');
    if ($maxquotaenabled && $values['quota'] > $maxquota) {
        $form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
        $SESSION->add_error_msg(get_string('maxquotaexceeded', 'artefact.file', display_size($maxquota)));
    }
    // Check that the external username isn't already in use
    if (isset($values['remoteusername']) && ($usedby = get_record_select('auth_remote_user', 'authinstance = ? AND remoteusername = ? AND localusr != ?', array($values['authinstance'], $values['remoteusername'], $values['id'])))) {
        $usedbyuser = get_field('usr', 'username', 'id', $usedby->localusr);
        $SESSION->add_error_msg(get_string('duplicateremoteusername', 'auth', $usedbyuser));
        $form->set_error('remoteusername', get_string('duplicateremoteusernameformerror', 'auth'));
    }
}
Пример #19
0
/**
 * Create user
 *
 * @param object $user stdclass or User object for the usr table
 * @param array  $profile profile field/values to set
 * @param string $institution Institution the user should joined to
 * @param stdclass $remoteauth authinstance record for a remote authinstance
 * @param string $remotename username on the remote site
 * @return integer id of the new user
 */
function create_user($user, $profile = array(), $institution = null, $remoteauth = null, $remotename = null)
{
    db_begin();
    if ($user instanceof User) {
        $user->create();
        $user->quota_init();
        $user->commit();
        $user = $user->to_stdclass();
    } else {
        $user->ctime = db_format_timestamp(time());
        if (empty($user->quota)) {
            $user->quota = get_config_plugin('artefact', 'file', 'defaultquota');
        }
        $user->id = insert_record('usr', $user, 'id', true);
    }
    // Bypass access check for 'copynewuser' institution/site views, because this user may not be logged in yet
    $user->newuser = true;
    if (isset($user->email) && $user->email != '') {
        set_profile_field($user->id, 'email', $user->email);
    }
    if (isset($user->firstname) && $user->firstname != '') {
        set_profile_field($user->id, 'firstname', $user->firstname);
    }
    if (isset($user->lastname) && $user->lastname != '') {
        set_profile_field($user->id, 'lastname', $user->lastname);
    }
    foreach ($profile as $k => $v) {
        if (in_array($k, array('firstname', 'lastname', 'email'))) {
            continue;
        }
        set_profile_field($user->id, $k, $v);
    }
    if (!empty($institution) && $institution != 'mahara') {
        if (is_string($institution)) {
            $institution = new Institution($institution);
        }
        if ($institution->name != 'mahara') {
            $institution->addUserAsMember($user);
            // uses $user->newuser
        }
    }
    if (!empty($remoteauth) && $remoteauth->authname != 'internal') {
        if (isset($remotename) && strlen($remotename) > 0) {
            $un = $remotename;
        } else {
            $un = $user->username;
        }
        delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'remoteusername', $un);
        insert_record('auth_remote_user', (object) array('authinstance' => $user->authinstance, 'remoteusername' => $un, 'localusr' => $user->id));
    }
    // Copy site views to the new user's profile
    $checkviewaccess = !$user->newuser;
    $userobj = new User();
    $userobj->find_by_id($user->id);
    $userobj->copy_views(get_column('view', 'id', 'institution', 'mahara', 'copynewuser', 1), $checkviewaccess);
    handle_event('createuser', $user);
    db_commit();
    return $user->id;
}
Пример #20
0
/**
 * Add the users to the system. Make sure that they have to change their
 * password on next login also.
 */
function uploadcsv_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $CSVDATA, $FORMAT, $UPDATES;
    $formatkeylookup = array_flip($FORMAT);
    $authinstance = (int) $values['authinstance'];
    $authrecord = get_record('auth_instance', 'id', $authinstance);
    $authobj = AuthFactory::create($authinstance);
    $institution = new Institution($authobj->institution);
    $maxusers = $institution->maxuseraccounts;
    if (!empty($maxusers)) {
        $members = count_records_sql('
            SELECT COUNT(*) FROM {usr} u INNER JOIN {usr_institution} i ON u.id = i.usr
            WHERE i.institution = ? AND u.deleted = 0', array($institution->name));
        if ($members + count($CSVDATA) > $maxusers) {
            $SESSION->add_error_msg(get_string('uploadcsvfailedusersexceedmaxallowed', 'admin'));
            redirect('/admin/users/uploadcsv.php');
        }
    }
    if ($values['updateusers']) {
        log_info('Updating users from the CSV file');
    } else {
        log_info('Inserting users from the CSV file');
    }
    db_begin();
    $addedusers = array();
    $cfgsendemail = get_config('sendemail');
    if (empty($values['emailusers'])) {
        // Temporarily disable email sent during user creation, e.g. institution membership
        $GLOBALS['CFG']->sendemail = false;
    }
    $key = 0;
    $steps_total = $values['updateusers'] ? 5 : 4;
    $steps_done = $steps_total - 3;
    $num_lines = sizeof($CSVDATA);
    foreach ($CSVDATA as $record) {
        if (!($key % 25)) {
            // This part has three times the weight of the other two steps.
            set_progress_info('uploaduserscsv', $num_lines * $steps_done + $key * 3, $num_lines * $steps_total, get_string('committingchanges', 'admin'));
        }
        $key++;
        $user = new StdClass();
        foreach ($FORMAT as $field) {
            if ($field == 'username' || $field == 'firstname' || $field == 'lastname' || $field == 'password' || $field == 'email' || $field == 'studentid' || $field == 'preferredname') {
                $user->{$field} = $record[$formatkeylookup[$field]];
            }
        }
        $user->authinstance = $authinstance;
        if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
            $user->quota = $values['quota'];
        }
        $profilefields = new StdClass();
        $remoteuser = null;
        foreach ($FORMAT as $field) {
            if ($field == 'username' || $field == 'password') {
                continue;
            }
            if ($field == 'remoteuser') {
                if (!empty($record[$formatkeylookup[$field]])) {
                    $remoteuser = $record[$formatkeylookup[$field]];
                }
                continue;
            }
            $profilefields->{$field} = $record[$formatkeylookup[$field]];
        }
        if (!$values['updateusers'] || !isset($UPDATES[$user->username])) {
            $user->passwordchange = (int) $values['forcepasswordchange'];
            $user->id = create_user($user, $profilefields, $institution, $authrecord, $remoteuser, $values, true);
            $addedusers[] = $user;
            log_debug('added user ' . $user->username);
        } else {
            if (isset($UPDATES[$user->username])) {
                $updated = update_user($user, $profilefields, $remoteuser, $values, true, true);
                if (empty($updated)) {
                    // Nothing changed for this user
                    unset($UPDATES[$user->username]);
                } else {
                    $UPDATES[$user->username] = $updated;
                    log_debug('updated user ' . $user->username . ' (' . implode(', ', array_keys($updated)) . ')');
                }
            }
        }
        set_time_limit(10);
    }
    db_commit();
    // Reenable email
    set_config('sendemail', $cfgsendemail);
    // Only send e-mail to users after we're sure they have been inserted
    // successfully
    $straccountcreatedtext = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordtext' : 'accountcreatedtext';
    $straccountcreatedhtml = $values['forcepasswordchange'] ? 'accountcreatedchangepasswordhtml' : 'accountcreatedhtml';
    if ($values['emailusers'] && $addedusers) {
        foreach ($addedusers as $user) {
            $failedusers = array();
            try {
                email_user($user, null, get_string('accountcreated', 'mahara', get_config('sitename')), get_string($straccountcreatedtext, 'mahara', $user->firstname, get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('sitename')), get_string($straccountcreatedhtml, 'mahara', $user->firstname, get_config('wwwroot'), get_config('sitename'), $user->username, $user->password, get_config('wwwroot'), get_config('wwwroot'), get_config('sitename')));
            } catch (EmailException $e) {
                log_info($e->getMessage());
                $failedusers[] = $user;
            }
        }
        if ($failedusers) {
            $message = get_string('uploadcsvsomeuserscouldnotbeemailed', 'admin') . "\n<ul>\n";
            foreach ($failedusers as $user) {
                $message .= '<li>' . full_name($user) . ' &lt;' . hsc($user->email) . "&gt;</li>\n";
            }
            $message .= "</ul>\n";
            $SESSION->add_info_msg($message, false);
        }
    }
    log_info('Added ' . count($addedusers) . ' users, updated ' . count($UPDATES) . ' users.');
    $SESSION->add_ok_msg(get_string('csvfileprocessedsuccessfully', 'admin'));
    if ($UPDATES) {
        $updatemsg = smarty_core();
        $updatemsg->assign('added', count($addedusers));
        $updatemsg->assign('updates', $UPDATES);
        $SESSION->add_info_msg($updatemsg->fetch('admin/users/csvupdatemessage.tpl'), false);
    } else {
        $SESSION->add_ok_msg(get_string('numbernewusersadded', 'admin', count($addedusers)));
    }
    set_progress_done('uploaduserscsv');
    redirect('/admin/users/uploadcsv.php');
}
Пример #21
0
 public static function get_searchable_fields()
 {
     if ($pub = get_config_plugin('artefact', 'internal', 'profilepublic')) {
         $public = explode(',', $pub);
     } else {
         $public = array();
     }
     $all = self::get_all_searchable_fields();
     $selected = self::get_always_searchable_fields();
     // If socialprofile is disabled, we need to remove any fields that may
     // have been selected when it was enabled.
     // If socialprofile is enabled, we need to remove any fields that my
     // have been selected when it was disabled.
     $need_to_update = false;
     foreach ($public as $pf) {
         if (isset($all[$pf])) {
             $selected[$pf] = $all[$pf];
         } else {
             $need_to_update = true;
         }
     }
     if ($need_to_update) {
         set_config_plugin('artefact', 'internal', 'profilepublic', join(',', array_keys($selected)));
     }
     return $selected;
 }
Пример #22
0
 public static function artefacttypes_filter_string()
 {
     $artefacttypes = explode(',', get_config_plugin('search', 'elasticsearch', 'artefacttypes'));
     $artefacttypes_str = '';
     foreach ($artefacttypes as $artefacttype) {
         $artefacttypes_str .= '\'' . $artefacttype . '\', ';
     }
     $artefacttypes_str = '(' . substr($artefacttypes_str, 0, strlen($artefacttypes_str) - 2) . ')';
     return $artefacttypes_str;
 }
Пример #23
0
$skintitle = $skinobj->get('title');
$skindesc = $skinobj->get('description');
$skintype = $skinobj->get('type');
$positions = array(1 => 'Top left', 2 => 'Top', 3 => 'Top right', 4 => 'Left', 5 => 'Centre', 6 => 'Right', 7 => 'Bottom left', 8 => 'Bottom', 9 => 'Bottom right');
$elements = array();
$elements['id'] = array('type' => 'hidden', 'value' => $id);
$elements['viewskin'] = array('type' => 'fieldset', 'legend' => get_string('skingeneraloptions', 'skin'), 'class' => $fieldset != 'viewskin' ? 'collapsed' : '', 'elements' => array('viewskin_title' => array('type' => 'text', 'title' => get_string('skintitle', 'skin'), 'defaultvalue' => !empty($skintitle) ? $skintitle : null), 'viewskin_description' => array('type' => 'textarea', 'rows' => 3, 'cols' => 40, 'resizable' => true, 'title' => get_string('skindescription', 'skin'), 'defaultvalue' => !empty($skindesc) ? $skindesc : null), 'viewskin_access' => array('type' => 'select', 'title' => get_string('skinaccessibility1', 'skin'), 'defaultvalue' => !empty($skintype) ? $skintype : null, 'options' => $accessoptions)));
$elements['skinbg'] = array('type' => 'fieldset', 'legend' => get_string('skinbackgroundoptions', 'skin'), 'class' => $fieldset != 'skinbg' ? 'collapsed' : '', 'elements' => array('body_background_color' => array('type' => 'color', 'title' => get_string('bodybgcolor', 'skin'), 'defaultvalue' => !empty($viewskin['body_background_color']) ? $viewskin['body_background_color'] : '#FFFFFF', 'size' => 7, 'options' => array('transparent' => true))));
// Currently site files don't work properly with site skins. And since site files are the only files that would make
// sense with site skins, we're going to just hide background images entirely for site skins for the time being.
if (!$designsiteskin) {
    $elements['skinbg']['elements'] = array_merge($elements['skinbg']['elements'], array('body_background_image' => array('type' => 'filebrowser', 'title' => get_string('bodybgimage', 'skin'), 'folder' => isset($folder) ? $folder : 0, 'highlight' => $highlight, 'browse' => isset($folder) ? 1 : 0, 'filters' => array('artefacttype' => array('image', 'profileicon')), 'page' => get_config('wwwroot') . 'skin/design.php?id=' . $id . '&fs=skinbg', 'config' => array('upload' => false, 'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'), 'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'), 'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'), 'createfolder' => false, 'edit' => false, 'select' => true, 'selectone' => true), 'defaultvalue' => !empty($viewskin['body_background_image']) ? array(intval($viewskin['body_background_image'])) : array(), 'selectlistcallback' => 'artefact_get_records_by_id'), 'body_background_repeat' => array('type' => 'select', 'title' => get_string('backgroundrepeat', 'skin'), 'defaultvalue' => !empty($viewskin['body_background_repeat']) ? intval($viewskin['body_background_repeat']) : 4, 'options' => array(Skin::BACKGROUND_REPEAT_NO => get_string('backgroundrepeatno', 'skin'), Skin::BACKGROUND_REPEAT_X => get_string('backgroundrepeatx', 'skin'), Skin::BACKGROUND_REPEAT_Y => get_string('backgroundrepeaty', 'skin'), Skin::BACKGROUND_REPEAT_BOTH => get_string('backgroundrepeatboth', 'skin'))), 'body_background_attachment' => array('type' => 'radio', 'title' => get_string('backgroundattachment', 'skin'), 'defaultvalue' => !empty($viewskin['body_background_repeat']) ? $viewskin['body_background_attachment'] : 'scroll', 'options' => array('fixed' => get_string('backgroundfixed', 'skin'), 'scroll' => get_string('backgroundscroll', 'skin'))), 'body_background_position' => array('type' => 'radio', 'title' => get_string('backgroundposition', 'skin'), 'defaultvalue' => !empty($viewskin['body_background_position']) ? intval($viewskin['body_background_position']) : 1, 'rowsize' => 3, 'hiddenlabels' => true, 'separator' => '<br />', 'options' => $positions)));
}
$elements['viewbg'] = array('type' => 'fieldset', 'legend' => get_string('viewbackgroundoptions', 'skin'), 'class' => $fieldset != 'viewbg' ? 'collapsed' : '', 'elements' => array('view_background_color' => array('type' => 'color', 'title' => get_string('viewbgcolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_background_color']) ? $viewskin['view_background_color'] : '#FFFFFF', 'size' => 7, 'options' => array('transparent' => true))));
if (!$designsiteskin) {
    $elements['viewbg']['elements'] = array_merge($elements['viewbg']['elements'], array('view_background_image' => array('type' => 'filebrowser', 'title' => get_string('viewbgimage', 'skin'), 'folder' => isset($folder) ? $folder : 0, 'highlight' => $highlight, 'browse' => isset($folder) ? 1 : 0, 'filters' => array('artefacttype' => array('image', 'profileicon')), 'page' => get_config('wwwroot') . 'skin/design.php?id=' . $id . '&fs=viewbg', 'config' => array('upload' => false, 'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'), 'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'), 'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'), 'createfolder' => false, 'edit' => false, 'select' => true, 'selectone' => true), 'defaultvalue' => !empty($viewskin['view_background_image']) ? array(intval($viewskin['view_background_image'])) : array(), 'selectlistcallback' => 'artefact_get_records_by_id'), 'view_background_repeat' => array('type' => 'select', 'title' => get_string('backgroundrepeat', 'skin'), 'defaultvalue' => !empty($viewskin['view_background_repeat']) ? intval($viewskin['view_background_repeat']) : 4, 'options' => array(Skin::BACKGROUND_REPEAT_NO => get_string('backgroundrepeatno', 'skin'), Skin::BACKGROUND_REPEAT_X => get_string('backgroundrepeatx', 'skin'), Skin::BACKGROUND_REPEAT_Y => get_string('backgroundrepeaty', 'skin'), Skin::BACKGROUND_REPEAT_BOTH => get_string('backgroundrepeatboth', 'skin'))), 'view_background_attachment' => array('type' => 'radio', 'title' => get_string('backgroundattachment', 'skin'), 'defaultvalue' => !empty($viewskin['view_background_repeat']) ? $viewskin['view_background_attachment'] : 'scroll', 'options' => array('fixed' => get_string('backgroundfixed', 'skin'), 'scroll' => get_string('backgroundscroll', 'skin'))), 'view_background_position' => array('type' => 'radio', 'title' => get_string('backgroundposition', 'skin'), 'defaultvalue' => !empty($viewskin['view_background_position']) ? intval($viewskin['view_background_position']) : 1, 'rowsize' => 3, 'hiddenlabels' => true, 'separator' => '<br />', 'options' => $positions), 'view_background_width' => array('type' => 'select', 'title' => get_string('viewwidth', 'skin'), 'defaultvalue' => !empty($viewskin['view_background_width']) ? intval($viewskin['view_background_width']) : 90, 'options' => array(50 => '50%', 60 => '60%', 70 => '70%', 80 => '80%', 90 => '90%', 100 => '100%'))));
}
$elements['viewheader'] = array('type' => 'fieldset', 'legend' => get_string('viewheaderoptions', 'skin'), 'class' => $fieldset != 'viewheader' ? 'collapsed' : '', 'elements' => array('header_background_color' => array('type' => 'color', 'title' => get_string('backgroundcolor', 'skin'), 'defaultvalue' => !empty($viewskin['header_background_color']) ? $viewskin['header_background_color'] : '#CCCCCC', 'size' => 7, 'options' => array('transparent' => true)), 'header_text_font_color' => array('type' => 'color', 'title' => get_string('textcolor', 'skin'), 'defaultvalue' => !empty($viewskin['header_text_font_color']) ? $viewskin['header_text_font_color'] : '#000000', 'size' => 7, 'options' => array('transparent' => true)), 'header_link_normal_color' => array('type' => 'color', 'title' => get_string('normallinkcolor', 'skin'), 'defaultvalue' => !empty($viewskin['header_link_normal_color']) ? $viewskin['header_link_normal_color'] : '#0000EE', 'size' => 7, 'options' => array('transparent' => true)), 'header_link_normal_underline' => array('type' => 'checkbox', 'title' => get_string('linkunderlined', 'skin'), 'defaultvalue' => isset($viewskin['header_link_normal_underline']) and intval($viewskin['header_link_normal_underline']) == 1 ? 'checked' : ''), 'header_link_hover_color' => array('type' => 'color', 'title' => get_string('hoverlinkcolor', 'skin'), 'defaultvalue' => !empty($viewskin['header_link_hover_color']) ? $viewskin['header_link_hover_color'] : '#EE0000', 'size' => 7, 'options' => array('transparent' => true)), 'header_link_hover_underline' => array('type' => 'checkbox', 'title' => get_string('linkunderlined', 'skin'), 'defaultvalue' => isset($viewskin['header_link_hover_underline']) and intval($viewskin['header_link_hover_underline']) == 1 ? 'checked' : ''), 'header_logo_image' => array('type' => 'radio', 'id' => 'designskinform_header_logo', 'title' => get_string('headerlogoimage1', 'skin'), 'defaultvalue' => !empty($viewskin['header_logo_image']) ? $viewskin['header_logo_image'] : 'normal', 'options' => array('normal' => get_string('headerlogoimagenormal', 'skin'), 'light' => get_string('headerlogoimagelight1', 'skin'), 'dark' => get_string('headerlogoimagedark1', 'skin')), 'separator' => '<br />')));
$elements['viewcontent'] = array('type' => 'fieldset', 'legend' => get_string('viewcontentoptions', 'skin'), 'class' => $fieldset != 'viewcontent' ? 'collapsed' : '', 'elements' => array('view_heading_font_family' => array('type' => 'select', 'title' => get_string('headingfontfamily', 'skin'), 'defaultvalue' => !empty($viewskin['view_heading_font_family']) ? $viewskin['view_heading_font_family'] : 'Arial', 'width' => 144, 'options' => Skin::get_all_font_options()), 'view_text_font_family' => array('type' => 'select', 'title' => get_string('textfontfamily', 'skin'), 'defaultvalue' => !empty($viewskin['view_text_font_family']) ? $viewskin['view_text_font_family'] : 'Arial', 'width' => 144, 'options' => Skin::get_textonly_font_options()), 'view_text_font_size' => array('type' => 'select', 'title' => get_string('fontsize', 'skin'), 'defaultvalue' => !empty($viewskin['view_text_font_size']) ? $viewskin['view_text_font_size'] : 'small', 'width' => 144, 'height' => 22, 'options' => array('xx-small' => array('value' => get_string('fontsizesmallest', 'skin'), 'style' => 'font-size: xx-small;'), 'x-small' => array('value' => get_string('fontsizesmaller', 'skin'), 'style' => 'font-size: x-small;'), 'small' => array('value' => get_string('fontsizesmall', 'skin'), 'style' => 'font-size: small;'), 'medium' => array('value' => get_string('fontsizemedium', 'skin'), 'style' => 'font-size: medium;'), 'large' => array('value' => get_string('fontsizelarge', 'skin'), 'style' => 'font-size: large;'), 'x-large' => array('value' => get_string('fontsizelarger', 'skin'), 'style' => 'font-size: x-large;'), 'xx-large' => array('value' => get_string('fontsizelargest', 'skin'), 'style' => 'font-size: xx-large;'))), 'view_text_font_color' => array('type' => 'color', 'title' => get_string('textcolor', 'skin'), 'description' => get_string('textcolordescription', 'skin'), 'defaultvalue' => !empty($viewskin['view_text_font_color']) ? $viewskin['view_text_font_color'] : '#000000', 'size' => 7, 'options' => array('transparent' => true)), 'view_text_heading_color' => array('type' => 'color', 'title' => get_string('headingcolor', 'skin'), 'description' => get_string('headingcolordescription', 'skin'), 'defaultvalue' => !empty($viewskin['view_text_heading_color']) ? $viewskin['view_text_heading_color'] : '#000000', 'size' => 7, 'options' => array('transparent' => true)), 'view_text_emphasized_color' => array('type' => 'color', 'title' => get_string('emphasizedcolor', 'skin'), 'description' => get_string('emphasizedcolordescription', 'skin'), 'defaultvalue' => !empty($viewskin['view_text_emphasized_color']) ? $viewskin['view_text_emphasized_color'] : '#000000', 'size' => 7, 'options' => array('transparent' => true)), 'view_link_normal_color' => array('type' => 'color', 'title' => get_string('normallinkcolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_link_normal_color']) ? $viewskin['view_link_normal_color'] : '#0000EE', 'size' => 7, 'options' => array('transparent' => true)), 'view_link_normal_underline' => array('type' => 'checkbox', 'title' => get_string('linkunderlined', 'skin'), 'defaultvalue' => isset($viewskin['view_link_normal_underline']) and intval($viewskin['view_link_normal_underline']) == 1 ? 'checked' : ''), 'view_link_hover_color' => array('type' => 'color', 'title' => get_string('hoverlinkcolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_link_hover_color']) ? $viewskin['view_link_hover_color'] : '#EE0000', 'size' => 7, 'options' => array('transparent' => true)), 'view_link_hover_underline' => array('type' => 'checkbox', 'title' => get_string('linkunderlined', 'skin'), 'defaultvalue' => isset($viewskin['view_link_hover_underline']) and intval($viewskin['view_link_hover_underline']) == 1 ? 'checked' : '')));
$elements['viewtable'] = array('type' => 'fieldset', 'legend' => get_string('viewtableoptions', 'skin'), 'class' => $fieldset != 'viewtable' ? 'collapsed' : '', 'elements' => array('view_table_border_color' => array('type' => 'color', 'title' => get_string('tableborder', 'skin'), 'defaultvalue' => !empty($viewskin['view_table_border_color']) ? $viewskin['view_table_border_color'] : '#CCCCCC', 'size' => 7, 'options' => array('transparent' => true)), 'view_table_header_color' => array('type' => 'color', 'title' => get_string('tableheader', 'skin'), 'defaultvalue' => !empty($viewskin['view_table_header_color']) ? $viewskin['view_table_header_color'] : '#CCCCCC', 'size' => 7, 'options' => array('transparent' => true)), 'view_table_header_text_color' => array('type' => 'color', 'title' => get_string('tableheadertext', 'skin'), 'defaultvalue' => !empty($viewskin['view_table_header_text_color']) ? $viewskin['view_table_header_text_color'] : '#000000', 'size' => 7, 'options' => array('transparent' => true)), 'view_table_odd_row_color' => array('type' => 'color', 'title' => get_string('tableoddrows', 'skin'), 'defaultvalue' => !empty($viewskin['view_table_odd_row_color']) ? $viewskin['view_table_odd_row_color'] : '#EEEEEE', 'size' => 7, 'options' => array('transparent' => true)), 'view_table_even_row_color' => array('type' => 'color', 'title' => get_string('tableevenrows', 'skin'), 'defaultvalue' => !empty($viewskin['view_table_even_row_color']) ? $viewskin['view_table_even_row_color'] : '#FFFFFF', 'size' => 7, 'options' => array('transparent' => true)), 'view_button_normal_color' => array('type' => 'color', 'title' => get_string('normalbuttoncolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_button_normal_color']) ? $viewskin['view_button_normal_color'] : '#CCCCCC', 'options' => array('transparent' => true)), 'view_button_hover_color' => array('type' => 'color', 'title' => get_string('hoverbuttoncolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_button_hover_color']) ? $viewskin['view_button_hover_color'] : '#EEEEEE', 'options' => array('transparent' => true)), 'view_button_text_color' => array('type' => 'color', 'title' => get_string('buttontextcolor', 'skin'), 'defaultvalue' => !empty($viewskin['view_button_text_color']) ? $viewskin['view_button_text_color'] : '#FFFFFF', 'options' => array('transparent' => true))));
$elements['viewadvanced'] = array('type' => 'fieldset', 'legend' => get_string('viewadvancedoptions', 'skin'), 'class' => $fieldset != 'viewadvanced' ? 'collapsed' : '', 'elements' => array('view_custom_css' => array('type' => 'textarea', 'rows' => 7, 'cols' => 50, 'style' => 'font-family:monospace', 'resizable' => true, 'fullwidth' => true, 'title' => get_string('skincustomcss', 'skin'), 'description' => get_string('skincustomcssdescription', 'skin'), 'defaultvalue' => !empty($viewskin['view_custom_css']) ? $viewskin['view_custom_css'] : null)));
$elements['fs'] = array('type' => 'hidden', 'value' => $fieldset);
$elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('save', 'mahara'), get_string('cancel', 'mahara')), 'goto' => get_config('wwwroot') . $goto);
$designskinform = pieform(array('name' => 'designskinform', 'class' => 'jstabs', 'method' => 'post', 'plugintype' => 'core', 'pluginname' => 'skin', 'renderer' => 'table', 'autofocus' => false, 'configdirs' => array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/file/form/'), 'elements' => $elements));
$smarty = smarty(array('jquery', 'tabs'), array(), array('mahara' => array('tab', 'selected')), array());
$smarty->assign('LANG', substr($CFG->lang, 0, 2));
$smarty->assign('USER', $USER);
$smarty->assign('designskinform', $designskinform);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->display('skin/design.tpl');
function designskinform_validate(Pieform $form, $values)
Пример #24
0
 public static function get_config_options()
 {
     $elements = array();
     $elements['gallerysettings'] = array('type' => 'fieldset', 'legend' => get_string('gallerysettings', 'blocktype.file/gallery'), 'collapsible' => true, 'elements' => array('useslimbox2' => array('type' => 'checkbox', 'title' => get_string('useslimbox2', 'blocktype.file/gallery'), 'description' => get_string('useslimbox2desc', 'blocktype.file/gallery'), 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'useslimbox2')), 'photoframe' => array('type' => 'checkbox', 'title' => get_string('photoframe', 'blocktype.file/gallery'), 'description' => get_string('photoframedesc', 'blocktype.file/gallery'), 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'photoframe')), 'previewwidth' => array('type' => 'text', 'size' => 4, 'title' => get_string('previewwidth', 'blocktype.file/gallery'), 'description' => get_string('previewwidthdesc', 'blocktype.file/gallery'), 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'previewwidth'), 'rules' => array('integer' => true, 'minvalue' => 16, 'maxvalue' => 1600))));
     $elements['flickrsettings'] = array('type' => 'fieldset', 'legend' => get_string('flickrsettings', 'blocktype.file/gallery'), 'collapsible' => true, 'collapsed' => true, 'elements' => array('flickrapikey' => array('type' => 'text', 'title' => get_string('flickrapikey', 'blocktype.file/gallery'), 'size' => 40, 'description' => get_string('flickrapikeydesc', 'blocktype.file/gallery'), 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'flickrapikey'))));
     $elements['photobucketsettings'] = array('type' => 'fieldset', 'legend' => get_string('pbsettings', 'blocktype.file/gallery'), 'collapsible' => true, 'collapsed' => true, 'elements' => array('pbapikey' => array('type' => 'text', 'title' => get_string('pbapikey', 'blocktype.file/gallery'), 'size' => 20, 'description' => get_string('pbapikeydesc', 'blocktype.file/gallery'), 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'pbapikey')), 'pbapiprivatekey' => array('type' => 'text', 'title' => get_string('pbapiprivatekey', 'blocktype.file/gallery'), 'size' => 40, 'defaultvalue' => get_config_plugin('blocktype', 'gallery', 'pbapiprivatekey'))));
     return array('elements' => $elements);
 }
Пример #25
0
 public function quota_init()
 {
     if (!$this->get('quota')) {
         if ($defaultquota = get_config_plugin('artefact', 'file', 'defaultquota')) {
             $this->set('quota', $defaultquota);
         }
     }
 }
Пример #26
0
 public static function instance_config_form(BlockInstance $instance)
 {
     $configdata = $instance->get('configdata');
     safe_require('artefact', 'file');
     $instance->set('artefactplugin', 'file');
     $elements = array('artefactfieldset' => array('type' => 'fieldset', 'collapsible' => true, 'collapsed' => true, 'legend' => get_string('Folders', 'artefact.file'), 'class' => 'last select-file mtl', 'elements' => array('artefactid' => self::filebrowser_element($instance, isset($configdata['artefactid']) ? array($configdata['artefactid']) : null))), 'sortorder' => array('type' => 'select', 'title' => get_string('sortorder'), 'defaultvalue' => isset($configdata['sortorder']) ? $configdata['sortorder'] : get_config_plugin('blocktype', 'folder', 'sortorder'), 'options' => array('asc' => get_string('ascending'), 'desc' => get_string('descending'))));
     if (get_config_plugin('blocktype', 'folder', 'folderdownloadzip')) {
         $elements['folderdownloadzip'] = array('type' => 'checkbox', 'labelhtml' => get_string('downloadfolderzipblock', 'artefact.file'), 'description' => get_string('downloadfolderzipdescriptionblock', 'artefact.file'), 'defaultvalue' => get_config_plugin('blocktype', 'folder', 'folderdownloadzip') ? isset($configdata['folderdownloadzip']) ? $configdata['folderdownloadzip'] : 0 : 0);
     }
     return $elements;
 }
Пример #27
0
            $artefact->commit();
        }
    } else {
        throw new ArtefactNotFoundException(get_string('cannotfindcreateartefact', 'artefact.resume'));
    }
}
if ($artefact->get('owner') != $USER->get('id')) {
    throw new AccessDeniedException(get_string('notartefactowner', 'error'));
}
$folder = param_integer('folder', 0);
$browse = (int) param_variable('browse', 0);
$highlight = null;
if ($file = param_integer('file', 0)) {
    $highlight = array($file);
}
$form = pieform(array('name' => 'editgoalsandskills', 'method' => 'post', 'jsform' => true, 'newiframeonsubmit' => true, 'jssuccesscallback' => 'editgoalsandskills_callback', 'jserrorcallback' => 'editgoalsandskills_callback', 'plugintype' => 'artefact', 'pluginname' => 'resume', 'configdirs' => array(get_config('libroot') . 'form/', get_config('docroot') . 'artefact/file/form/'), 'elements' => array('description' => array('type' => 'wysiwyg', 'title' => get_string('description', 'artefact.resume'), 'rows' => 20, 'cols' => 65, 'defaultvalue' => $artefact->get('description'), 'rules' => array('maxlength' => 65536)), 'filebrowser' => array('type' => 'filebrowser', 'title' => get_string('attachments', 'artefact.blog'), 'folder' => $folder, 'highlight' => $highlight, 'browse' => $browse, 'page' => get_config('wwwroot') . 'artefact/resume/editgoalsandskills.php?id=' . $artefact->get('id') . '&browse=1', 'browsehelp' => 'browsemyfiles', 'config' => array('upload' => true, 'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'), 'resizeonuploaduseroption' => get_config_plugin('artefact', 'file', 'resizeonuploaduseroption'), 'resizeonuploaduserdefault' => $USER->get_account_preference('resizeonuploaduserdefault'), 'createfolder' => false, 'edit' => false, 'select' => true), 'defaultvalue' => $artefact->attachment_id_list(), 'selectlistcallback' => 'artefact_get_records_by_id', 'selectcallback' => 'add_resume_attachment', 'unselectcallback' => 'delete_resume_attachment'), 'artefacttype' => array('type' => 'hidden', 'value' => $artefact->get('artefacttype')), 'submitform' => array('type' => 'submitcancel', 'class' => 'btn-success', 'value' => array(get_string('save'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'artefact/resume/goalsandskills.php'))));
/*
 * Javascript specific to this page.  Creates the list of files
 * attached to the resume goals or skills.
 */
$wwwroot = get_config('wwwroot');
$noimagesmessage = json_encode(get_string('noimageshavebeenattachedtothispost', 'artefact.blog'));
$javascript = <<<EOF
function editgoalsandskills_callback(form, data) {
    editgoalsandskills_filebrowser.callback(form, data);
};
EOF;
$smarty = smarty(array(), array(), array(), array('tinymceconfig' => '
        plugins: "tooltoggle,textcolor,link,imagebrowser,table,emoticons,spellchecker,paste,code,fullscreen,directionality,searchreplace,nonbreaking,charmap",
        image_filebrowser: "editgoalsandskills_filebrowser",
    ', 'sideblocks' => array(array('name' => 'quota', 'weight' => -10, 'data' => array()))));
Пример #28
0
 public static function get_config_options()
 {
     $elements = array('commentratings' => array('type' => 'checkbox', 'title' => get_string('commentratings', 'artefact.comment'), 'defaultvalue' => get_config_plugin('artefact', 'comment', 'commentratings'), 'help' => true));
     return array('name' => 'commentconfig', 'elements' => $elements, 'renderer' => 'table');
 }
Пример #29
0
function xmldb_artefact_file_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2007010900) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('adminfiles');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
        set_field('artefact_file_files', 'adminfiles', 0);
        // Put all folders into artefact_file_files
        $folders = get_column_sql("\n            SELECT a.id\n            FROM {artefact} a\n            LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n            WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
        if ($folders) {
            foreach ($folders as $folderid) {
                $data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
                insert_record('artefact_file_files', $data);
            }
        }
    }
    if ($oldversion < 2007011800) {
        // Make sure the default quota is set
        set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
    }
    if ($oldversion < 2007011801) {
        // Create image table
        $table = new XMLDBTable('artefact_file_image');
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
        $status = $status && create_table($table);
        $images = get_column('artefact', 'id', 'artefacttype', 'image');
        log_debug(count($images));
        require_once get_config('docroot') . 'artefact/lib.php';
        foreach ($images as $imageid) {
            $image = artefact_instance_from_id($imageid);
            $path = $image->get_path();
            $image->set('dirty', false);
            $data = new StdClass();
            $data->artefact = $imageid;
            if (file_exists($path)) {
                list($data->width, $data->height) = getimagesize($path);
            }
            if (empty($data->width) || empty($data->height)) {
                $data->width = 0;
                $data->height = 0;
            }
            insert_record('artefact_file_image', $data);
        }
    }
    if ($oldversion < 2007013100) {
        // Add new tables for file/mime types
        $table = new XMLDBTable('artefact_file_file_types');
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
        create_table($table);
        $table = new XMLDBTable('artefact_file_mime_types');
        $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
        $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        create_table($table);
        safe_require('artefact', 'file');
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2007021400) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('oldextension');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2007042500) {
        // migrate everything we had to change to  make mysql happy
        execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
    }
    if ($oldversion < 2008091100) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('fileid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        add_field($table, $field);
        execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL");
    }
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('filetype');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
        // Guess mime type for existing files
        $fileartefacts = get_records_sql_array('
            SELECT
                a.artefacttype, f.artefact, f.oldextension, f.fileid
            FROM
                {artefact} a,
                {artefact_file_files} f
            WHERE
                a.id = f.artefact
        ', array());
        require_once get_config('libroot') . 'file.php';
        if ($fileartefacts) {
            foreach ($fileartefacts as $a) {
                $type = null;
                if ($a->artefacttype == 'image') {
                    $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                    $type = $size['mime'];
                } else {
                    if ($a->artefacttype == 'profileicon') {
                        $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        $type = $size['mime'];
                    } else {
                        if ($a->artefacttype == 'file') {
                            $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        }
                    }
                }
                if ($type) {
                    set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact);
                }
            }
        }
        delete_records('config', 'field', 'pathtofile');
    }
    if ($oldversion < 2008101701) {
        if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
            $olddata = unserialize($data);
            $newdata = array();
            foreach ($olddata as $d) {
                if ($d == 'mov') {
                    $newdata[] = 'quicktime';
                } else {
                    if ($d == 'mp4') {
                        $newdata[] = 'mp4_video';
                    } else {
                        if ($d != 'mpg') {
                            $newdata[] = $d;
                        }
                    }
                }
            }
            set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata));
        }
    }
    if ($oldversion < 2009021200) {
        $table = new XMLDBTable('artefact_file_mime_types');
        $key = new XMLDBKey('artefilemimetype_des_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        drop_key($table, $key);
        $table = new XMLDBTable('artefact_file_file_types');
        drop_table($table);
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2009021301) {
        // IE has been uploading jpegs with the image/pjpeg mimetype,
        // which is not recognised as an image by the download script.
        // Fix all existing jpegs in the db:
        set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg');
        // This won't happen again because we now read the contents of the
        // uploaded file to detect image artefacts, and overwrite the mime
        // type declared by the browser if we see an image.
    }
    if ($oldversion < 2009033000) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
        }
    }
    return $status;
}
Пример #30
0
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
$issiteview = $view->get('institution') == 'mahara';
if ($viewskin && get_config('skins') && can_use_skins($owner, false, $issiteview) && (!isset($THEME->skins) || $THEME->skins !== false)) {
    $skin = array('skinid' => $viewskin, 'viewid' => $view->get('id'));
    $skindata = unserialize(get_field('skin', 'viewskin', 'id', $viewskin));
} else {
    $skin = false;
}
if (!$view->is_public()) {
    $headers[] = '<meta name="robots" content="noindex">';
    // Tell search engines not to index non-public views
}
// include slimbox2 js and css files, if it is enabled...
if (get_config_plugin('blocktype', 'gallery', 'useslimbox2')) {
    $langdir = get_string('thisdirection', 'langconfig') == 'rtl' ? '-rtl' : '';
    $headers = array_merge($headers, array('<script type="application/javascript" src="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/js/slimbox2.js') . '"></script>', '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'lib/slimbox2/css/slimbox2' . $langdir . '.css') . '">'));
}
$can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
$can_copy = $view->is_copyable($view);
$viewgroupform = false;
if ($owner && $owner == $USER->get('id')) {
    if ($tutorgroupdata = group_get_user_course_groups()) {
        if (!$view->is_submitted()) {
            $viewgroupform = view_group_submission_form($view, $tutorgroupdata, 'view');
        }
    }
}
$viewcontent = $view->build_rows();
// Build content before initialising smarty in case pieform elements define headers.