Exemple #1
0
function compositeformedit_submit(Pieform $form, $values)
{
    global $SESSION;
    $tabs = PluginArtefactResume::composite_tabs();
    $goto = get_config('wwwroot') . 'artefact/resume/';
    if (isset($tabs[$values['compositetype']])) {
        $goto .= $tabs[$values['compositetype']] . '.php';
    } else {
        $goto .= 'index.php';
    }
    try {
        call_static_method(generate_artefact_class_name($values['compositetype']), 'process_compositeform', $form, $values);
    } catch (Exception $e) {
        $SESSION->add_error_msg(get_string('compositesavefailed', 'artefact.resume'));
        redirect($goto);
    }
    $result = array('error' => false, 'message' => get_string('compositesaved', 'artefact.resume'), 'goto' => $goto);
    if ($form->submitted_by_js()) {
        // Redirect back to the resume composite 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 getRecordDataById($type, $id)
 {
     global $USER;
     $sql = 'SELECT  a.id, a.artefacttype, a.parent, a.owner, a.title, a.description, a.institution, a.group, a.author,
     p.artefacttype AS parent_artefacttype, p.title AS parent_title, p.description  AS parent_description, a.license,
     afi.width, afi.height, a.note
     FROM {artefact} a
     LEFT OUTER JOIN {artefact} p ON p.id = a.parent
     LEFT OUTER JOIN {artefact_file_image} afi ON afi.artefact = a.id
     WHERE a.id = ?';
     $record = get_record_sql($sql, array($id));
     if (!$record) {
         return false;
     }
     $record->title = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->title));
     $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description));
     // If user is owner
     if ($USER->get('id') == $record->owner) {
         switch ($record->artefacttype) {
             case 'image':
             case 'video':
             case 'audio':
             case 'file':
                 $record->link = 'artefact/file';
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link .= '/index.php?folder=' . $record->parent;
                 }
                 break;
             case 'blogpost':
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link = 'artefact/blog/view/index.php?id=' . $record->parent;
                 }
                 break;
             case 'blog':
                 $record->link = 'artefact/blog/view/index.php';
                 if ($USER->get_account_preference('multipleblogs')) {
                     $record->link .= '?id=' . $record->id;
                 }
                 break;
             case 'coverletter':
             case 'personalinformation':
                 $record->link = 'artefact/resume/index.php';
                 break;
             case 'educationhistory':
             case 'employmenthistory':
                 $record->link = 'artefact/resume/employment.php';
                 break;
             case 'book':
             case 'certification':
             case 'membership':
                 $record->link = 'artefact/resume/achievements.php';
                 break;
             case 'academicgoal':
             case 'careergoal':
             case 'personalgoal':
             case 'personalinformation':
             case 'academicskill':
             case 'personalskill':
             case 'workskill':
                 $record->link = 'artefact/resume/goalsandskills.php';
                 break;
             case 'interest':
                 $record->link = 'artefact/resume/interests.php';
                 break;
             case 'plan':
                 $record->link = 'artefact/plans/plan.php?id=' . $record->id;
                 break;
             case 'task':
                 if (isset($record->parent) && intval($record->parent) > 0) {
                     $record->link = 'artefact/plans/plan.php?id=' . $record->parent;
                 }
                 break;
             case 'socialprofile':
                 safe_require('artefact', 'internal');
                 $record->note = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->note));
                 $socialprofile = new ArtefactTypeSocialprofile($record->id);
                 $icons = $socialprofile->get_profile_icons(array($record));
                 if (!empty($icons)) {
                     $record->link = $icons[0]->link;
                     $record->icon = $icons[0]->icon;
                 }
                 break;
         }
     }
     require_once get_config('docroot') . 'artefact/resume/lib.php';
     if (PluginArtefactResume::is_active()) {
         // If the artefacttype is one of the résumé ones we need to fetch the related item info
         $resumetypes = PluginArtefactResume::composite_tabs();
         if (array_key_exists($record->artefacttype, $resumetypes)) {
             try {
                 $query = "SELECT * FROM {artefact_resume_" . $record->artefacttype . "} WHERE artefact = ?";
                 $results = get_records_sql_assoc($query, array($record->id));
             } catch (SQLException $e) {
                 // Table doesn't exist
                 $results = array();
             }
             $record->resumeitems = $results;
         }
     }
     // VIEWS get all the views the artefact is included into.
     // artefact parents are folder, blog, plan, cpd
     $sql = 'SELECT COALESCE(v.id, vp.id) AS id, COALESCE(v.title, vp.title) AS title
     FROM {artefact} a
     LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
     LEFT OUTER JOIN {view} v ON v.id = va.view
     LEFT OUTER JOIN {artefact} parent ON parent.id = a.parent
     LEFT OUTER JOIN {view_artefact} vap ON vap.artefact = parent.id
     LEFT OUTER JOIN {view} vp ON vp.id = vap.view
     WHERE a.id = ?';
     $views = get_records_sql_array($sql, array($id));
     if ($views) {
         $record_views = array();
         foreach ($views as $view) {
             if (isset($view->id)) {
                 $record_views[$view->id] = $view->title;
             }
         }
         $record_views = self::views_by_artefact_acl_filter($record_views);
         $record->views = $record_views;
     }
     //  Tags
     $tags = get_records_array('artefact_tag', 'artefact', $id);
     if ($tags != false) {
         foreach ($tags as $tag) {
             $record->tags[] = $tag->tag;
         }
     } else {
         $record->tags = null;
     }
     //  Created by
     if (intval($record->author) > 0) {
         $record->createdby = get_record('usr', 'id', $record->author);
         $record->createdbyname = display_name($record->createdby);
     }
     //  Thumb
     if ($record->artefacttype == 'image' || $record->artefacttype == 'profileicon') {
         if (isset($record->width) && isset($record->height) && intval($record->width) > 0 && intval($record->height) > 0) {
             if ($record->width > $record->height) {
                 $size = '80x' . intval($record->height * 80 / $record->width);
             } else {
                 $size = intval($record->width * 80 / $record->height) . 'x80';
             }
         }
         $record->thumb = ArtefactTypeImage::get_icon(array('id' => $id, 'size' => $size));
     }
     return $record;
 }
