function personalinformation_submit(Pieform $form, $values) { global $personalinformation, $USER; $userid = $USER->get('id'); $errors = array(); try { if (empty($personalinformation)) { $personalinformation = new ArtefactTypePersonalinformation(0, array('owner' => $userid, 'title' => get_string('personalinformation', 'artefact.resume'))); } foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) { $personalinformation->set_composite($field, $values[$field]); } $personalinformation->commit(); } catch (Exception $e) { $errors['personalinformation'] = true; } if (empty($errors)) { $form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume')); } else { $message = ''; foreach (array_keys($errors) as $key) { $message .= get_string('resumesavefailed', 'artefact.resume') . "\n"; } $form->json_reply(PIEFORM_ERR, $message); } }
function interests_submit(Pieform $form, $values) { global $coverletter, $personalinformation, $interest, $USER; $userid = $USER->get('id'); $errors = array(); try { if (empty($interest) && !empty($values['interest'])) { $interest = new ArtefactTypeInterest(0, array('owner' => $userid, 'description' => $values['interest'])); $interest->commit(); } else { if (!empty($interest) && !empty($values['interest'])) { $interest->set('description', $values['interest']); $interest->commit(); } else { if (!empty($interest) && empty($values['interest'])) { $interest->delete(); } } } } catch (Exception $e) { $errors['interest'] = true; } if (empty($errors)) { $form->json_reply(PIEFORM_OK, get_string('resumesaved', 'artefact.resume')); } else { $message = ''; foreach (array_keys($errors) as $key) { $message .= get_string('resumesavefailed', 'artefact.resume') . "\n"; } $form->json_reply(PIEFORM_ERR, $message); } }
function activityprefs_submit(Pieform $form, $values) { global $activitytypes, $admintypes, $USER; $userid = $USER->get('id'); foreach ($activitytypes as $type) { if ($values['activity_' . $type->id] == 'none') { $USER->set_activity_preference($type->id, null); } else { $USER->set_activity_preference($type->id, $values['activity_' . $type->id]); } } $form->json_reply(PIEFORM_OK, get_string('prefssaved', 'account')); }
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 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 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 accountprefs_submit(Pieform $form, $values) { global $USER; $authobj = AuthFactory::create($USER->authinstance); db_begin(); if (isset($values['password1']) && $values['password1'] !== '') { global $authclass; $password = $authobj->change_password($USER, $values['password1']); $USER->password = $password; $USER->passwordchange = 0; $USER->commit(); } // use this as looping through values is not safe. $expectedprefs = expected_account_preferences(); foreach (array_keys($expectedprefs) as $pref) { if (isset($values[$pref])) { $USER->set_account_preference($pref, $values[$pref]); } } $returndata = array(); if (isset($values['username']) && $values['username'] != $USER->get('username')) { $USER->username = $values['username']; $USER->commit(); $returndata['username'] = $values['username']; } db_commit(); $returndata['message'] = get_string('prefssaved', 'account'); $form->json_reply(PIEFORM_OK, $returndata); }
function activityprefs_submit(Pieform $form, $values) { global $USER; save_notification_settings($values, $USER); $form->json_reply(PIEFORM_OK, get_string('prefssaved', 'account')); }
function goalandskillform_submit(Pieform $form, $values) { foreach ($values as $key => $value) { if (!in_array($key, ArtefactTypeResumeGoalAndSkill::get_goalandskill_artefact_types())) { continue; } try { $a = artefact_instance_from_type($key); $a->set('description', $value); } catch (Exception $e) { global $USER; $classname = generate_artefact_class_name($key); $a = new $classname(0, array('owner' => $USER->get('id'), 'title' => get_string($key), 'description' => $value)); } $a->commit(); } $form->json_reply(PIEFORM_OK, get_string('goalandskillsaved', 'artefact.resume')); }
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); }
public static function config_success(Pieform $form, $values) { $result = array(); $form->json_reply(PIEFORM_OK, $result, false); }
function upload_submit(Pieform $form, $values) { global $USER, $filesize; safe_require('artefact', 'file'); try { $USER->quota_add($filesize); } catch (QuotaException $qe) { $form->json_reply(PIEFORM_ERR, array('message' => get_string('profileiconuploadexceedsquota', 'artefact.file', get_config('wwwroot')))); } // Entry in artefact table $data = new stdClass(); $data->owner = $USER->id; $data->parent = ArtefactTypeFolder::get_folder_id(get_string('imagesdir', 'artefact.file'), get_string('imagesdirdesc', 'artefact.file'), null, true, $USER->id); $data->title = $values['title'] ? $values['title'] : $values['file']['name']; $data->title = ArtefactTypeFileBase::get_new_file_title($data->title, (int) $data->parent, $USER->id); // unique title $data->note = $values['file']['name']; $data->size = $filesize; $imageinfo = getimagesize($values['file']['tmp_name']); $data->width = $imageinfo[0]; $data->height = $imageinfo[1]; $data->filetype = $imageinfo['mime']; $data->description = get_string('uploadedprofileicon', 'artefact.file'); $artefact = new ArtefactTypeProfileIcon(0, $data); if (preg_match("/\\.([^\\.]+)\$/", $values['file']['name'], $saved)) { $artefact->set('oldextension', $saved[1]); } $artefact->commit(); $id = $artefact->get('id'); // Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . $id % 256 . '/'; check_dir_exists($directory); move_uploaded_file($values['file']['tmp_name'], $directory . $id); $USER->commit(); $form->json_reply(PIEFORM_OK, get_string('profileiconaddedtoimagesfolder', 'artefact.file', get_string('imagesdir', 'artefact.file'))); }
function pluginconfig_submit(Pieform $form, $values) { $success = false; global $plugintype, $pluginname, $classname; try { call_static_method($classname, 'save_config_options', $values); $success = true; } catch (Exception $e) { $success = false; } if ($success) { $form->json_reply(PIEFORM_OK, get_string('settingssaved')); } else { $form->json_reply(PIEFORM_ERR, array('message' => get_string('settingssavefailed'))); } }
function upload_submit(Pieform $form, $values) { global $USER, $filesize; // If there are no icons, we can set this one that is being uploaded to be // the default for the user $setasdefault = false; if (0 == get_field('artefact', 'COUNT(*)', 'artefacttype', 'profileicon', 'owner', $USER->id)) { $setasdefault = true; } try { $USER->quota_add($filesize); } catch (QuotaException $qe) { $form->json_reply(PIEFORM_ERR, array('message' => get_string('profileiconuploadexceedsquota', 'artefact.file', get_config('wwwroot')))); } // Entry in artefact table $data = (object) array('owner' => $USER->id, 'title' => $values['title'] ? $values['title'] : $values['file']['name'], 'note' => $values['file']['name'], 'size' => $filesize); $imageinfo = getimagesize($values['file']['tmp_name']); $data->width = $imageinfo[0]; $data->height = $imageinfo[1]; $data->filetype = $imageinfo['mime']; $artefact = new ArtefactTypeProfileIcon(0, $data); if (preg_match("/\\.([^\\.]+)\$/", $values['file']['name'], $saved)) { $artefact->set('oldextension', $saved[1]); } $artefact->commit(); $id = $artefact->get('id'); // Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . $id % 256 . '/'; check_dir_exists($directory); move_uploaded_file($values['file']['tmp_name'], $directory . $id); if ($setasdefault) { $USER->profileicon = $id; } $USER->commit(); $form->json_reply(PIEFORM_OK, get_string('uploadedprofileiconsuccessfully', 'artefact.file')); }
function accountprefs_submit(Pieform $form, $values) { global $USER; $authobj = AuthFactory::create($USER->authinstance); db_begin(); if (isset($values['password1']) && $values['password1'] !== '') { global $authclass; $password = $authobj->change_password($USER, $values['password1']); $USER->password = $password; $USER->passwordchange = 0; $USER->commit(); } // use this as looping through values is not safe. $expectedprefs = expected_account_preferences(); if ($values['maildisabled'] == 0 && get_account_preference($USER->get('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->get('email'); $u->id = $USER->get('id'); update_bounce_count($u, true); update_send_count($u, true); } foreach (array_keys($expectedprefs) as $pref) { if (isset($values[$pref])) { $USER->set_account_preference($pref, $values[$pref]); } } $returndata = array(); if (isset($values['username']) && $values['username'] != $USER->get('username')) { $USER->username = $values['username']; $USER->commit(); $returndata['username'] = $values['username']; } db_commit(); $returndata['message'] = get_string('prefssaved', 'account'); $form->json_reply(PIEFORM_OK, $returndata); }