Exemple #1
0
 foreach ($actions as $act) {
     /// Verify whether the diploma corresponds to this course and this USER
     $requesteddip = $DB->get_record('diplome_diploma', 'id', $dipids[$act]);
     /// Only if requested dip exists
     if ($requesteddip !== false) {
         if ($requesteddip->userid != $USER->id) {
             echo '<p class="error">' . get_string('wrongcertificateowner', 'diplome') . '</p>';
             continue;
         }
         $course2 = $DB->get_record('course', 'id', $requesteddip->courseid);
         if (!$course2) {
             echo '<p class="error"><b>' . $requesteddip->id . '</b> : ' . get_string('invalidcourseidindatabase', 'diplome') . '</p>';
             // delete_records('diplome_diploma', 'id', $requesteddip->id);
             continue;
         }
         $roleassign = get_valid_roleassign($requesteddip->userid, $requesteddip->courseid);
         if (!$roleassign) {
             echo '<p class="error"><b>' . $course2->fullname . '</b> : ' . get_string('studentviewinvalidroleassignindatabase', 'diplome') . '</p>';
             // delete_records('diplome_diploma', 'id', $requesteddip->id);
             // unlink($CFG->dataroot.'/'.$filepath);
             continue;
         }
         $filepath = 'user/d0/' . $requesteddip->userid . '/' . $course2->fullname . '.pdf';
         if (!file_exists($CFG->dataroot . '/' . $filepath)) {
             echo '<p class="error"><b>' . $requesteddip->userid . '/' . $course2->fullname . '.pdf' . '</b> : ' . get_string('certificatefiledeleted', 'diplome') . '</p>';
             // delete_records('diplome_diploma', 'id', $requesteddip->id);
             continue;
         }
         if ($requesteddip->status > 1) {
             echo '<p class="error">' . get_string('certificatefileprinted', 'diplome') . '</p>';
         }
 $filetype = $uploaded['type'][$counter];
 if (strcmp($filetype, $pdftype) != 0) {
     echo '<p class="error"><b>' . $uploaded['name'][$counter] . '</b> : ' . get_string('pdffiletypeerror', 'diplome') . '.</p>';
     break;
 }
 $filesize = $uploaded['size'][$counter];
 if ($filesize > 4194304) {
     echo '<p class="error"><b>' . $uploaded['name'][$counter] . '</b> : ' . get_string('filesizeerror', 'diplome') . '</p>';
     break;
 }
 $uid = $userid[$counter];
 if (($user = get_record('user', 'id', $uid)) === false) {
     echo '<p class="error">' . get_string('nosuchuser', 'diplome') . '</p>';
     break;
 }
 if (get_valid_roleassign($uid, $course->id) === false) {
     echo '<p class="error"><b>' . $user->firstname . ' ' . $user->lastname . '</b> : ' . get_string('invalidroleassign', 'diplome') . '</p>';
     break;
 }
 $diploma = get_record('diplome_diploma', 'userid', $uid, 'courseid', $course->id);
 if ($diploma === false) {
     $diprecord = new object();
     $diprecord->userid = $uid;
     $diprecord->courseid = $course->id;
 } else {
     if ($diploma->status == 2) {
         echo '<p class=error>' . $user->firstname . ' ' . $user->lastname . ' ' . get_string('alreadyprinted', 'diplome') . '</p>';
         break;
     }
 }
 $dir = "user/d0/" . $uid;
Exemple #3
0
if (!empty($CFG->forcelogin) and !isloggedin()) {
    // protect images if login required and not logged in;
    // do not use require_login() because it is expensive and not suitable here anyway
    redirect('img/error.png');
}
// disable moodle specific debug messages
disable_debugging();
$relativepath = get_file_argument('download.php');
$args = explode('/', trim($relativepath, '/'));
if (count($args) == 2) {
    $pathname = $CFG->dataroot . '/user/d0' . $relativepath;
    $lifetime = 0;
    /// Verify role assignment of the student in the specified course
    $pos = strrpos($args[1], '.pdf');
    $coursename = substr($args[1], 0, $pos);
    $user = get_record('user', 'id', $args[0]);
    if ($user === false) {
        redirect('img/error.png');
    }
    $course = get_record('course', 'fullname', $coursename);
    if ($course === false) {
        redirect('img/error.png');
    }
    $validdip = get_record('diplome_diploma', 'userid', $user->id, 'courseid', $course->id);
    $validra = get_valid_roleassign((int) $args[0], $course->id);
    if ($validra !== false && $validdip != false && file_exists($pathname) && !is_dir($pathname)) {
        send_file($pathname, $user->lastname . '_' . $user->firstname . '_' . $args[1], $lifetime);
    }
}
/// When path does not corespond -> use default instead
redirect('img/error.png');
Exemple #4
0
function print_course_diplomas_table($showstatus, $cid, $i)
{
    global $CFG, $DB;
    /// Print students table with the available diplomas
    if ($showstatus == 0) {
        $studentds = $DB->{$DB}->get_records_sql("SELECT d.id, d.courseid, d.userid, d.status, u.firstname, u.lastname, c.fullname\n\t\t\tFROM {$CFG->prefix}course c\n\t\t\tINNER JOIN {$CFG->prefix}diplome_diploma d\n\t\t\t\tON c.id = '" . $cid . "'\n\t\t\t\tAND c.id = d.courseid \n\t\t\tINNER JOIN {$CFG->prefix}user u\n\t\t\t\tON d.userid = u.id\n\t\t\tORDER BY u.lastname, u.firstname;\n\t\t\t");
    } else {
        $studentds = $DB->get_records_sql("SELECT d.id, d.courseid, d.userid, d.status, u.firstname, u.lastname, c.fullname\n\t\t\tFROM {$CFG->prefix}course c\n\t\t\tINNER JOIN {$CFG->prefix}diplome_diploma d\n\t\t\t\tON c.id = '" . $cid . "'\n\t\t\t\tAND c.id = d.courseid\n\t\t\t\tAND d.status >= '" . $showstatus . "'\n\t\t\tINNER JOIN {$CFG->prefix}user u\n\t\t\t\tON d.userid = u.id\n\t\t\tORDER BY u.lastname, u.firstname;\n\t\t\t");
    }
    if (!$studentds) {
        echo '<p class="error">' . get_string('nocoursecertificateswithstatus', 'diplome') . '</p>';
    } else {
        $table = new html_table();
        $table->width = '60%';
        $table->class = 'generaltable overviewtable';
        $table->data = array();
        $table->head = array(get_string('headerstudent', 'diplome'), get_string('headerdownload', 'diplome'), get_string('headerrequested', 'diplome'), get_string('headerprinted', 'diplome'), get_string('headersigned', 'diplome'), get_string('headerready', 'diplome'));
        $table->align = array('center', 'center', 'left', 'left', 'left', 'left');
        $table->size = array('', '', '', '', '', '');
        foreach ($studentds as $studentd) {
            $roleassign = get_valid_roleassign($studentd->userid, $studentd->courseid);
            $filepath = $studentd->userid . '/' . $studentd->fullname . '.pdf';
            if ($roleassign === false) {
                echo '<p class="error"><b>' . $studentd->id . '</b> : ' . get_string('invalidroleassignindatabase', 'diplome') . '</p>';
                // delete_record('diplome_diploma', 'id', $student->id);
                // unlink($CFG->dataroot.'/'.$filepath);
                continue;
            }
            if (!file_exists($CFG->dataroot . '/user/d0/' . $filepath)) {
                echo '<b>' . $studentd->userid . '/' . $studentd->fullname . '.pdf' . '</b> : ';
                echo '<p class="error"><b>' . $filepath . '</b> : ' . get_string('certificatefiledeleted', 'diplome') . '</p>';
                // delete_records('diplome_diploma', 'id', $student->id);
                continue;
            } else {
                echo 'vasilica';
                $row = array();
                $row[] = $studentd->firstname . ' ' . $studentd->lastname;
                $row[] = '<a href="' . $CFG->wwwroot . '/mod/diplome/download.php/' . $filepath . '">Download</a>';
                if ($studentd->status == 0) {
                    $row[] = '<img src="img/redcherry.png" alt="' . get_string('no', 'diplome') . '"/>';
                } else {
                    $row[] = '<img src="img/greencherry.png" alt="' . get_string('yes', 'diplome') . '"/>';
                }
                $column = 1;
                do {
                    $inputs = '';
                    if ($studentd->status == $column) {
                        $inputs = '<input type="checkbox" name="actions[]" value="' . $i . '"/>';
                        $inputs .= '<input type="hidden" name="dids[]" value="' . $studentd->id . '"/>';
                        $inputs .= '<input type="hidden" name="dstatus[]" value="' . $studentd->status . '"/>';
                        $i++;
                    } else {
                        if ($studentd->status > $column) {
                            $inputs = '<img src="img/green.gif" alt="' . get_string('yes', 'diplome') . '"/>';
                        }
                    }
                    $column++;
                    $row[] = $inputs;
                } while ($column < 4);
                $table->data[] = $row;
            }
        }
        echo '<br/>';
        if (!$table->data) {
            echo '<p class="error">' . get_string('novalidrequests', 'diplome') . '</p>';
            return $i;
        }
        echo html_writer::table($table);
        echo '<br/>';
        return $i;
    }
}