function editsitepage_submit(Pieform $form, $values) { global $USER; $data = new StdClass(); $data->name = $values['pagename']; $data->content = $values['pagetext']; $data->mtime = db_format_timestamp(time()); $data->mauthor = $USER->get('id'); try { update_record('site_content', $data, 'name'); } catch (SQLException $e) { $form->reply(PIEFORM_ERR, get_string('savefailed', 'admin')); } $form->reply(PIEFORM_OK, get_string('pagesaved', 'admin')); }
function networkingform_submit(Pieform $form, $values) { $reply = ''; if ($form->get_submitvalue() === 'deletekey') { global $SESSION; $openssl = OpenSslRepo::singleton(); $openssl->get_keypair(true); $SESSION->add_info_msg(get_string('keydeleted', 'admin')); // Using cancel here as a hack to get it to redirect so it shows the new keys $form->reply(PIEFORM_CANCEL, array('location' => get_config('wwwroot') . 'admin/site/networking.php')); } if (get_config('enablenetworking') != $values['enablenetworking']) { if (!set_config('enablenetworking', $values['enablenetworking'])) { networkingform_fail($form); } else { if (empty($values['enablenetworking'])) { $reply .= get_string('networkingdisabled', 'admin'); } else { $reply .= get_string('networkingenabled', 'admin'); } } } if (get_config('promiscuousmode') != $values['promiscuousmode']) { if (!set_config('promiscuousmode', $values['promiscuousmode'])) { networkingform_fail($form); } else { if (empty($values['promiscuousmode'])) { $reply .= get_string('promiscuousmodedisabled', 'admin'); } else { $reply .= get_string('promiscuousmodeenabled', 'admin'); } } } $form->reply(PIEFORM_OK, array('message' => $reply == '' ? get_string('networkingunchanged', 'admin') : $reply, 'goto' => '/admin/site/networking.php')); }
function resumelicense_submit(Pieform $form, $values) { global $personalinformation, $USER; $userid = $USER->get('id'); if (empty($personalinformation)) { $personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume'))); } if (get_config('licensemetadata')) { $personalinformation->set('license', $values['license']); $personalinformation->set('licensor', $values['licensor']); $personalinformation->set('licensorurl', $values['licensorurl']); } $personalinformation->commit(); $result = array('error' => false, 'message' => get_string('resumesaved', 'artefact.resume'), 'goto' => get_config('wwwroot') . 'artefact/resume/license.php'); if ($form->submitted_by_js()) { $SESSION->add_ok_msg($result['message']); $form->json_reply(PIEFORM_OK, $result, false); } $form->reply(PIEFORM_OK, $result); }
function add_feedback_form_cancel_submit(Pieform $form) { global $view; $form->reply(PIEFORM_OK, array('goto' => '/' . $view->get_url(false))); }
public function instance_config_store(Pieform $form, $values) { global $SESSION, $USER; // Destroy form values we don't care about unset($values['sesskey']); unset($values['blockinstance']); unset($values['action_configureblockinstance_id_' . $this->get('id')]); unset($values['blockconfig']); unset($values['id']); unset($values['change']); unset($values['new']); if (isset($values['retractable'])) { switch ($values['retractable']) { case BlockInstance::RETRACTABLE_YES: $values['retractable'] = 1; $values['retractedonload'] = 0; break; case BlockInstance::RETRACTABLE_RETRACTED: $values['retractable'] = 1; $values['retractedonload'] = 1; break; case BlockInstance::RETRACTABLE_NO: default: $values['retractable'] = 0; $values['retractedonload'] = 0; break; } } // make sure that user is allowed to publish artefact. This is to stop // hacking of form value to attach other users private data. $badattachment = false; if (!empty($values['artefactid'])) { $badattachment = !$this->verify_attachment_permissions($values['artefactid']); } if (!empty($values['artefactids'])) { $badattachment = !$this->verify_attachment_permissions($values['artefactids']); } if ($badattachment) { $result['message'] = get_string('unrecoverableerror', 'error'); $form->set_error(null, $result['message']); $form->reply(PIEFORM_ERR, $result); exit; } $redirect = '/view/blocks.php?id=' . $this->get('view'); if (param_boolean('new', false)) { $redirect .= '&new=1'; } if ($category = param_alpha('c', '')) { $redirect .= '&c=' . $category; } $result = array('goto' => $redirect); if (is_callable(array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save'))) { try { $values = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save', $values, $this); } catch (MaharaException $e) { $result['message'] = $e instanceof UserException ? $e->getMessage() : get_string('unrecoverableerror', 'error'); $form->set_error(null, $result['message']); $form->reply(PIEFORM_ERR, $result); } } $title = isset($values['title']) ? $values['title'] : ''; unset($values['title']); // A block may return a list of other blocks that need to be // redrawn after configuration of this block. $torender = !empty($values['_redrawblocks']) && $form->submitted_by_js() ? $values['_redrawblocks'] : array(); unset($values['_redrawblocks']); $this->set('configdata', $values); $this->set('title', $title); $this->commit(); try { $rendered = $this->render_editing(false, false, $form->submitted_by_js()); } catch (HTMLPurifier_Exception $e) { $message = get_string('blockconfigurationrenderingerror', 'view') . ' ' . $e->getMessage(); $form->reply(PIEFORM_ERR, array('message' => $message)); } $result = array('error' => false, 'message' => get_string('blockinstanceconfiguredsuccessfully', 'view'), 'data' => $rendered, 'blockid' => $this->get('id'), 'viewid' => $this->get('view'), 'goto' => $redirect); // Render all the other blocks in the torender list $result['otherblocks'] = array(); foreach ($torender as $blockid) { if ($blockid != $result['blockid']) { $otherblock = new BlockInstance($blockid); $result['otherblocks'][] = array('blockid' => $blockid, 'data' => $otherblock->render_editing(false, false, true)); } } $form->reply(PIEFORM_OK, $result); }
function editgoalsandskills_submit(Pieform $form, array $values) { global $SESSION, $artefact, $USER; require_once 'embeddedimage.php'; $newdescription = EmbeddedImage::prepare_embedded_images($values['description'], $values['artefacttype'], $USER->get('id')); db_begin(); $artefact->set('title', get_string($values['artefacttype'], 'artefact.resume')); $artefact->set('description', $newdescription); $artefact->commit(); // Attachments $old = $artefact->attachment_id_list(); $new = is_array($values['filebrowser']) ? $values['filebrowser'] : array(); // only allow the attaching of files that exist and are editable by user foreach ($new as $key => $fileid) { $file = artefact_instance_from_id($fileid); if (!$file instanceof ArtefactTypeFile || !$USER->can_publish_artefact($file)) { unset($new[$key]); } } if (!empty($new) || !empty($old)) { foreach ($old as $o) { if (!in_array($o, $new)) { try { $artefact->detach($o); } catch (ArtefactNotFoundException $e) { } } } foreach ($new as $n) { if (!in_array($n, $old)) { try { $artefact->attach($n); } catch (ArtefactNotFoundException $e) { } } } } db_commit(); $result = array('error' => false, 'message' => get_string('goalandskillsaved', 'artefact.resume'), 'goto' => get_config('wwwroot') . 'artefact/resume/goalsandskills.php'); if ($form->submitted_by_js()) { // Redirect back to the resume goals and skills page from within the iframe $SESSION->add_ok_msg($result['message']); $form->json_reply(PIEFORM_OK, $result, false); } $form->reply(PIEFORM_OK, $result); }
function delete_submit(Pieform $form, $values) { $blogpost = new ArtefactTypeBlogPost((int) $values['delete']); $blogpost->check_permission(); if ($blogpost->get('locked')) { $form->reply(PIEFORM_ERR, get_string('submittedforassessment', 'view')); } $blogpost->delete(); $form->reply(PIEFORM_OK, array('message' => get_string('blogpostdeleted', 'artefact.blog'), 'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blogpost->get('parent'), 'id' => $values['delete'])); }
function changeauth_submit(Pieform $form, $values) { global $users, $SESSION, $authinstances, $USER; $newauth = AuthFactory::create($values['authinstance']); $needspassword = method_exists($newauth, 'change_password'); $updated = 0; $needpassword = 0; db_begin(); $newauthinst = get_records_select_assoc('auth_instance', 'id = ?', array($values['authinstance'])); if ($USER->get('admin') || $USER->is_institutional_admin($newauthinst[$values['authinstance']]->institution)) { foreach ($users as $user) { if ($user->authinstance != $values['authinstance']) { // Authinstance can be changed by institutional admins if both the // old and new authinstances belong to the admin's institutions $authinst = get_field('auth_instance', 'institution', 'id', $user->authinstance); if ($USER->get('admin') || $USER->is_institutional_admin($authinst)) { // determine the current remoteusername $current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id); if (!$current_remotename) { $current_remotename = $user->username; } // remove row if new authinstance row already exists to avoid doubleups delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id); insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $current_remotename, 'localusr' => $user->id)); } if ($user->haspassword && !$needspassword) { $user->password = ''; } else { if ($needspassword && !$user->haspassword) { $needpassword++; } } $user->authinstance = $values['authinstance']; update_record('usr', $user, 'id'); $updated++; } } } db_commit(); if ($needpassword) { // Inform the user that they may need to reset passwords $SESSION->add_info_msg(get_string('bulkchangeauthmethodresetpassword', 'admin', $needpassword)); } $message = get_string('bulkchangeauthmethodsuccess', 'admin', $updated); $form->reply(PIEFORM_OK, array('message' => $message)); }
function siteoptions_fail(Pieform $form, $field) { $form->reply(PIEFORM_ERR, array('message' => get_string('setsiteoptionsfailed', 'admin', get_string($field, 'admin')), 'goto' => '/admin/site/options.php')); }
function objection_form_cancel_submit(Pieform $form) { global $view; $form->reply(PIEFORM_OK, array('goto' => '/view/view.php?id=' . $view->get('id'))); }
function add_feedback_form_cancel_submit(Pieform $form) { global $view; $form->reply(PIEFORM_CANCEL, array('location' => $view->get_url(true))); }
public static function instance_config_validate(Pieform $form, $values) { global $USER; if (!empty($values['images'])) { foreach ($values['images'] as $id) { $image = new ArtefactTypeImage($id); if (!$image instanceof ArtefactTypeImage || !$USER->can_view_artefact($image)) { $result['message'] = get_string('unrecoverableerror', 'error'); $form->set_error(null, $result['message']); $form->reply(PIEFORM_ERR, $result); } } } if (!empty($values['folder'])) { $folder = artefact_instance_from_id($values['folder']); if (!$folder instanceof ArtefactTypeFolder || !$USER->can_view_artefact($folder)) { $result['message'] = get_string('unrecoverableerror', 'error'); $form->set_error(null, $result['message']); $form->reply(PIEFORM_ERR, $result); } } }
function editpost_submit(Pieform $form, $values) { global $USER, $SESSION, $blogpost, $blog; db_begin(); $postobj = new ArtefactTypeBlogPost($blogpost, null); $postobj->set('title', $values['title']); $postobj->set('description', $values['description']); $postobj->set('tags', $values['tags']); $postobj->set('published', !$values['draft']); if (!$blogpost) { $postobj->set('parent', $blog); $postobj->set('owner', $USER->id); } $postobj->commit(); $blogpost = $postobj->get('id'); // Attachments $old = $postobj->attachment_id_list(); // $new = is_array($values['filebrowser']['selected']) ? $values['filebrowser']['selected'] : array(); $new = is_array($values['filebrowser']) ? $values['filebrowser'] : array(); if (!empty($new) || !empty($old)) { foreach ($old as $o) { if (!in_array($o, $new)) { $postobj->detach($o); } } foreach ($new as $n) { if (!in_array($n, $old)) { $postobj->attach($n); } } } db_commit(); $result = array('error' => false, 'message' => get_string('blogpostsaved', 'artefact.blog'), 'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog); if ($form->submitted_by_js()) { // Redirect back to the blog page from within the iframe $SESSION->add_ok_msg($result['message']); $form->json_reply(PIEFORM_OK, $result, false); } $form->reply(PIEFORM_OK, $result); }
function editnote_submit(Pieform $form, array $values) { global $SESSION, $artefact, $goto; require_once 'embeddedimage.php'; db_begin(); $artefact->set('title', $values['title']); $newdescription = EmbeddedImage::prepare_embedded_images($values['description'], 'textbox', $artefact->get('id'), $artefact->get('group')); $artefact->set('description', $newdescription); $artefact->set('tags', $values['tags']); $artefact->set('allowcomments', (int) $values['allowcomments']); if (isset($values['perms'])) { $artefact->set('rolepermissions', $values['perms']); $artefact->set('dirty', true); } if (get_config('licensemetadata')) { $artefact->set('license', $values['license']); $artefact->set('licensor', $values['licensor']); $artefact->set('licensorurl', $values['licensorurl']); } $artefact->commit(); // Attachments $old = $artefact->attachment_id_list(); $new = is_array($values['filebrowser']) ? $values['filebrowser'] : array(); if (!empty($new) || !empty($old)) { foreach ($old as $o) { if (!in_array($o, $new)) { try { $artefact->detach($o); } catch (ArtefactNotFoundException $e) { } } } foreach ($new as $n) { if (!in_array($n, $old)) { try { $artefact->attach($n); } catch (ArtefactNotFoundException $e) { } } } } // need to update the block_instances where this artefact is used - so they have // the correct configuration artefactids if ($blocks = get_column('view_artefact', 'block', 'artefact', $artefact->get('id'))) { require_once get_config('docroot') . 'blocktype/lib.php'; foreach ($blocks as $block) { $bi = new BlockInstance($block); $configdata = $bi->get('configdata'); $configdata['artefactids'] = $new; $bi->set('configdata', $configdata); $bi->commit(); } } db_commit(); $result = array('error' => false, 'message' => get_string('noteupdated', 'artefact.internal'), 'goto' => $goto); if ($form->submitted_by_js()) { // Redirect back to the note page from within the iframe $SESSION->add_ok_msg($result['message']); $form->json_reply(PIEFORM_OK, $result, false); } $form->reply(PIEFORM_OK, $result); }
function editsitepage_submit(Pieform $form, $values) { global $USER; $data = new StdClass(); $data->name = $values['pagename']; if (empty($values['pageusedefault'])) { $data->content = $values['pagetext']; } $data->mtime = db_format_timestamp(time()); $data->mauthor = $USER->get('id'); $data->institution = $values['pageinstitution']; // update the institution config if needed if (isset($values['pageusedefault'])) { $configdata = new StdClass(); $configdata->institution = $data->institution; $configdata->field = 'sitepages_' . $data->name; $whereobj = clone $configdata; $configdata->value = !empty($values['pageusedefault']) ? 'mahara' : $data->institution; ensure_record_exists('institution_config', $whereobj, $configdata); } if (get_record('site_content', 'name', $data->name, 'institution', $data->institution)) { try { update_record('site_content', $data, array('name', 'institution')); } catch (SQLException $e) { $form->reply(PIEFORM_ERR, get_string('savefailed', 'admin')); } } else { // local site page doesn't exist for this institution so we shall add it $data->ctime = db_format_timestamp(time()); try { insert_record('site_content', $data); } catch (SQLException $e) { $form->reply(PIEFORM_ERR, get_string('savefailed', 'admin')); } } $form->reply(PIEFORM_OK, get_string('pagesaved', 'admin')); }
function editurl_submit(Pieform $form, $values) { global $tokens, $view, $collection, $SESSION; $viewid = $view->get('id'); if ($collection) { $viewids = get_column('collection_view', 'view', 'collection', $collection->get('id')); } else { $viewids = array($viewid); } $access = (object) array('token' => $values['token'], 'startdate' => db_format_timestamp($values['startdate']), 'stopdate' => db_format_timestamp($values['stopdate'])); if (!$view->get('allowcomments')) { if ($access->allowcomments = (int) $values['allowcomments']) { $access->approvecomments = (int) $values['approvecomments']; } } $whereobject = (object) array('token' => $values['token']); if (isset($tokens[$values['token']])) { foreach ($viewids as $id) { $access->view = $id; $whereobject->view = $id; update_record('view_access', $access, $whereobject); } $message = get_string('secreturlupdated', 'view'); $form->reply(PIEFORM_OK, $message); } $form->reply(PIEFORM_ERR, get_string('formerror')); }
function add_annotation_feedback_form_submit(Pieform $form, $values) { global $USER; $data = (object) array('title' => get_string('Annotation', 'artefact.annotation'), 'description' => $values['message'], 'onannotation' => $values['annotationid']); // hidden fields. $artefactid = $values['artefactid']; $viewid = $values['viewid']; $blockid = $values['blockid']; if ($artefactid) { $artefact = artefact_instance_from_id($artefactid); $data->artefact = $artefactid; $data->owner = $artefact->get('owner'); $data->group = $artefact->get('group'); $data->institution = $artefact->get('institution'); } else { if ($viewid) { $view = new View($viewid); $data->view = $viewid; $data->owner = $view->get('owner'); $data->group = $view->get('group'); $data->institution = $view->get('institution'); } } if ($author = $USER->get('id')) { $anonymous = false; $data->author = $author; } else { $anonymous = true; $data->authorname = $values['authorname']; } if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) { $data->private = 1; $data->requestpublic = 'author'; $moderated = true; } else { $data->private = (int) (!$values['ispublic']); $moderated = false; } $private = $data->private; $annotationfeedback = new ArtefactTypeAnnotationfeedback(0, $data); $annotation = new ArtefactTypeAnnotation($values['annotationid']); db_begin(); $annotationfeedback->commit(); $url = $annotation->get_view_url($view->get('id'), true, false); $goto = get_config('wwwroot') . $url; if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) { $arg = $author ? display_name($USER, null, true) : $data->authorname; $moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.annotation', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.annotation', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Annotation', 'section' => 'artefact.annotation')), 'users' => array($data->owner), 'url' => $url); } require_once 'activity.php'; $data = (object) array('annotationfeedbackid' => $annotationfeedback->get('id'), 'annotationid' => $values['annotationid'], 'viewid' => $viewid, 'artefactid' => $artefactid); activity_occurred('annotationfeedback', $data, 'artefact', 'annotation'); if (isset($moderatemsg)) { activity_occurred('maharamessage', $moderatemsg); } db_commit(); if (param_exists('offset')) { $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options(); $options->showcomment = 'last'; $options->artefact = $artefactid; $options->view = $viewid; $options->annotation = $values['annotationid']; $options->block = $blockid; $newlist = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options); } else { $newlist = null; } // If you're anonymous and your message is moderated or private, then you won't // be able to tell what happened to it. So we'll provide some more explanation in // the feedback message. if ($anonymous && $moderated) { $message = get_string('annotationfeedbacksubmittedmoderatedanon', 'artefact.annotation'); } else { if ($anonymous && $private) { $message = get_string('annotationfeedbacksubmittedprivateanon', 'artefact.annotation'); } else { $message = get_string('annotationfeedbacksubmitted', 'artefact.annotation'); } } $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist)); }
public static function wallpost_submit(Pieform $form, $values) { global $USER; $record = (object) array('instance' => $values['instance'], 'from' => $USER->get('id'), 'replyto' => $values['replyto'] ? $values['replyto'] : null, 'private' => (int) (bool) $values['private'], 'postdate' => db_format_timestamp(time()), 'text' => $values['text']); insert_record('blocktype_wall_post', $record); $instance = new BlockInstance($values['instance']); $owner = $instance->get_view()->get('owner'); $smarty = smarty_core(); $smarty->assign('instanceid', $instance->get('id')); $smarty->assign('ownwall', !empty($USER) && $USER->get('id') == $owner); if ($posts = self::fetch_posts($instance)) { $smarty->assign('wallposts', $posts); } $renderedposts = $smarty->fetch('blocktype:wall:inlineposts.tpl'); $form->reply(PIEFORM_OK, array('message' => get_string('addpostsuccess', 'blocktype.wall'), 'posts' => $renderedposts, 'block' => $values['instance'])); }
function adduser_validate(Pieform $form, $values) { global $USER, $TRANSPORTER; $authobj = AuthFactory::create($values['authinstance']); $institution = $authobj->institution; // Institutional admins can only set their own institutions' authinstances if (!$USER->get('admin') && !$USER->is_institutional_admin($authobj->institution)) { $form->set_error('authinstance', get_string('notadminforinstitution', 'admin')); return; } $institution = new Institution($authobj->institution); // Don't exceed max user accounts for the institution if ($institution->isFull()) { $institution->send_admin_institution_is_full_message(); $form->set_error('authinstance', get_string('institutionmaxusersexceeded', 'admin')); return; } $username = $values['username']; $firstname = sanitize_firstname($values['firstname']); $lastname = sanitize_lastname($values['lastname']); $email = sanitize_email($values['email']); $password = $values['password']; if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) { $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))); } } if (method_exists($authobj, 'is_username_valid_admin')) { if (!$authobj->is_username_valid_admin($username)) { $form->set_error('username', get_string('usernameinvalidadminform', 'auth.internal')); } } else { if (method_exists($authobj, 'is_username_valid')) { if (!$authobj->is_username_valid($username)) { $form->set_error('username', get_string('usernameinvalidform', 'auth.internal')); } } } if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', array(strtolower($username)))) { $form->set_error('username', get_string('usernamealreadytaken', 'auth.internal')); } if (method_exists($authobj, 'is_password_valid') && !$authobj->is_password_valid($password)) { $form->set_error('password', get_string('passwordinvalidform', 'auth.' . $authobj->type)); } if (isset($_POST['createmethod']) && $_POST['createmethod'] == 'leap2a') { $form->set_error('firstname', null); $form->set_error('lastname', null); $form->set_error('email', null); if (!$values['leap2afile'] && ($_FILES['leap2afile']['error'] == UPLOAD_ERR_INI_SIZE || $_FILES['leap2afile']['error'] == UPLOAD_ERR_FORM_SIZE)) { $form->reply(PIEFORM_ERR, array('message' => get_string('uploadedfiletoobig'), 'goto' => '/admin/users/add.php')); $form->set_error('leap2afile', get_string('uploadedfiletoobig')); return; } else { if (!$values['leap2afile']) { $form->set_error('leap2afile', $form->i18n('rule', 'required', 'required')); return; } } if ($values['leap2afile']['type'] == 'application/octet-stream') { require_once 'file.php'; $mimetype = file_mime_type($values['leap2afile']['tmp_name']); } else { $mimetype = trim($values['leap2afile']['type'], '"'); } $date = time(); $niceuser = preg_replace('/[^a-zA-Z0-9_-]/', '-', $values['username']); safe_require('import', 'leap'); $fakeimportrecord = (object) array('data' => array('importfile' => $values['leap2afile']['tmp_name'], 'importfilename' => $values['leap2afile']['name'], 'importid' => $niceuser . '-' . $date, 'mimetype' => $mimetype)); $TRANSPORTER = new LocalImporterTransport($fakeimportrecord); try { $TRANSPORTER->extract_file(); PluginImportLeap::validate_transported_data($TRANSPORTER); } catch (Exception $e) { $form->set_error('leap2afile', $e->getMessage()); } } else { if (!$form->get_error('firstname') && empty($firstname)) { $form->set_error('firstname', $form->i18n('rule', 'required', 'required')); } if (!$form->get_error('lastname') && empty($lastname)) { $form->set_error('lastname', $form->i18n('rule', 'required', 'required')); } if (!$form->get_error('email')) { if (!$form->get_error('email') && empty($email)) { $form->set_error('email', get_string('invalidemailaddress', 'artefact.internal')); } if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) { $form->set_error('email', get_string('emailalreadytaken', 'auth.internal')); } } } }
/** * This function processes the form for the composite * @throws Exception */ public static function process_compositeform(Pieform $form, $values) { global $USER; $error = self::ensure_composite_value($values, $values['compositetype'], $USER->get('id')); if (is_array($error)) { $form->reply(PIEFORM_ERR, array('message' => $error['message'])); if (isset($error['goto'])) { redirect($error['goto']); } } }
function editpost_submit(Pieform $form, $values) { global $USER, $SESSION, $blogpost, $blog; require_once 'embeddedimage.php'; db_begin(); $postobj = new ArtefactTypeBlogPost($blogpost, null); $postobj->set('title', $values['title']); $postobj->set('description', $values['description']); $postobj->set('tags', $values['tags']); if (get_config('licensemetadata')) { $postobj->set('license', $values['license']); $postobj->set('licensor', $values['licensor']); $postobj->set('licensorurl', $values['licensorurl']); } $postobj->set('published', !$values['draft']); $postobj->set('allowcomments', (int) $values['allowcomments']); if (!$blogpost) { $postobj->set('parent', $blog); $blogobj = new ArtefactTypeBlog($blog); if ($blogobj->get('institution')) { $postobj->set('institution', $blogobj->get('institution')); } else { if ($blogobj->get('group')) { $postobj->set('group', $blogobj->get('group')); } else { $postobj->set('owner', $USER->id); } } } $postobj->commit(); $blogpost = $postobj->get('id'); // Need to wait until post is saved in case we are a new blogpost before we can sort out embedded images as we need an id $postobj->set('description', EmbeddedImage::prepare_embedded_images($values['description'], 'blogpost', $postobj->get('id'))); // Attachments $old = $postobj->attachment_id_list(); // $new = is_array($values['filebrowser']['selected']) ? $values['filebrowser']['selected'] : array(); $new = is_array($values['filebrowser']) ? $values['filebrowser'] : array(); // only allow the attaching of files that exist and are editable by user foreach ($new as $key => $fileid) { $file = artefact_instance_from_id($fileid); if (!$file instanceof ArtefactTypeFile || !$USER->can_publish_artefact($file)) { unset($new[$key]); } } if (!empty($new) || !empty($old)) { foreach ($old as $o) { if (!in_array($o, $new)) { try { $postobj->detach($o); } catch (ArtefactNotFoundException $e) { } } } foreach ($new as $n) { if (!in_array($n, $old)) { try { $postobj->attach($n); } catch (ArtefactNotFoundException $e) { } } } } db_commit(); $result = array('error' => false, 'message' => get_string('blogpostsaved', 'artefact.blog'), 'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog); if ($form->submitted_by_js()) { // Redirect back to the blog page from within the iframe $SESSION->add_ok_msg($result['message']); $form->json_reply(PIEFORM_OK, $result, false); } $form->reply(PIEFORM_OK, $result); }
function notrude_form_submit(Pieform $form, $values) { global $view, $artefact, $USER; require_once 'activity.php'; db_begin(); $objection = new stdClass(); if ($artefact) { $objection->objecttype = 'artefact'; $objection->objectid = $artefact->get('id'); } else { $objection->objecttype = 'view'; $objection->objectid = $view->get('id'); } $objection->resolvedby = $USER->get('id'); $objection->resolvedtime = db_format_timestamp(time()); update_record('objectionable', $objection, array('id' => $values['objection'])); // Send notification to other admins. $reportername = display_default_name($USER); if ($artefact) { $goto = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefact->get('id') . '&view=' . $view->get('id'); } else { $goto = $view->get_url(); } $data = (object) array('view' => $view->get('id'), 'reporter' => $USER->get('id'), 'subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'viewunobjectionablesubject', 'section' => 'view', 'args' => array($view->get('title'), $reportername)), 'message' => (object) array('key' => 'viewunobjectionablebody', 'section' => 'view', 'args' => array($reportername, $view->get('title'), $view->formatted_owner())))); activity_occurred('objectionable', $data); db_commit(); $form->reply(PIEFORM_OK, array('message' => get_string('messagesent'), 'goto' => $goto)); }
function networkingform_fail(Pieform $form) { $form->reply(PIEFORM_ERR, array('message' => get_string('enablenetworkingfailed', 'admin'), 'goto' => '/admin/site/networking.php')); }
public function instance_config_store(Pieform $form, $values) { global $SESSION; // Destroy form values we don't care about unset($values['sesskey']); unset($values['blockinstance']); unset($values['action_configureblockinstance_id_' . $this->get('id')]); unset($values['blockconfig']); unset($values['id']); unset($values['change']); unset($values['new']); if (is_callable(array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save'))) { $values = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save', $values); } $title = isset($values['title']) ? $values['title'] : ''; unset($values['title']); $this->set('configdata', $values); $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); if (!$title && $title !== '0' && method_exists($blocktypeclass, 'get_instance_title')) { // Get the default title for the block if one isn't set $title = call_static_method($blocktypeclass, 'get_instance_title', $this); } $this->set('title', $title); try { $rendered = $this->render_editing(false, false, $form->submitted_by_js()); } catch (HTMLPurifier_Exception $e) { $message = get_string('blockconfigurationrenderingerror', 'view') . ' ' . $e->getMessage(); $form->reply(PIEFORM_ERR, array('message' => $message)); } $this->commit(); $result = array('error' => false, 'message' => get_string('blockinstanceconfiguredsuccessfully', 'view'), 'data' => $rendered, 'blockid' => $this->get('id'), 'viewid' => $this->get('view')); $redirect = '/view/blocks.php?id=' . $this->get('view'); if (param_boolean('new', false)) { $redirect .= '&new=1'; } if ($category = param_alpha('c', '')) { $redirect .= '&c=' . $category; } $result['goto'] = $redirect; $form->reply(PIEFORM_OK, $result); }