// Check all variables.
if ($chapterid) {
    // Single chapter printing - only visible!
    $chapter = $DB->get_record('giportfolio_chapters', array('id' => $chapterid, 'giportfolioid' => $giportfolio->id), '*', MUST_EXIST);
} else {
    // Complete giportfolio.
    $chapter = false;
}
$PAGE->set_url('/mod/giportfolio/pdfgiportfolio.php', array('id' => $id, 'chapterid' => $chapterid));
unset($id);
unset($chapterid);
// Security checks END.
// Read chapters.
$chapters = giportfolio_preload_chapters($giportfolio);
// SYNERGY - add fake user chapters.
$additionalchapters = giportfolio_preload_userchapters($giportfolio, $userid = null);
if ($additionalchapters) {
    $chapters = $chapters + $additionalchapters;
}
// SYNERGY.
$strgiportfolios = get_string('modulenameplural', 'mod_giportfolio');
$strgiportfolio = get_string('modulename', 'mod_giportfolio');
$strtop = get_string('top', 'mod_giportfolio');
class PORTFOLIOPDF extends TCPDF
{
    // Page header.
    public function Header()
    {
        $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
        $this->Line(10, 7, 200, 7, $style);
        // Set font.
Ejemplo n.º 2
0
// Edit mode.
// Security checks START - teachers edit; students view.
if ($id) {
    $cm = get_coursemodule_from_id('giportfolio', $id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $giportfolio = $DB->get_record('giportfolio', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
    $giportfolio = $DB->get_record('giportfolio', array('id' => $bid), '*', MUST_EXIST);
    $cm = get_coursemodule_from_instance('giportfolio', $giportfolio->id, 0, false, MUST_EXIST);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $id = $cm->id;
}
require_course_login($course, true, $cm);
$chapters = giportfolio_preload_chapters($giportfolio);
// SYNERGY - add fake user chapters.
$additionalchapters = giportfolio_preload_userchapters($giportfolio, $USER->id);
if ($additionalchapters) {
    $chapters = $chapters + $additionalchapters;
}
// SYNERGY.
$context = context_module::instance($cm->id);
require_capability('mod/giportfolio:view', $context);
$allowedit = has_capability('mod/giportfolio:edit', $context);
$allowcontribute = has_capability('mod/giportfolio:submitportfolio', $context);
$allowreport = has_capability('report/outline:view', $context->get_course_context());
if ($allowedit) {
    if ($edit != -1 and confirm_sesskey()) {
        $USER->editing = $edit;
    } else {
        if (isset($USER->editing)) {
            $edit = $USER->editing;
                if ($found and $ch->subchapter) {
                    // Here I should delete contributions first.
                    giportfolio_delete_user_contributions($ch->id, $USER->id, $giportfolio->id);
                    $DB->delete_records('giportfolio_userchapters', array('id' => $ch->id, 'iduser' => $USER->id));
                } else {
                    if ($found) {
                        break;
                    }
                }
            }
        }
    }
    // Here I should delete contributions first.
    giportfolio_delete_user_contributions($chapter->id, $USER->id, $giportfolio->id);
    $DB->delete_records('giportfolio_userchapters', array('id' => $chapter->id, 'iduser' => $USER->id));
    giportfolio_preload_userchapters($giportfolio, $userid = null);
    // Fix structure.
    redirect('viewgiportfolio.php?id=' . $cm->id . '&useredit=1');
}
echo $OUTPUT->header();
// The operation has not been confirmed yet so ask the user to do so.
if ($chapter->subchapter) {
    $strconfirm = get_string('confchapterdelete', 'mod_giportfolio');
} else {
    $strconfirm = get_string('confchapterdeleteall', 'mod_giportfolio');
}
echo '<br />';
$continue = new moodle_url('/mod/giportfolio/deleteuserchapter.php', array('id' => $cm->id, 'chapterid' => $chapter->id, 'confirm' => 1));
$cancel = new moodle_url('/mod/giportfolio/viewgiportfolio.php', array('id' => $cm->id, 'chapterid' => $chapter->id));
echo $OUTPUT->confirm("<strong>{$chapter->title}</strong><p>{$strconfirm}</p>", $continue, $cancel);
echo $OUTPUT->footer();
            }
        }
    } else {
        if ($chs > 1) {
            for ($i = $lastpage->pagenum + 1; $i < $chs; $i++) {
                $newchapters[] = $chapters[$i];
            }
        }
        for ($i = $ts; $i <= $te; $i++) {
            $newchapters[$i] = $chapters[$i];
        }
        for ($i = $chs; $i <= $che; $i++) {
            $newchapters[$i] = $chapters[$i];
        }
        if ($te < count($chapters)) {
            for ($i = $te; $i <= count($chapters); $i++) {
                $newchapters[$i] = $chapters[$i];
            }
        }
    }
    // Store chapters in the new order.
    $i = $lastpage->pagenum + 1;
    foreach ($newchapters as $ch) {
        $ch->pagenum = $i;
        $DB->update_record('giportfolio_userchapters', $ch);
        $i++;
    }
}
giportfolio_preload_userchapters($giportfolio, $USER->id);
// Fix structure.
redirect('viewgiportfolio.php?id=' . $cm->id . '&chapterid=' . $chapter->id . '&useredit=1');
            $data->giportfolioid = $giportfolio->id;
            $data->hidden = 0;
            $data->timecreated = time();
            $data->timemodified = time();
            $data->importsrc = '';
            $data->content = '';
            // Updated later.
            $data->contentformat = FORMAT_HTML;
            // Updated later.
            $data->iduser = $USER->id;
            // Make room for new page.
            $sql = "UPDATE {giportfolio_userchapters}\n                   SET pagenum = pagenum + 1\n                 WHERE giportfolioid = ? AND pagenum >= ? AND iduser = ? ";
            $DB->execute($sql, array($giportfolio->id, $data->pagenum, $data->iduser));
            $data->id = $DB->insert_record('giportfolio_userchapters', $data);
            // Store the files.
            $data = file_postupdate_standard_editor($data, 'content', $options, $context, 'mod_giportfolio', 'chapter', $data->id);
            $DB->update_record('giportfolio_userchapters', $data);
        }
        giportfolio_preload_userchapters($giportfolio, null);
        // Fix structure.
        redirect("viewgiportfolio.php?id={$cm->id}&chapterid={$data->id}&useredit=1");
    }
}
// Otherwise fill and print the form.
$PAGE->set_title(format_string($giportfolio->name));
$PAGE->add_body_class('mod_giportfolio');
$PAGE->set_heading(format_string($course->fullname));
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editinguserchapter', 'mod_giportfolio'));
$mform->display();
echo $OUTPUT->footer();