/** * @todo Documenting this function */ function stampcoll_user_complete($course, $user, $mod, $stampcoll) { global $USER; $context = get_context_instance(CONTEXT_MODULE, $mod->id); if ($USER->id == $user->id) { if (!has_capability('mod/stampcoll:viewownstamps', $context)) { echo get_string('notallowedtoviewstamps', 'stampcoll'); return true; } } else { if (!has_capability('mod/stampcoll:viewotherstamps', $context)) { echo get_string('notallowedtoviewstamps', 'stampcoll'); return true; } } if (!($allstamps = stampcoll_get_stamps($stampcoll->id))) { // no stamps yet in this instance echo get_string('nostampscollected', "stampcoll"); return true; } $userstamps = array(); foreach ($allstamps as $s) { if ($s->userid == $user->id) { $userstamps[] = $s; } } unset($allstamps); unset($s); if (empty($userstamps)) { echo get_string('nostampscollected', 'stampcoll'); } else { echo get_string('numberofcollectedstamps', 'stampcoll', count($userstamps)); echo '<div class="stamppictures">'; foreach ($userstamps as $s) { echo stampcoll_stamp($s, $stampcoll->image); } echo '</div>'; unset($s); } }
if (!$stampcoll->displayzero) { $sql .= 'HAVING COUNT(s.id) > 0 '; } // First query with not limits to get the number of returned rows if (($ausers = get_records_sql($select . $sql . $sort)) !== false) { $table->pagesize($perpage, count($ausers)); // Second query with pagination limits if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) { foreach ($ausers as $auser) { $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true); $fullname = fullname($auser); $count = $auser->count; $stamps = ''; if (isset($userstamps[$auser->id])) { foreach ($userstamps[$auser->id] as $s) { $stamps .= stampcoll_stamp($s, $stampcoll->image); } unset($s); } $row = array($picture, $fullname, $count, $stamps); $table->add_data($row); } } } $table->print_html(); /// Print the whole table /// Mini form for setting user preference echo '<br />'; echo '<form name="options" action="view.php?id=' . $cm->id . '" method="post">'; echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />'; echo '<table id="optiontable" align="center">';
} if ($auser->id != $USER->id && $cap_viewotherstamps) { $count = $auser->count; } $comment = '<form name="addform" action="editstamps.php?id=' . $cm->id . '" method="post">'; $comment .= '<input name="text" type="text" size="35" maxlength="250" />'; $comment .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; $comment .= '<input type="hidden" name="userid" value="' . $auser->id . '" />'; $comment .= '<input type="hidden" name="page" value="' . $page . '" />'; $comment .= '<input type="hidden" name="addstamp" value="1" />'; $comment .= '<input type="submit" value="' . get_string('addstampbutton', 'stampcoll') . '" /></form>'; $row = array($picture, $fullname, $count, $comment); $table->add_data($row); if ($cap_viewotherstamps && $showupdateforms && isset($userstamps[$auser->id])) { foreach ($userstamps[$auser->id] as $userstamp) { $count = stampcoll_stamp($userstamp, '', true, false, $CFG->pixpath . '/t/preview.gif'); $count .= ' '; if ($cap_managestamps) { $count .= '<a href="editstamps.php?id=' . $cm->id . '&d=' . $userstamp->id . '&sesskey=' . sesskey() . '&page=' . $page . '" title="' . get_string('deletestamp', 'stampcoll') . '">'; $count .= '<img src="' . $CFG->pixpath . '/t/delete.gif" height="11" width="11" border="0" alt="' . get_string('deletestamp', 'stampcoll') . '" />'; $count .= '</a> '; } if ($cap_managestamps || $userstamp->giver == $USER->id) { $comment = '<form name="updateform" action="editstamps.php?id=' . $cm->id . '" method="post">'; $comment .= '<input name="text" type="text" size="35" maxlength="250" value="' . format_string($userstamp->text) . '" />'; $comment .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; $comment .= '<input type="hidden" name="stampid" value="' . $userstamp->id . '" />'; $comment .= '<input type="hidden" name="page" value="' . $page . '" />'; $comment .= '<input type="hidden" name="updatestamp" value="1" />'; $comment .= '<input type="submit" value="' . get_string('updatestampbutton', 'stampcoll') . '" /></form>'; } else {