Example #1
0
 function get_date_item_display($column, $item)
 {
     if (empty($item->{$column})) {
         return '-';
     } else {
         return cm_timestamp_to_date($item->{$column});
     }
 }
 /**
  * Get the data to display for this table page.
  *
  * @param bool $download Flag to not include HTML for report download.
  * @return array An array of data records.
  */
 function get_data($download = false)
 {
     global $CURMAN, $CFG, $USER;
     /// Don't include users with the 'groupleader' role at the site level.
     $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
     $procid = get_field('role', 'id', 'shortname', 'groupleader');
     $LIKE = $CURMAN->db->sql_compare();
     if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') {
         $FULLNAME = 'usr.firstname || \' \' || COALESCE(usr.mi, \'\') || \' \' || usr.lastname';
     } else {
         $FULLNAME = 'CONCAT(usr.firstname,\' \',IFNULL(usr.mi, \'\'),\' \',usr.lastname)';
     }
     $cselect = 'SELECT COUNT(DISTINCT usr.id) ';
     $select = "SELECT usr.id as id,\n                           usr.idnumber as idnumber,\n                           usr.email as email,\n                           MAX(usr.timecreated) as timecreated,\n                           usr.birthdate as birthdate,\n                           usr.gender as gender,\n                           usr.country as country,\n                           clst.name as clustername,\n                           MAX(clsgrd.timegraded) as timegraded,\n                           {$FULLNAME} as student,\n                           curass.curriculumid as curriculumid,\n                           cras1.curriculumid as cras1id, cras2.curriculumid as cras2id, cras3.curriculumid as cras3id\n                   ";
     $tables = "FROM " . $CURMAN->db->prefix_table(USRTABLE) . " usr\n                    LEFT JOIN {$CFG->prefix}user mu ON mu.idnumber = usr.idnumber\n                    LEFT JOIN {$CFG->prefix}role_assignments ra ON (ra.roleid = {$procid}) AND ra.contextid = {$context->id} AND ra.userid = mu.id\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CLSGRTABLE) . " clsgrd ON clsgrd.userid = usr.id\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CLSTUSERTABLE) . " uclst ON uclst.userid = usr.id\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CLSTTABLE) . " clst ON clst.id = uclst.clusterid\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " curass ON curass.userid = usr.id\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras1 ON cras1.userid = usr.id\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras2 ON cras2.userid = usr.id AND (cras2.id != cras1.id)\n                    LEFT JOIN " . $CURMAN->db->prefix_table(CURASSTABLE) . " cras3 ON cras3.userid = usr.id AND (cras3.id != cras1.id) AND (cras3.id != cras2.id)\n                   ";
     $timenow = time();
     $yearago = $timenow - 365 * 24 * 60 * 60;
     $yearagostr = date('Y/m/d', $yearago);
     $where = "(ra.id IS NULL) ";
     $group = "GROUP BY usr.id ";
     if (!has_capability('block/curr_admin:viewreports', $context)) {
         if (has_capability('block/curr_admin:viewgroupreports', $context)) {
             $clstid = get_field(CLSTUSERTABLE, 'clusterid', 'userid', cm_get_crlmuserid($USER->id));
             $where .= "AND (uclst.clusterid = {$clstid}) ";
         }
     }
     if ($this->extrasql) {
         $where .= (!empty($where) ? ' AND ' : '') . $this->extrasql . ' ';
     }
     if (!empty($where)) {
         $where = 'WHERE ' . $where . ' ';
     }
     if (!empty($this->sort)) {
         $sort = 'ORDER BY ' . $this->sort . ' ' . $this->dir . ' ';
     } else {
         $sort = '';
     }
     if (!empty($this->perpage)) {
         if ($CURMAN->db->_dbconnection->databaseType == 'postgres7') {
             $limit = 'LIMIT ' . $this->perpage . ' OFFSET ' . $this->page * $this->perpage;
         } else {
             $limit = 'LIMIT ' . $this->page * $this->perpage . ', ' . $this->perpage;
         }
     } else {
         $limit = '';
     }
     /// Count the total number of results.
     $sql = $cselect . $tables . $where;
     $this->numrecs = $CURMAN->db->count_records_sql($sql);
     /// Get the current 'page' of results.
     $sql = $select . $tables . $where . $group . $sort . $limit;
     $this->data = $CURMAN->db->get_records_sql($sql);
     $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
     if (!empty($this->data)) {
         $curricula = get_records(CURTABLE);
         $countries = cm_get_list_of_countries();
         foreach ($this->data as $di => $datum) {
             $datum->currentclassid = 0;
             $datum->currentclass = '';
             $datum->lastclassid = 0;
             $datum->lastclass = '';
             $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
             $timenow = time();
             if (!$download) {
                 //                  if (has_capability('block/curr_admin:viewlocationusers', $context)) {
                 $datum->student = '<a href="index.php?s=rep&amp;section=rept&amp;type=' . 'induser&amp;frompage=enrol&amp;user='******'">' . $datum->student . '</a>';
                 //                  }
             }
             if ($datum->timecreated > 0) {
                 $datum->origenroldate = cm_timestamp_to_date($datum->timecreated);
             } else {
                 $datum->origenroldate = get_string('unknown', 'block_curr_admin');
             }
             $datum->birthdate = cm_timestring_to_date($datum->birthdate);
             $datum->timegraded = $datum->timegraded > 0 ? cm_timestamp_to_date($datum->timegraded) : '';
             switch ($datum->gender) {
                 case 'M':
                 case 'm':
                     $datum->gender = get_string('male', 'block_curr_admin');
                     break;
                 case 'F':
                 case 'f':
                     $datum->gender = get_string('female', 'block_curr_admin');
                     break;
                 default:
                     $datum->gender = get_string('unknown', 'block_curr_admin');
                     break;
             }
             $datum->curricula = '';
             if (!empty($datum->cras1id)) {
                 $datum->curricula .= $curricula[$datum->cras1id]->name;
             }
             if (!empty($datum->cras2id)) {
                 $datum->curricula .= !empty($datum->curricula) ? ',' : '' . $curricula[$datum->cras2id]->name;
             }
             if (!empty($datum->cras3id)) {
                 $datum->curricula .= !empty($datum->curricula) ? ',' : '' . $curricula[$datum->cras3id]->name;
             }
             if (!empty($datum->country) && isset($countries[$datum->country])) {
                 $datum->country = $countries[$datum->country];
             }
             $this->data[$di] = $datum;
         }
     }
 }