function compositeformedit_submit(Pieform $form, $values)
{
    global $SESSION;
    $tabs = PluginArtefactResume::composite_tabs();
    $goto = get_config('wwwroot') . '/artefact/resume/';
    if (isset($tabs[$values['compositetype']])) {
        $goto .= $tabs[$values['compositetype']] . '.php';
    }
    try {
        call_static_method(generate_artefact_class_name($values['compositetype']), 'process_compositeform', $form, $values);
    } catch (Exception $e) {
        $SESSION->add_error_msg(get_string('compositesavefailed', 'artefact.resume'));
        redirect($goto);
    }
    $SESSION->add_ok_msg(get_string('compositesaved', 'artefact.resume'));
    redirect($goto);
}
 *
 */
define('INTERNAL', true);
define('MENUITEM', 'profile/myresume');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'resume');
require_once dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once 'pieforms/pieform.php';
require_once 'pieforms/pieform/elements/calendar.php';
require_once get_config('docroot') . 'artefact/lib.php';
define('TITLE', get_string('myresume', 'artefact.resume'));
$id = param_integer('id');
$artefact = param_integer('artefact');
$a = artefact_instance_from_id($artefact);
$type = $a->get('artefacttype');
$tabs = PluginArtefactResume::composite_tabs();
define('RESUME_SUBPAGE', $tabs[$type]);
if ($a->get('owner') != $USER->get('id')) {
    throw new AccessDeniedException(get_string('notartefactowner', 'error'));
}
$elements = call_static_method(generate_artefact_class_name($type), 'get_addform_elements');
$elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('save'), get_string('cancel')), 'goto' => get_config('wwwroot') . '/artefact/resume/' . $tabs[$type] . '.php');
$elements['compositetype'] = array('type' => 'hidden', 'value' => $type);
$cform = array('name' => $type, 'plugintype' => 'artefact', 'pluginname' => 'resume', 'elements' => $elements, 'successcallback' => 'compositeformedit_submit');
$a->populate_form($cform, $id, $type);
$compositeform = pieform($cform);
$smarty = smarty();
$smarty->assign('compositeform', $compositeform);
$smarty->assign('composite', $type);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());