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);
}
示例#2
0
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);
}
示例#3
0
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);
}
示例#4
0
 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);
 }
示例#5
0
文件: post.php 项目: Br3nda/mahara
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);
}
示例#6
0
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);
}
示例#7
0
 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);
 }