Example #3
0
 function user_profile_html($returnurl = '', $editurl = '')
 {
     $returnurl = empty($returnurl) ? 'index.php?s=usr&amp;section=users' : $returnurl;
     $editurl = empty($editurl) ? 'index.php?s=usr&amp;section=users&amp;action=edit&amp;userid=' . $this->id : $editurl;
     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     $output = '';
     $output .= '<div class="mform"><fieldset id="main" class="clearfix">
                 <legend class="ftoggler">' . fullname($this) . '</legend>
                 <div class="fcontainer">';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('idnumber') . ':</div>' . '<div class="felement">' . $this->idnumber . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('username') . ':</div>' . '<div class="felement">' . $this->username . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('timecreated', 'block_curr_admin') . ':</div>' . '<div class="felement">' . (!empty($this->timecreated) ? cm_timestamp_to_date($this->timecreated) : '-') . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('userfirstname', 'block_curr_admin') . ':</div>' . '<div class="felement">' . $this->firstname . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('userlastname', 'block_curr_admin') . ':</div>' . '<div class="felement">' . $this->lastname . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('usermi', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->mi . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('email') . ':</div>' . '<div class="felement">' . $this->email . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('email2', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->email2 . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('useraddress', 'block_curr_admin') . ':</div>' . '<div class="felement">' . $this->address . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('useraddress2', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->address2 . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('usercity', 'block_curr_admin') . ':</div>' . '<div class="felement">' . $this->city . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('userstate', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->state . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('country') . ':</div>' . '<div class="felement">' . $this->country . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('userpostalcode', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->postalcode . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('phone') . ':</div>' . '<div class="felement">' . $this->phone . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('phone2', 'block_curr_admin') . ':</div>' . '<div class="felement">' . $this->phone2 . '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('fax', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->fax . '</div></div>';
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('userbirthdate', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->birthdate . '</div></div>';
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('usergender', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->gender . '</div></div>';
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('preferredlanguage', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->language . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('usercluster', 'block_curr_admin') . ':</div>';
     $output .= '<div class="felement">';
     if (isset($this->cluster)) {
         $clusternames = array();
         foreach ($this->cluster as $cluster) {
             $clusternames[] = $cluster->name;
         }
         $output .= implode(', ', $clusternames);
     }
     $output .= '</div></div>';
     /*
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('transfercredits', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->transfercredits . '</div></div>';
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('usercomments', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->comments . '</div></div>';
       $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('notes', 'block_curr_admin') . ':</div>' .
       '<div class="felement">' . $this->notes . '</div></div>';
     */
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('createdtime', 'block_curr_admin') . ':</div>' . '<div class="felement">' . (empty($this->timecreated) ? '-' : userdate($this->timecreated)) . '</div></div>';
     $output .= '<div class="fitem"><div class="fitemtitle">' . get_string('inactive', 'block_curr_admin') . ':</div>' . '<div class="felement">' . ($this->inactive == 1 ? 'Yes' : 'No') . '</div></div>';
     $output .= '<br />';
     $output .= '<div class="fitem"><div class="fitemtitle"><a href="' . $returnurl . '">' . get_string('back') . '</div>' . '<div class="felement"><a href="' . $editurl . '">' . get_string('edit') . '</div></div>';
     $output .= '</div></fieldset></div>';
     return $output;
 }
 /**
  * Get the data needed for a downloadable version of the report (all data,
  * no paging necessary) and format it accordingly for the download file
  * type.
  *
  * NOTE: It is expected that the valid format types will be overridden in
  * an extended report class as the array is empty by default.
  *
  * @param string $format A valid format type.
  */
 function download($format)
 {
     global $CFG;
     $output = '';
     if (empty($this->rawdata)) {
         return $output;
     }
     $filename = !empty($this->title) ? $this->title : get_string('download_report', 'block_curr_admin');
     switch ($format) {
         case 'csv':
             $filename .= '.csv';
             header("Content-Transfer-Encoding: ascii");
             header("Content-Disposition: attachment; filename={$filename}");
             header("Content-Type: text/comma-separated-values");
             $row = array();
             $row[] = get_string('curriculum', 'block_curr_admin');
             foreach ($this->headers as $header) {
                 $row[] = $this->csv_escape_string(strip_tags($header));
             }
             echo implode(',', $row) . "\n";
             if (!empty($this->rawdata)) {
                 foreach ($this->rawdata as $curid => $curlist) {
                     $output .= '<strong>' . $curlist->curriculumname . ' - ' . get_string('enrolled_classes', 'block_curr_admin') . '</strong>';
                     $this->data = $curlist->data;
                     $output .= $this->display();
                     unset($this->table);
                     $output .= '<br /><br />';
                 }
             } else {
                 $output .= '<h2>' . get_string('no_classes_completed', 'block_curr_admin') . '</h2>';
             }
             foreach ($this->rawdata as $curid => $curlist) {
                 $first = $curlist->curriculumname;
                 foreach ($curlist->data as $datum) {
                     if (!is_object($datum)) {
                         continue;
                     }
                     $row = array();
                     $row[] = $this->csv_escape_string($first);
                     foreach ($this->headers as $id => $header) {
                         if (isset($datum->{$id})) {
                             $row[] = $this->csv_escape_string($datum->{$id});
                         } else {
                             $row[] = '""';
                         }
                     }
                     echo implode(',', $row) . "\n";
                 }
             }
             break;
         case 'excel':
             require_once $CFG->libdir . '/excellib.class.php';
             $filename .= '.xls';
             /// Creating a workbook
             $workbook = new MoodleExcelWorkbook('-');
             /// Sending HTTP headers
             $workbook->send($filename);
             /// Creating the first worksheet
             $sheettitle = get_string('studentprogress', 'reportstudentprogress');
             $myxls =& $workbook->add_worksheet($sheettitle);
             /// Format types
             $format =& $workbook->add_format();
             $format->set_bold(0);
             $formatbc =& $workbook->add_format();
             $formatbc->set_bold(1);
             $formatbc->set_align('center');
             $formatb =& $workbook->add_format();
             $formatb->set_bold(1);
             $formaty =& $workbook->add_format();
             $formaty->set_bg_color('yellow');
             $formatc =& $workbook->add_format();
             $formatc->set_align('center');
             $formatr =& $workbook->add_format();
             $formatr->set_bold(1);
             $formatr->set_color('red');
             $formatr->set_align('center');
             $formatg =& $workbook->add_format();
             $formatg->set_bold(1);
             $formatg->set_color('green');
             $formatg->set_align('center');
             $rownum = 0;
             $colnum = 0;
             $myxls->write($rownum, $colnum++, get_string('curriculum', 'block_curr_admin'), $formatbc);
             foreach ($this->headers as $header) {
                 $myxls->write($rownum, $colnum++, $header, $formatbc);
             }
             foreach ($this->rawdata as $curid => $curlist) {
                 $first = $curlist->curriculumname;
                 foreach ($curlist->data as $datum) {
                     if (!is_object($datum)) {
                         continue;
                     }
                     $rownum++;
                     $colnum = 0;
                     $myxls->write($rownum, $colnum++, $first, $format);
                     foreach ($this->headers as $id => $header) {
                         if (isset($datum->{$id})) {
                             $myxls->write($rownum, $colnum++, $datum->{$id}, $format);
                         } else {
                             $myxls->write($rownum, $colnum++, '', $format);
                         }
                     }
                 }
             }
             $workbook->close();
             break;
         case 'pdf':
             require_once $CFG->libdir . '/fpdf/fpdf.php';
             $filename .= '.pdf';
             $this->newpdf = new FPDF('P', 'in', 'letter');
             $marginx = 0.75;
             $marginy = 28.35 / $this->newpdf->k;
             $marginy = 0.75;
             $this->newpdf->setMargins($marginx, $marginy);
             $this->newpdf->SetFont('Arial', '', 9);
             $this->newpdf->AddPage();
             $this->newpdf->SetFillColor(225, 225, 225);
             if (file_exists("{$CFG->dirroot}/curriculum/pix/transcript.jpg")) {
                 $this->newpdf->Image("{$CFG->dirroot}/curriculum/pix/transcript.jpg", 0, 0, 8.5, 11.0, 'jpg');
             }
             $this->newpdf->SetFont('Arial', 'I', 7);
             $this->newpdf->SetXY($marginx, 2.62);
             $full = 8.5 - 2.0 * $marginx;
             $half = $full / 2.0;
             $qrtr = $half / 2.0;
             $this->newpdf->Cell($full, 0.2, get_string('transmessage', 'block_curr_admin'), 0, 0, 'C', 0);
             $this->newpdf->Ln(0.15);
             $this->newpdf->Ln(0.15);
             $this->newpdf->SetFont('Arial', '', 8);
             /// Set the left, middle and right columns.
             $leftcol = array();
             $middcol = array();
             $rghtcol = array();
             $leftcol[] = cm_fullname($this->user);
             switch ($this->user->gender) {
                 case 'M':
                 case 'm':
                     $gender = get_string('male', 'block_curr_admin');
                     break;
                 case 'F':
                 case 'f':
                     $gender = get_string('female', 'block_curr_admin');
                     break;
                 default:
                     $gender = get_string('unknown', 'block_curr_admin');
                     break;
             }
             $middcol[] = get_string('sex', 'block_curr_admin');
             $rghtcol[] = $gender;
             $bday = cm_timestring_to_date($this->user->birthdate);
             $leftcol[] = $this->user->address;
             $middcol[] = get_string('born', 'block_curr_admin');
             $rghtcol[] = $bday;
             if (!empty($this->user->origenroldate)) {
                 $enroldate = cm_timestring_to_date($this->user->origenroldate);
             } else {
                 if (!empty($this->user->timecreated)) {
                     $enroldate = cm_timestamp_to_date($this->user->timecreated);
                 } else {
                     $enroldate = get_string('unknown', 'block_curr_admin');
                 }
             }
             if (!empty($this->user->address2)) {
                 $leftcol[] = $this->user->address2;
             }
             $middcol[] = get_string('registrationdate', 'block_curr_admin');
             $rghtcol[] = $enroldate;
             $text = !empty($this->user->city) ? s($this->user->city) : '';
             $text .= !empty($this->user->state) ? (!empty($text) ? ', ' : '') . $this->user->state : '';
             $text .= !empty($this->user->postalcode) ? (!empty($text) ? ' ' : '') . s($this->user->postalcode) : '';
             $text .= !empty($this->user->country) ? (!empty($text) ? ' ' : '') . cm_get_country($this->user->country) : '';
             $leftcol[] = $text;
             $middcol[] = get_string('nuident', 'block_curr_admin');
             $rghtcol[] = $this->user->idnumber;
             $entrycredstr = get_string('entrycred', 'block_curr_admin') . ': ' . $this->user->entrycred;
             if ($this->newpdf->GetStringWidth($entrycredstr) > $half) {
                 if ($lines = $this->split_lines($entrycredstr, $half)) {
                     foreach ($lines as $line) {
                         $leftcol[] = $line;
                     }
                 }
             } else {
                 $leftcol[] = $entrycredstr;
             }
             $middcol[] = get_string('degree', 'block_curr_admin') . ':';
             $rghtcol[] = $this->user->degree;
             $leftcol[] = get_string('awards', 'block_curr_admin') . ': ' . $this->user->awards;
             foreach ($leftcol as $idx => $lefttxt) {
                 if (isset($middcol[$idx])) {
                     $this->newpdf->Cell($half, 0.2, $lefttxt, 0, 0, 'L', 0);
                     $this->newpdf->Cell($qrtr, 0.2, $middcol[$idx], 0, 0, 'L', 0);
                     $this->newpdf->Cell($qrtr, 0.2, $rghtcol[$idx], 0, 0, 'L', 0);
                 } else {
                     $this->newpdf->Cell($full, 0.2, $lefttxt, 0, 0, 'L', 0);
                 }
                 $this->newpdf->Ln(0.15);
             }
             $twidth = 0;
             $heights = array();
             $widths = array();
             $hmap = array();
             $rownum = 0;
             $this->newpdf->SetFont('Arial', '', 7);
             /// PASS 1 - Calculate sizes.
             foreach ($this->headers as $id => $header) {
                 $widths[$id] = $this->newpdf->GetStringWidth($header) + 0.2;
                 $twidth += $widths[$id];
             }
             $row = 0;
             foreach ($this->rawdata as $curid => $curlist) {
                 foreach ($curlist->data as $datum) {
                     if (!isset($heights[$row])) {
                         $heights[$row] = 0;
                     }
                     foreach ($this->headers as $id => $header) {
                         if (isset($datum->{$id})) {
                             $width = $this->newpdf->GetStringWidth($datum->{$id}) + 0.2;
                             if ($width > $widths[$id]) {
                                 $lines = ceil($width / $widths[$id]);
                                 $lines = 1;
                                 $widths[$id] = $width;
                             } else {
                                 $lines = 1;
                             }
                             $height = $lines * 0.2;
                             if ($height > $heights[$row]) {
                                 $heights[$row] = $height;
                             }
                         }
                     }
                     $row++;
                 }
             }
             /// Calculate the width of the table...
             $twidth = 0;
             foreach ($widths as $width) {
                 $twidth += $width;
             }
             $curx = 0.2;
             $cury = $this->newpdf->GetY() + 0.1;
             $endx = 8.300000000000001;
             $endy = $cury;
             $this->newpdf->Line($marginx, $cury, 8.5 - $marginx, $endy);
             $this->newpdf->Ln(0.2);
             /// Readjust the left margin according to the total width...
             $marginx = (8.5 - $twidth) / 2.0;
             $this->newpdf->setMargins($marginx, $marginy);
             //                $this->newpdf->SetX($marginx);
             $this->newpdf->Cell(8.300000000000001, 0.2, get_string('transmessage1', 'block_curr_admin'), 0, 0, 'L', 0);
             $this->newpdf->Ln(0.15);
             $this->newpdf->Cell(8.300000000000001, 0.2, get_string('transmessage2', 'block_curr_admin'), 0, 0, 'L', 0);
             $this->newpdf->Ln(0.15);
             $this->newpdf->Ln(0.15);
             $leftsummary = array();
             $rightsummary = array();
             foreach ($this->rawdata as $curid => $curlist) {
                 foreach ($this->headers as $id => $header) {
                     $text = str_replace(' ', "\n", $header);
                     $this->newpdf->Cell($widths[$id], 0.2, "{$text}", 1, 0, 'C', 1);
                 }
                 $this->newpdf->Ln();
                 $row = 0;
                 foreach ($curlist->data as $datum) {
                     if (is_array($datum) && strtolower($datum[0]) == 'hr') {
                         $curx = $this->newpdf->GetX();
                         $cury = $this->newpdf->GetY() + 0.1;
                         $endx = 0;
                         $endy = $cury;
                         foreach ($widths as $width) {
                             $endx += $width;
                         }
                         $this->newpdf->Line($curx, $cury, $endx, $endy);
                         $this->newpdf->SetX($curx + 0.1);
                     } else {
                         foreach ($this->headers as $id => $header) {
                             $text = '';
                             if (isset($datum->{$id})) {
                                 $text = $datum->{$id};
                             }
                             $this->newpdf->Cell($widths[$id], $heights[$row], $text, 0, 0, 'L', 0);
                         }
                     }
                     $this->newpdf->Ln();
                     $row++;
                 }
                 $curx = $marginx;
                 $cury = $this->newpdf->GetY() + 0.1;
                 $endx = 8.5 - $marginx;
                 $endy = $cury;
                 $this->newpdf->Line($curx, $cury, $endx, $endy);
                 $this->newpdf->Ln(0.2);
                 $this->newpdf->Write(0.2, "\n");
                 if ($curlist->numcredits > 0) {
                     $gpa = sprintf('%1.2f', (double) $curlist->gpa / (double) $curlist->numcredits);
                 } else {
                     $gpa = '0.0';
                 }
                 $leftsummary[] = get_string('total_credits', 'block_curr_admin', $curlist->curriculumname) . ": {$curlist->numcredits}";
                 $rightsummary[] = "{$curlist->curriculumname} Grade Point Average: {$gpa}";
             }
             foreach ($leftsummary as $idx => $lsummary) {
                 $this->newpdf->Cell(4.25, 0.2, $lsummary, 0, 0, 'L', 0);
                 $this->newpdf->Cell(4.25, 0.2, $rightsummary[$idx], 0, 0, 'L', 0);
                 $this->newpdf->Ln(0.15);
             }
             $this->newpdf->Ln(0.15);
             $this->newpdf->Cell(4.25, 0.2, get_string('transfercredits', 'block_curr_admin') . ": {$this->user->transfercredits}", 0, 0, 'L', 0);
             $this->newpdf->Ln(0.75);
             /// Signature line:
             $curx = $this->newpdf->GetX();
             $cury = $this->newpdf->GetY() + 0.1;
             $endx = 0;
             $endy = $cury;
             foreach ($widths as $width) {
                 $endx += $width;
             }
             $this->newpdf->Line($marginx, $cury, 8.5 - $marginx, $endy);
             $this->newpdf->Ln(0.15);
             $half = (8.5 - 2 * $marginx) / 2.0;
             $this->newpdf->Cell($half, 0.2, get_string('registrar', 'block_curr_admin'), 0, 0, 'L', 0);
             $this->newpdf->Cell($half, 0.2, get_string('date', 'block_curr_admin'), 0, 0, 'L', 0);
             $this->newpdf->Output($filename, 'I');
             break;
         default:
             return $output;
             break;
     }
 }
 /**
  * Takes a record and transform it into an appropriate format
  * This method is set up as a hook to be implented by actual report class
  *
  * @param   stdClass  $record         The current report record
  * @param   string    $export_format  The format being used to render the report
  *
  * @return  stdClass                  The reformatted record
  */
 function transform_record($record, $export_format)
 {
     $record->user_id = fullname($record);
     // start-end dates
     $sdate = cm_timestamp_to_date($record->startdate, STR_DATE_FORMAT);
     $edate = !empty($record->enddate) ? cm_timestamp_to_date($record->enddate, STR_DATE_FORMAT) : get_string('present', $this->langfile);
     $record->startdate = empty($record->startdate) && empty($record->enddate) ? get_string('na', $this->langfile) : "{$sdate} - {$edate}";
     // completed date
     $record->completed = $record->status != STUSTATUS_NOTCOMPLETE && !empty($record->completed) ? cm_timestamp_to_date($record->completed, STR_DATE_FORMAT) : get_string('incomplete', $this->langfile);
     // status mapping
     $statusmap = array(STUSTATUS_NOTCOMPLETE => 'na', STUSTATUS_FAILED => 'status_failed', STUSTATUS_PASSED => 'status_passed');
     $record->status = get_string($statusmap[$record->status], $this->langfile);
     if (!empty($record->grade)) {
         $record->grade = cm_display_grade($record->grade);
         if ($export_format != php_report::$EXPORT_FORMAT_CSV) {
             $record->grade .= get_string('percent_symbol', $this->langfile);
         }
     } else {
         $record->grade = get_string('na', $this->langfile);
     }
     return $record;
 }
 /**
  * Main display function.
  *
  * Fetch and display (or download) the required data.
  *
  * @param string $sort     The column to sort results by.
  * @param string $dir      The direction to sort by.
  * @param int    $page     The page number to display results for.
  * @param int    $perpage  The number of results per page.
  * @param string $search   A string to search for.
  * @param string $alpha    An initial to filter results by.
  * @param string $download The format to download the report in.
  */
 function main($sort = '', $dir = '', $page = 0, $perpage = 20, $download = '', $frompage = '')
 {
     global $CFG, $USER;
     $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
     $canaccessum = false;
     if (has_capability('block/curr_admin:viewreports', $context)) {
         $this->usrid = cm_get_param('user', 0);
         $canaccessum = true;
     } else {
         if (has_capability('block/curr_admin:viewgroupreports', $context)) {
             // Verify userid
             $this->usrid = cm_get_param('user', 0);
             if (!cm_can_access_userreport($this->usrid)) {
                 error("No access allowed.");
             }
             $canaccessum = false;
         } else {
             if (has_capability('block/curr_admin:viewownreports', $context)) {
                 // Make sure only this user.
                 if (!($this->usrid = cm_get_crlmuserid($USER->id))) {
                     error("No account found.");
                 }
             } else {
                 error("No access allowed.");
             }
         }
     }
     $user = new user($this->usrid);
     $this->baseurl .= '&amp;user='******'&amp;hideins=' . $this->hideins;
     $this->set_title('Individual User Report for ' . cm_fullname($user));
     if (empty($download)) {
         $output = '';
         if ($frompage == '') {
             $frompage = 'users';
         }
         $pagename = get_string("report{$frompage}", 'block_curr_admin');
         $bc = '<span class="breadcrumb"><a href="index.php?s=rep&amp;section=rept&amp;type=' . $frompage . '">' . $pagename . '</a> &raquo; ' . $this->title . '</span>';
         $output .= cm_print_heading_block($bc, '', true);
         $output .= '<br />' . "\n";
     }
     $this->get_data(!empty($download));
     $this->add_column('courseidnumber', 'Course ID', 'left', false);
     $this->add_column('coursename', 'Course Name', 'left', false);
     $this->add_column('classidnumber', 'Class ID', 'left', false);
     if (!empty($this->_maxexams)) {
         for ($i = 1; $i <= $this->_maxexams; $i++) {
             $this->add_column('ccgrade' . $i, 'Exam ' . $i, 'left', false);
             $this->add_column('cctimegraded' . $i, 'Date ' . $i, 'left', false);
         }
     }
     $this->add_column('classgrade', 'Class Grade', 'left', false);
     $this->add_column('credits', 'Credits', 'left', false);
     $this->add_column('datecomplete', 'Completed', 'left', false);
     $this->add_column('completestatus', 'Status', 'left', false);
     //        $this->add_column('nextdue', 'Next Due', 'left', true);
     //        $this->add_column('insid', 'Instructor ID', 'left', true);
     /*
             if (!$this->hideins) {
                 $this->add_column('insname', 'Instructor Name', 'left', true);
             }
     */
     $this->set_default_sort('coursename', 'ASC');
     $this->sort = !empty($sort) ? $sort : $this->defsort;
     $this->dir = !empty($dir) ? $dir : $this->defdir;
     $this->page = 0;
     $this->perpage = 9999;
     if (empty($download)) {
         $tlink = $CFG->wwwroot . '/curriculum/index.php';
         $toptions = array('s' => 'rep', 'section' => 'rept', 'type' => 'transcript', 'user' => $this->usrid);
         $tlabel = get_string('transcript', 'block_curr_admin');
         $output .= '<div class="trans-button">' . print_single_button($tlink, $toptions, $tlabel, NULL, NULL, true) . '</div>';
         if (!empty($this->rawdata)) {
             $output .= $this->print_download_menu();
         }
         $output .= '<br />';
         $output .= '<fieldset>' . "\n";
         /*
                     $output .= '<form action="index.php" method="post">';
                     $output .= '<input type="hidden" name="s" value="rep" />';
                     $output .= '<input type="hidden" name="section" value="rept" />';
                     $output .= '<input type="hidden" name="type" value="induser" />';
                     $output .= '<input type="hidden" name="sort" value="' . $this->sort . '" />';
                     $output .= '<input type="hidden" name="dir" value="' . $this->dir . '" />';
                     $output .= '<input type="hidden" name="user" value="' . $this->usrid . '" />';
                     $output .= 'Hide instructor name <input type="checkbox" name="hideins" value="1" ' .
                                (!empty($this->hideins) ? ' checked' : '') . ' /> ';
                     $output .= '<input type="submit" value="Update Display" />';
                     $output .= '</form><br />';
         */
         if (empty($user->origenroldate)) {
             if (empty($user->timecreated)) {
                 $origdate = get_string('unknown', 'block_curr_admin');
             } else {
                 $origdate = cm_timestamp_to_date($user->timecreated);
             }
         } else {
             if (!($origdate = cm_timestring_to_date($user->origenroldate))) {
                 $origdate = get_string('unknown', 'block_curr_admin');
             }
         }
         $output .= '<legend>' . get_string('user_information', 'block_curr_admin') . '</legend>';
         $output .= '<div style="float: left; width: 50%;"><b>' . get_string('user_id', 'block_curr_admin') . '</b> ';
         if ($canaccessum) {
             $output .= '<a href="' . $CFG->wwwroot . '/curriculum/index.php?s=usr&userid=' . $user->id . '&action=view">' . $user->idnumber . '</a></div>';
         } else {
             $output .= $user->idnumber . '</div>';
         }
         $output .= '<div style="float: left; width: 50%;"><b>' . get_string('student_email', 'block_curr_admin') . ':</b> ' . $user->email . '</div><br />';
         $output .= '<div style="float: left; width: 50%;"><b>' . get_string('firstname', 'block_curr_admin') . ':</b> ' . $user->firstname . '</div>';
         $output .= '<div style="float: left; width: 50%;"><b>' . get_string('original_reg_date', 'block_curr_admin') . ':</b> ' . $origdate . '</div><br />';
         $output .= '<div style="float: left; width: 35%;"><b>' . get_string('lastname', 'block_curr_admin') . ':</b> ' . $user->lastname . '</div><br />';
         $output .= '</fieldset><br />';
         if (!empty($this->rawdata)) {
             foreach ($this->rawdata as $curid => $curlist) {
                 $output .= '<strong>' . $curlist->curriculumname . ' - ' . get_string('enrolled_classes', 'block_curr_admin') . '</strong>';
                 $this->data = $curlist->data;
                 $output .= $this->display();
                 unset($this->table);
                 $output .= '<br /><br />';
             }
         } else {
             $output .= '<h2>' . get_string('no_classes_completed', 'block_curr_admin') . '</h2>';
         }
         $output .= $this->print_footer();
         echo $output;
     } else {
         $this->download($download);
     }
 }
 /**
  * Creates rows for each item in $items.
  * @param $items array of records
  * @param $columns associative array of column ids => column heading text.  column ids correspond to record properties.
  * @param $table the table object to add the items to
  */
 function add_table_items($items, $columns, $table = null)
 {
     $countries = cm_get_list_of_countries();
     $table->width = "95%";
     foreach ($items as $item) {
         // TODO: (short term) push this logic to the page class, by using a get_cell_value($item, $columnname) function that is called for
         // each cell in the table.
         // TODO: (long term) push this logic to the model, either by using accessors or by using field types
         $newarr = array();
         foreach ($columns as $column => $cdesc) {
             // From cmclasspage
             if ($column == 'idnumber') {
                 $newarr[] = '<a href="index.php?s=rep&amp;section=rept&amp;type=classroster&amp;' . 'class=' . $item->id . '">' . $item->idnumber . '</a>';
             } else {
                 if ($column == 'envname') {
                     $newarr[] = '<div align="center"><span title="' . $item->envdescription . '">' . $item->envname . '</span></div>';
                 } else {
                     if ($column == 'startdate' || $column == 'enddate') {
                         if (empty($item->{$column})) {
                             $newarr[] = '-';
                         } else {
                             $newarr[] = cm_timestamp_to_date($item->{$column});
                         }
                     } else {
                         if ($column == 'starttime') {
                             if ($item->starttimehour == '0' && $item->starttimeminute == '0') {
                                 $newarr[] = 'n/a';
                             } else {
                                 $newarr[] = $item->starttimehour . ':' . sprintf("%02d", $item->starttimeminute);
                             }
                         } else {
                             if ($column == 'endtime') {
                                 if ($item->endtimehour == '0' && $item->endtimeminute == '0') {
                                     $newarr[] = 'n/a';
                                 } else {
                                     $newarr[] = $item->endtimehour . ':' . sprintf("%02d", $item->endtimeminute);
                                 }
                                 // From usermanagementpage
                             } else {
                                 if ($column == 'location') {
                                     $newarr[] = '<a href="index.php?s=rep&amp;section=rept&amp;type=' . 'recloc&amp;loc=' . $item->location . '">' . $item->location . '</a>';
                                 } else {
                                     if ($column == 'currentclass') {
                                         $newarr[] = '<a href="index.php?s=rep&amp;section=rept&amp;type=' . 'classroster&amp;class=' . $item->currentclassid . '">' . $item->currentclass . '</a>';
                                     } else {
                                         if ($column == 'lastclass') {
                                             $newarr[] = '<a href="index.php?s=rep&amp;section=rept&amp;type=' . 'classroster&amp;class=' . $item->lastclassid . '">' . $item->lastclass . '</a>';
                                         } else {
                                             if ($column == 'country') {
                                                 $newarr[] = isset($countries[$item->country]) ? $countries[$item->country] : '';
                                             } else {
                                                 if ($column == 'timecreated') {
                                                     if (!empty($item->origenroldate)) {
                                                         $dateparts = explode('/', $item->origenroldate);
                                                         $bt = mktime(0, 0, 0, $dateparts[1], $dateparts[2], $dateparts[0]);
                                                         $newarr[] = userdate($bt);
                                                     } else {
                                                         if (!empty($item->timecreated)) {
                                                             $newarr[] = userdate($item->timecreated);
                                                         } else {
                                                             $newarr[] = '-';
                                                         }
                                                     }
                                                 } else {
                                                     $newarr[] = $item->{$column};
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // Add link to specified columns
             if (in_array($column, $this->view_columns)) {
                 $target = $this->get_new_page(array('action' => 'view', 'id' => $item->id));
                 $newarr[count($newarr) - 1] = '<a href="' . $target->get_url() . '">' . $newarr[count($newarr) - 1] . '</a>';
             }
         }
         $newarr[] = $this->get_buttons(array('id' => $item->id));
         $table->data[] = $newarr;
     }
     return $table;
 }