Ejemplo n.º 1
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     if (is_array($value)) {
         $content = $value['checked'];
         $allrequired = $value['allrequired'] ? true : false;
     } else {
         $content = array();
         $allrequired = false;
     }
     $str = '';
     $found = false;
     foreach (explode("\n", $this->field->param1) as $checkbox) {
         $checkbox = trim($checkbox);
         if (in_array($checkbox, $content)) {
             $str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), true, $checkbox);
         } else {
             $str .= html_writer::checkbox('f_' . $this->field->id . '[]', s($checkbox), false, $checkbox);
         }
         $found = true;
     }
     if (!$found) {
         return '';
     }
     $str .= html_writer::checkbox('f_' . $this->field->id . '_allreq', null, $allrequired, get_string('selectedrequired', 'data'));
     return $str;
 }
Ejemplo n.º 2
0
 /**
  * Print HTML to display the "Also show old questions" checkbox
  */
 public function display_options_adv()
 {
     echo \html_writer::start_div();
     echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'showhidden', 'value' => '0', 'id' => 'showhidden_off'));
     echo \html_writer::checkbox('showhidden', '1', !$this->hide, get_string('showhidden', 'question'), array('id' => 'showhidden_on', 'class' => 'searchoptions'));
     echo \html_writer::end_div() . "\n";
 }
 public function destination_courses_selector(moodle_url $nextstageurl, destination_courses_search $courses = null, $courseid)
 {
     $html = html_writer::start_tag('div', array('class' => 'import-course-selector backup-restore'));
     $html .= html_writer::start_tag('form', array('method' => 'post', 'action' => $nextstageurl->out_omit_querystring()));
     foreach ($nextstageurl->params() as $key => $value) {
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
     }
     $html .= html_writer::start_tag('div', array('class' => 'ics-existing-group backup-section'));
     $html .= $this->output->heading(get_string('selectgroups', 'local_syncgroups'), 2, array('class' => 'header'));
     $html .= html_writer::start_tag('ul');
     $groups = groups_get_all_groups($courseid, 0, 0, 'g.id, g.name');
     foreach ($groups as $group) {
         $html .= html_writer::start_tag('li') . html_writer::checkbox('groups[]', $group->id, false, $group->name) . html_writer::end_tag('li');
     }
     $html .= html_writer::end_tag('ul');
     $html .= html_writer::end_tag('div');
     // We only allow import adding for now. Enforce it here.
     $html .= html_writer::start_tag('div', array('class' => 'ics-existing-course backup-section'));
     $html .= $this->output->heading(get_string('syncgroupsto', 'local_syncgroups'), 2, array('class' => 'header'));
     $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
     $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('continue'))));
     $html .= html_writer::end_tag('div');
     $html .= html_writer::end_tag('form');
     $html .= html_writer::end_tag('div');
     return $html;
 }
Ejemplo n.º 4
0
 function display_search_field($value = 0)
 {
     $selectors = html_writer::select_time('days', 'f_' . $this->field->id . '_d', $value['timestamp']) . html_writer::select_time('months', 'f_' . $this->field->id . '_m', $value['timestamp']) . html_writer::select_time('years', 'f_' . $this->field->id . '_y', $value['timestamp']);
     $datecheck = html_writer::checkbox('f_' . $this->field->id . '_z', 1, $value['usedate']);
     $str = $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data');
     return $str;
 }
Ejemplo n.º 5
0
function block_poll_get_response_checks($options, $selected)
{
    foreach ($options as $option) {
        $arr[] = html_writer::checkbox('', '', $option->id == $selected, '', array('onclick' => 'this.checked=' . ($option->id == $selected ? 'true' : 'false')));
    }
    return $arr;
}
Ejemplo n.º 6
0
/** Display an standard html checkbox with an optional label
 * NOTE: this version is from Moodle 1.9x it *SUPPORTS* script tags for onclick
 *       (unlike the version in /lib/deprecatedlib.php)
 *
 * @param string  $name    The name of the checkbox
 * @param string  $value   The valus that the checkbox will pass when checked
 * @param boolean $checked The flag to tell the checkbox initial state
 * @param string  $label   The label to be showed near the checkbox
 * @param string  $alt     The info to be inserted in the alt tag
 */
function _print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script = '', $return = false)
{
    if (defined('USE_OLD_CHECKBOX')) {
        static $idcounter = 0;
        if (!$name) {
            $name = 'unnamed';
        }
        if ($alt) {
            $alt = strip_tags($alt);
        } else {
            $alt = 'checkbox';
        }
        if ($checked) {
            $strchecked = ' checked="checked"';
        } else {
            $strchecked = '';
        }
        $htmlid = 'auto-cb' . sprintf('%04d', ++$idcounter);
        $output = '<span class="checkbox ' . $name . "\">";
        $output .= '<input name="' . $name . '" id="' . $htmlid . '" type="checkbox" value="' . $value . '" alt="' . $alt . '"' . $strchecked . ' ' . (!empty($script) ? ' onclick="' . $script . '" ' : '') . ' />';
        if (!empty($label)) {
            $output .= ' <label for="' . $htmlid . '">' . $label . '</label>';
        }
        $output .= '</span>' . "\n";
        if (empty($return)) {
            echo $output;
        } else {
            return $output;
        }
    } else {
        $output = html_writer::checkbox($name, $value, $checked, $label, empty($script) ? null : array('onclick' => $script));
        if (empty($return)) {
            echo $output;
        } else {
            return $output;
        }
    }
}
Ejemplo n.º 7
0
/**
 * Get users for unlinking/relinking. Called from ajax.php via turnitintooltwo.js.
 *
 * @global type $DB
 * @return array return array of users to display
 */
function turnitintooltwo_getusers()
{
    global $DB;
    $config = turnitintooltwo_admin_config();
    $return = array();
    $idisplaystart = optional_param('iDisplayStart', 0, PARAM_INT);
    $idisplaylength = optional_param('iDisplayLength', 10, PARAM_INT);
    $secho = optional_param('sEcho', 1, PARAM_INT);
    $displaycolumns = array('tu.userid', 'tu.turnitin_uid', 'mu.lastname', 'mu.firstname', 'mu.email');
    $queryparams = array();
    // Add sort to query.
    $isortcol[0] = optional_param('iSortCol_0', null, PARAM_INT);
    $isortingcols = optional_param('iSortingCols', 0, PARAM_INT);
    $queryorder = "";
    if (!is_null($isortcol[0])) {
        $queryorder = " ORDER BY ";
        $startorder = $queryorder;
        for ($i = 0; $i < intval($isortingcols); $i++) {
            $isortcol[$i] = optional_param('iSortCol_' . $i, null, PARAM_INT);
            $bsortable[$i] = optional_param('bSortable_' . $isortcol[$i], null, PARAM_TEXT);
            $ssortdir[$i] = optional_param('sSortDir_' . $i, null, PARAM_TEXT);
            if ($bsortable[$i] == "true") {
                $queryorder .= $displaycolumns[$isortcol[$i]] . " " . $ssortdir[$i] . ", ";
            }
        }
        if ($queryorder == $startorder) {
            $queryorder = "";
        } else {
            $queryorder = substr_replace($queryorder, "", -2);
        }
    }
    // Add search to query.
    $ssearch = optional_param('sSearch', '', PARAM_TEXT);
    $querywhere = ' WHERE ( ';
    for ($i = 0; $i < count($displaycolumns); $i++) {
        $bsearchable[$i] = optional_param('bSearchable_' . $i, null, PARAM_TEXT);
        if (!is_null($bsearchable[$i]) && $bsearchable[$i] == "true" && $ssearch != '') {
            $include = true;
            if ($i <= 1) {
                if (!is_int($ssearch) || is_null($ssearch)) {
                    $include = false;
                }
            }
            if ($include) {
                $querywhere .= $DB->sql_like($displaycolumns[$i], ':search_term_' . $i, false) . " OR ";
                $queryparams['search_term_' . $i] = '%' . $ssearch . '%';
            }
        }
    }
    if ($querywhere == ' WHERE ( ') {
        $querywhere = "";
    } else {
        $querywhere = substr_replace($querywhere, "", -3);
        $querywhere .= " )";
    }
    $query = "SELECT tu.id AS id, tu.userid AS userid, tu.turnitin_uid AS turnitin_uid, tu.turnitin_utp AS turnitin_utp, " . "mu.firstname AS firstname, mu.lastname AS lastname, mu.email AS email " . "FROM {turnitintooltwo_users} tu " . "LEFT JOIN {user} mu ON tu.userid = mu.id " . $querywhere . $queryorder;
    $users = $DB->get_records_sql($query, $queryparams, $idisplaystart, $idisplaylength);
    $totalusers = count($DB->get_records_sql($query, $queryparams));
    $return["aaData"] = array();
    foreach ($users as $user) {
        $checkbox = html_writer::checkbox('userids[]', $user->id, false, '', array("class" => "browser_checkbox"));
        $pseudoemail = "";
        if (!empty($config->enablepseudo)) {
            $pseudouser = new TiiPseudoUser(turnitintooltwo_user::get_pseudo_domain());
            $pseudouser->setEmail($user->email);
            $pseudoemail = $pseudouser->getEmail();
        }
        $return["aaData"][] = array($checkbox, $user->turnitin_uid == 0 ? '' : $user->turnitin_uid, format_string($user->lastname), format_string($user->firstname), $pseudoemail);
    }
    $return["sEcho"] = $secho;
    $return["iTotalRecords"] = count($users);
    $return["iTotalDisplayRecords"] = $totalusers;
    return $return;
}
 /**
  * Display the interface for messaging options
  *
  * @param   mixed   $processors         array of objects containing message processors
  * @param   mixed   $providers          array of objects containing message providers
  * @param   mixed   $preferences        array of objects containing current preferences
  * @param   mixed   $defaultpreferences array of objects containing site default preferences
  * @return  string                      The text to render
  */
 public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences)
 {
     // Filter out enabled, available system_configured and user_configured processors only.
     $readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();'));
     // Start the form.  We're not using mform here because of our special formatting needs ...
     $output = html_writer::start_tag('form', array('method' => 'post', 'class' => 'mform'));
     $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
     /// Settings table...
     $output .= html_writer::start_tag('fieldset', array('id' => 'providers', 'class' => 'clearfix'));
     $output .= html_writer::nonempty_tag('legend', get_string('providers_config', 'message'), array('class' => 'ftoggler'));
     // Display the messging options table
     $table = new html_table();
     $table->attributes['class'] = 'generaltable';
     $table->data = array();
     $table->head = array('');
     foreach ($readyprocessors as $processor) {
         $table->head[] = get_string('pluginname', 'message_' . $processor->name);
     }
     $number_procs = count($processors);
     // Populate the table with rows
     foreach ($providers as $provider) {
         $preferencebase = $provider->component . '_' . $provider->name;
         $headerrow = new html_table_row();
         $providername = get_string('messageprovider:' . $provider->name, $provider->component);
         $providercell = new html_table_cell($providername);
         $providercell->header = true;
         $providercell->colspan = $number_procs + 1;
         $providercell->attributes['class'] = 'c0';
         $headerrow->cells = array($providercell);
         $table->data[] = $headerrow;
         foreach (array('loggedin', 'loggedoff') as $state) {
             $optionrow = new html_table_row();
             $optionname = new html_table_cell(get_string($state . 'description', 'message'));
             $optionname->attributes['class'] = 'c0';
             $optionrow->cells = array($optionname);
             foreach ($readyprocessors as $processor) {
                 // determine the default setting
                 $permitted = MESSAGE_DEFAULT_PERMITTED;
                 $defaultpreference = $processor->name . '_provider_' . $preferencebase . '_permitted';
                 if (isset($defaultpreferences->{$defaultpreference})) {
                     $permitted = $defaultpreferences->{$defaultpreference};
                 }
                 // If settings are disallowed, just display the message that
                 // the setting is not permitted, if not use user settings or
                 // force them.
                 if ($permitted == 'disallowed') {
                     if ($state == 'loggedoff') {
                         // skip if we are rendering the second line
                         continue;
                     }
                     $cellcontent = html_writer::nonempty_tag('div', get_string('notpermitted', 'message'), array('class' => 'dimmed_text'));
                     $optioncell = new html_table_cell($cellcontent);
                     $optioncell->rowspan = 2;
                     $optioncell->attributes['class'] = 'disallowed';
                 } else {
                     // determine user preferences and use then unless we force
                     // the preferences.
                     $disabled = array();
                     if ($permitted == 'forced') {
                         $checked = true;
                         $disabled['disabled'] = 1;
                     } else {
                         $checked = false;
                         // See if hser has touched this preference
                         if (isset($preferences->{$preferencebase . '_' . $state})) {
                             // User have some preferneces for this state in the database, use them
                             $checked = isset($preferences->{$preferencebase . '_' . $state}[$processor->name]);
                         } else {
                             // User has not set this preference yet, using site default preferences set by admin
                             $defaultpreference = 'message_provider_' . $preferencebase . '_' . $state;
                             if (isset($defaultpreferences->{$defaultpreference})) {
                                 $checked = (int) in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference}));
                             }
                         }
                     }
                     $elementname = $preferencebase . '_' . $state . '[' . $processor->name . ']';
                     // prepare language bits
                     $processorname = get_string('pluginname', 'message_' . $processor->name);
                     $statename = get_string($state, 'message');
                     $labelparams = array('provider' => $providername, 'processor' => $processorname, 'state' => $statename);
                     $label = get_string('sendingviawhen', 'message', $labelparams);
                     $cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
                     $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname), $disabled));
                     $optioncell = new html_table_cell($cellcontent);
                     $optioncell->attributes['class'] = 'mdl-align';
                 }
                 $optionrow->cells[] = $optioncell;
             }
             $table->data[] = $optionrow;
         }
     }
     $output .= html_writer::start_tag('div');
     $output .= html_writer::table($table);
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('fieldset');
     foreach ($processors as $processor) {
         if (($processorconfigform = $processor->object->config_form($preferences)) && $processor->enabled) {
             $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_' . $processor->name, 'class' => 'clearfix'));
             $output .= html_writer::nonempty_tag('legend', get_string('pluginname', 'message_' . $processor->name), array('class' => 'ftoggler'));
             $output .= html_writer::start_tag('div');
             $output .= $processorconfigform;
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('fieldset');
         }
     }
     $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_general', 'class' => 'clearfix'));
     $output .= html_writer::nonempty_tag('legend', get_string('generalsettings', 'admin'), array('class' => 'ftoggler'));
     $output .= html_writer::start_tag('div');
     $output .= get_string('blocknoncontacts', 'message') . ': ';
     $output .= html_writer::checkbox('blocknoncontacts', 1, $preferences->blocknoncontacts, '');
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('fieldset');
     $output .= html_writer::start_tag('div', array('class' => 'mdl-align'));
     $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatemyprofile'), 'class' => 'form-submit'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('form');
     return $output;
 }
 public function view_bulk_certificates(moodle_url $url, array $selectedusers = null)
 {
     global $OUTPUT, $CFG, $DB;
     $course_context = context_course::instance($this->get_course()->id);
     $page = $url->get_param('page');
     $perpage = $url->get_param('perpage');
     $issuelist = $url->get_param('issuelist');
     $action = $url->get_param('action');
     $groupid = 0;
     $groupmode = groups_get_activity_groupmode($this->coursemodule);
     if ($groupmode) {
         $groupid = groups_get_activity_group($this->coursemodule, true);
     }
     $page_start = intval($page * $perpage);
     $usercount = 0;
     if (!$selectedusers) {
         $users = get_enrolled_users($course_context, '', $groupid);
         $usercount = count($users);
         $users = array_slice($users, $page_start, $perpage);
     } else {
         list($sqluserids, $params) = $DB->get_in_or_equal($selectedusers);
         $sql = "SELECT * FROM {user} WHERE id {$sqluserids}";
         //Adding sort
         $sort = '';
         $override = new stdClass();
         $override->firstname = 'firstname';
         $override->lastname = 'lastname';
         $fullnamelanguage = get_string('fullnamedisplay', '', $override);
         if ($CFG->fullnamedisplay == 'firstname lastname' or $CFG->fullnamedisplay == 'firstname' or $CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'firstname lastname') {
             $sort = " ORDER BY firstname, lastname";
         } else {
             // ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'lastname firstname')
             $sort = " ORDER BY lastname, firstname";
         }
         $users = $DB->get_records_sql($sql . $sort, $params);
     }
     if (!$action) {
         echo $OUTPUT->header();
         $this->show_tabs($url);
         groups_print_activity_menu($this->coursemodule, $url);
         $selectoptions = array('completed' => get_string('completedusers', 'simplecertificate'), 'allusers' => get_string('allusers', 'simplecertificate'));
         $select = new single_select($url, 'issuelist', $selectoptions, $issuelist);
         $select->label = get_string('showusers', 'simplecertificate');
         echo $OUTPUT->render($select);
         echo '<br>';
         echo '<form id="bulkissue" name="bulkissue" method="post" action="view.php">';
         echo html_writer::label(get_string('bulkaction', 'simplecertificate'), 'menutype', true);
         echo '&nbsp;';
         $selectoptions = array('pdf' => get_string('onepdf', 'simplecertificate'), 'zip' => get_string('multipdf', 'simplecertificate'), 'email' => get_string('sendtoemail', 'simplecertificate'));
         echo html_writer::select($selectoptions, 'type', 'pdf');
         $table = new html_table();
         $table->width = "95%";
         $table->tablealign = "center";
         //strgrade
         $table->head = array(' ', get_string('fullname'), get_string('grade'));
         $table->align = array("left", "left", "center");
         $table->size = array('1%', '89%', '10%');
         foreach ($users as $user) {
             $canissue = $this->can_issue($user, $issuelist != 'allusers');
             if (empty($canissue)) {
                 $chkbox = html_writer::checkbox('selectedusers[]', $user->id, false);
                 $name = $OUTPUT->user_picture($user) . fullname($user);
                 $table->data[] = array($chkbox, $name, $this->get_grade($user->id));
             }
         }
         $downloadbutton = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download')), get_string('bulkbuttonlabel', 'simplecertificate'));
         echo $OUTPUT->paging_bar($usercount, $page, $perpage, $url);
         echo '<br />';
         echo html_writer::table($table);
         echo html_writer::tag('div', $downloadbutton, array('style' => 'text-align: center'));
         echo '</form>';
     } else {
         if ($action == 'download') {
             $type = $url->get_param('type');
             // Calculate file name
             $filename = str_replace(' ', '_', clean_filename($this->get_instance()->coursename . ' ' . get_string('modulenameplural', 'simplecertificate') . ' ' . strip_tags(format_string($this->get_instance()->name, true)) . '.' . strip_tags(format_string($type, true))));
             switch ($type) {
                 //One pdf with all certificates
                 case 'pdf':
                     $pdf = $this->create_pdf_object();
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             //To one pdf file
                             $issuecert = $this->get_issue($user);
                             $this->create_pdf($issuecert, $pdf, true);
                             //Save certificate PDF
                             if (!$this->issue_file_exists($issuecert)) {
                                 //To force file creation
                                 $issuecert->haschage = true;
                                 $this->get_issue_file($issuecert);
                             }
                         }
                     }
                     $pdf->Output($filename, 'D');
                     break;
                     //One zip with all certificates in separated files
                 //One zip with all certificates in separated files
                 case 'zip':
                     $filesforzipping = array();
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             $issuecert = $this->get_issue($user);
                             if ($file = $this->get_issue_file($issuecert)) {
                                 $fileforzipname = $file->get_filename();
                                 $filesforzipping[$fileforzipname] = $file;
                             } else {
                                 error_log(get_string('filenotfound', 'simplecertificate'));
                                 print_error(get_string('filenotfound', 'simplecertificate'));
                             }
                         }
                     }
                     $tempzip = $this->create_temp_file('issuedcertificate_');
                     //zipping files
                     $zipper = new zip_packer();
                     if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
                         //send file and delete after sending.
                         send_temp_file($tempzip, $filename);
                     }
                     break;
                 case 'email':
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             $issuecert = $this->get_issue($user);
                             if ($this->get_issue_file($issuecert)) {
                                 $this->send_certificade_email($issuecert);
                             } else {
                                 error_log(get_string('filenotfound', 'simplecertificate'));
                                 print_error('filenotfound', 'simplecertificate');
                             }
                         }
                     }
                     $url->remove_params('action', 'type');
                     redirect($url, get_string('emailsent', 'simplecertificate'), 5);
                     break;
             }
             exit;
         }
     }
     echo $OUTPUT->footer();
 }
Ejemplo n.º 10
0
 function display_search_field($value = '')
 {
     global $CFG, $DB;
     if (is_array($value)) {
         $content = $value['selected'];
         $allrequired = $value['allrequired'] ? true : false;
     } else {
         $content = array();
         $allrequired = false;
     }
     static $c = 0;
     $str = '<label class="accesshide" for="f_' . $this->field->id . '">' . $this->field->name . '</label>';
     $str .= '<select id="f_' . $this->field->id . '" name="f_' . $this->field->id . '[]" multiple="multiple">';
     // display only used options
     $varcharcontent = $DB->sql_compare_text('content', 255);
     $sql = "SELECT DISTINCT {$varcharcontent} AS content\n                  FROM {data_content}\n                 WHERE fieldid=? AND content IS NOT NULL";
     $usedoptions = array();
     if ($used = $DB->get_records_sql($sql, array($this->field->id))) {
         foreach ($used as $data) {
             $valuestr = $data->content;
             if ($valuestr === '') {
                 continue;
             }
             $values = explode('##', $valuestr);
             foreach ($values as $value) {
                 $usedoptions[$value] = $value;
             }
         }
     }
     $found = false;
     foreach (explode("\n", $this->field->param1) as $option) {
         $option = trim($option);
         if (!isset($usedoptions[$option])) {
             continue;
         }
         $found = true;
         $str .= '<option value="' . s($option) . '"';
         if (in_array($option, $content)) {
             // Selected by user.
             $str .= ' selected = "selected"';
         }
         $str .= '>' . $option . '</option>';
     }
     if (!$found) {
         // oh, nothing to search for
         return '';
     }
     $str .= '</select>';
     $str .= html_writer::checkbox('f_' . $this->field->id . '_allreq', null, $allrequired, get_string('selectedrequired', 'data'));
     return $str;
 }
Ejemplo n.º 11
0
 /**
  * Print comments
  * @param int $page
  * @return bool return false if no comments available
  */
 public function print_comments($page = 0)
 {
     global $OUTPUT, $CFG, $OUTPUT, $DB;
     $count = $DB->count_records('comments');
     $comments = $this->get_comments($page);
     if (count($comments) == 0) {
         echo $OUTPUT->notification(get_string('nocomments', 'moodle'));
         return false;
     }
     $table = new html_table();
     $table->head = array(html_writer::checkbox('selectall', '', false, get_string('selectall'), array('id' => 'comment_select_all', 'class' => 'comment-report-selectall')), get_string('author', 'search'), get_string('content'), get_string('action'));
     $table->align = array('left', 'left', 'left', 'left');
     $table->attributes = array('class' => 'generaltable commentstable');
     $table->data = array();
     $link = new moodle_url('/comment/index.php', array('action' => 'delete', 'sesskey' => sesskey()));
     foreach ($comments as $c) {
         $this->setup_plugin($c);
         if (!empty($this->plugintype)) {
             $context_url = plugin_callback($this->plugintype, $this->pluginname, 'comment', 'url', array($c));
         }
         $checkbox = html_writer::checkbox('comments', $c->id, false);
         $action = html_writer::link(new moodle_url($link, array('commentid' => $c->id)), get_string('delete'));
         if (!empty($context_url)) {
             $action .= html_writer::empty_tag('br');
             $action .= html_writer::link($context_url, get_string('commentincontext'), array('target' => '_blank'));
         }
         $table->data[] = array($checkbox, $c->fullname, $c->content, $action);
     }
     echo html_writer::table($table);
     echo $OUTPUT->paging_bar($count, $page, $this->perpage, $CFG->wwwroot . '/comment/index.php');
     return true;
 }
Ejemplo n.º 12
0
 /**
  *
  */
 protected function get_action_icon_selectallnone()
 {
     global $PAGE;
     $PAGE->requires->js_init_call('M.mod_dataform.util.init_select_allnone', array('preset'));
     return html_writer::checkbox('presetselectallnone', null, false, null, array('id' => 'id_presetselectallnone'));
 }
Ejemplo n.º 13
0
function authorize_print_action_button($orderid, $do, $suborderid = 0, $confirm = false, $unenrol = false, $nobutton = false, $extrahtml = '')
{
    global $CFG, $OUTPUT;
    global $authstrs;
    $ret = '<form action="' . $CFG->wwwroot . '/enrol/authorize/index.php' . '" method="post"><div>' . '<input type="hidden" name="order" value="' . $orderid . '" />' . '<input type="hidden" name="do" value="' . $do . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
    if (!empty($suborderid)) {
        $ret .= '<input type="hidden" name="suborder" value="' . $suborderid . '" />';
    }
    if (!empty($confirm)) {
        $ret .= '<input type="hidden" name="confirm" value="1" />';
    }
    if (!empty($unenrol)) {
        $ret .= html_writer::checkbox('unenrol', 1, false, $unenrol) . '<br />';
    }
    $ret .= $extrahtml;
    $ret .= '<input type="submit" value="' . $authstrs->{$do} . '" />' . '</div></form>';
    if (!empty($nobutton)) {
        $ret .= '<form method="get" action="index.php"><div><input type="hidden" name="order" value="' . $orderid . '" /><input type="submit" value="' . $nobutton . '" /></div></form>';
    }
    return $ret;
}
Ejemplo n.º 14
0
    /**
     * Prints a form for configuring this authentication plugin.
     *
     * This function is called from admin/auth.php, and outputs a full page with
     * a form for configuring this plugin.
     *
     * TODO: as print_auth_lock_options() core function displays an old-fashion HTML table, I didn't bother writing
     * some proper Moodle code. This code is similar to other auth plugins (04/09/11)
     *
     * @param array $page An object containing all the data for this page.
     */
    public function config_form($config, $err, $userfields)
    {
        global $OUTPUT, $CFG;
        echo '<div class="alert alert-success"  role="alert">' . get_string('supportmaintenance', 'auth_googleoauth2') . '</div>';
        // TODO: replace this table html ugliness by some nice bootstrap html code.
        echo '<table cellspacing="0" cellpadding="5" border="0">
            <tr>
               <td colspan="3">
                    <h2 class="main">';
        print_string('auth_googlesettings', 'auth_googleoauth2');
        $providers = provider_list();
        foreach ($providers as $providername) {
            $clientidname = $providername . 'clientid';
            $clientsecretname = $providername . 'clientsecret';
            // Set to defaults if undefined.
            if (!isset($config->{$clientidname})) {
                $config->{$clientidname} = '';
            }
            if (!isset($config->{$clientsecretname})) {
                $config->{$clientsecretname} = '';
            }
            // Client id.
            echo '</h2>
               </td>
            </tr>
            <tr  style="vertical-align: top;">
                <td align="right"><label for="' . $clientidname . '">';
            print_string('auth_' . $clientidname . '_key', 'auth_googleoauth2');
            echo '</label></td><td>';
            echo html_writer::empty_tag('input', array('type' => 'text', 'id' => $clientidname, 'name' => $clientidname, 'class' => $clientidname, 'value' => $config->{$clientidname}));
            if (isset($err[$clientidname])) {
                echo $OUTPUT->error_text($err[$clientidname]);
            }
            echo '</td><td>';
            $parse = parse_url($CFG->wwwroot);
            print_string('auth_' . $clientidname, 'auth_googleoauth2', array('jsorigins' => $parse['scheme'] . '://' . $parse['host'], 'siteurl' => $CFG->httpswwwroot, 'domain' => $CFG->httpswwwroot, 'redirecturls' => $CFG->httpswwwroot . '/auth/googleoauth2/' . $providername . '_redirect.php', 'callbackurl' => $CFG->httpswwwroot . '/auth/googleoauth2/' . $providername . '_redirect.php', 'sitedomain' => $parse['host']));
            echo '</td></tr>';
            // Client secret.
            echo '<tr  style="vertical-align: top;">
                <td align="right"><label for="' . $clientsecretname . '">';
            print_string('auth_' . $clientsecretname . '_key', 'auth_googleoauth2');
            echo '</label></td><td>';
            echo html_writer::empty_tag('input', array('type' => 'text', 'id' => $clientsecretname, 'name' => $clientsecretname, 'class' => $clientsecretname, 'value' => $config->{$clientsecretname}));
            if (isset($err[$clientsecretname])) {
                echo $OUTPUT->error_text($err[$clientsecretname]);
            }
            echo '</td><td>';
            print_string('auth_' . $clientsecretname, 'auth_googleoauth2');
            echo '</td></tr>
            <tr style="min-height: 20px"><td>&nbsp;</td></tr>';
        }
        if (!isset($config->googleipinfodbkey)) {
            $config->googleipinfodbkey = '';
        }
        if (!isset($config->googleuserprefix)) {
            $config->googleuserprefix = 'social_user_';
        }
        if (!isset($config->oauth2displaybuttons)) {
            $config->oauth2displaybuttons = 1;
        }
        // IPinfoDB.
        echo '<tr>
                <td align="right"><label for="googleipinfodbkey">';
        print_string('auth_googleipinfodbkey_key', 'auth_googleoauth2');
        echo '</label></td><td>';
        echo html_writer::empty_tag('input', array('type' => 'text', 'id' => 'googleipinfodbkey', 'name' => 'googleipinfodbkey', 'class' => 'googleipinfodbkey', 'value' => $config->googleipinfodbkey));
        if (isset($err["googleipinfodbkey"])) {
            echo $OUTPUT->error_text($err["googleipinfodbkey"]);
        }
        echo '</td><td>';
        print_string('auth_googleipinfodbkey', 'auth_googleoauth2', (object) array('website' => $CFG->wwwroot));
        echo '</td></tr>';
        // User prefix.
        echo '<tr>
                <td align="right"><label for="googleuserprefix">';
        print_string('auth_googleuserprefix_key', 'auth_googleoauth2');
        echo '</label></td><td>';
        echo html_writer::empty_tag('input', array('type' => 'text', 'id' => 'googleuserprefix', 'name' => 'googleuserprefix', 'class' => 'googleuserprefix', 'value' => $config->googleuserprefix));
        if (isset($err["googleuserprefix"])) {
            echo $OUTPUT->error_text($err["googleuserprefix"]);
        }
        echo '</td><td>';
        print_string('auth_googleuserprefix', 'auth_googleoauth2');
        echo '</td></tr>';
        // Display buttons.
        echo '<tr>
                <td align="right"><label for="oauth2displaybuttons">';
        print_string('oauth2displaybuttons', 'auth_googleoauth2');
        echo '</label></td><td>';
        $checked = empty($config->oauth2displaybuttons) ? '' : 'checked';
        echo html_writer::checkbox('oauth2displaybuttons', 1, $checked, '', array('type' => 'checkbox', 'id' => 'oauth2displaybuttons', 'class' => 'oauth2displaybuttons'));
        if (isset($err["oauth2displaybuttons"])) {
            echo $OUTPUT->error_text($err["oauth2displaybuttons"]);
        }
        echo '</td><td>';
        $code = '<code>&lt;?php require_once($CFG-&gt;dirroot . \'/auth/googleoauth2/lib.php\');
                auth_googleoauth2_display_buttons(); ?&gt;</code>';
        print_string('oauth2displaybuttonshelp', 'auth_googleoauth2', $code);
        echo '</td></tr>';
        // Block field options.
        // Hidden email options - email must be set to: locked.
        echo html_writer::empty_tag('input', array('type' => 'hidden', 'value' => 'locked', 'name' => 'lockconfig_field_lock_email'));
        // Display other field options.
        foreach ($userfields as $key => $userfield) {
            if ($userfield == 'email') {
                unset($userfields[$key]);
            }
        }
        print_auth_lock_options('googleoauth2', $userfields, get_string('auth_fieldlocks_help', 'auth'), false, false);
        echo '</table>';
        // Calculate how many login per providers.
        $providerstats = (object) $this->get_stats();
        $strothermoodle = get_string('othermoodle', 'auth_googleoauth2');
        $strstattitle = get_string('stattitle', 'auth_googleoauth2', $providerstats);
        echo '
            <center>
            <script type="text/javascript" src="https://www.google.com/jsapi"></script>
                <script type="text/javascript">
                  google.load("visualization", "1", {packages:["corechart"]});
                  google.setOnLoadCallback(drawChart);
                  function drawChart() {

                    var data = google.visualization.arrayToDataTable([
                      [\'Provider\', \'Login total\'],
                      [\'Google\', ' . $providerstats->google . '],
                      [\'Facebook\', ' . $providerstats->facebook . ' ],
                      [\'Github\',  ' . $providerstats->github . ' ],
                      [\'Linkedin\', ' . $providerstats->linkedin . ' ],
                      [\'Microsoft\', ' . $providerstats->microsoft . ' ],
                      [\'Dropbox\', ' . $providerstats->dropbox . ' ],
                      [\'VK\', ' . $providerstats->vk . ' ],
                      [\'Battle.net\', ' . $providerstats->battlenet . ' ],
                      [\'' . $strothermoodle . '\',    ' . $providerstats->moodle . ' ]
                    ]);

                    var options = {
                      title: \'' . $strstattitle . '\',
                      is3D: true,
                      slices: {
                        0: { color: \'#D50F25\' },
                        1: { color: \'#3b5998\' },
                        2: { color: \'#eee\', fontcolor: \'black\'},
                        3: { color: \'#007bb6\'},
                        4: { color: \'#7cbb00\'},
                        5: { color: \'#007ee5\'},
                        6: { color: \'#45668e\'},
                        7: { color: \'#00B4FF\'},
                        8: { color: \'#ee7600\'}
                      }
                    };

                    var chart = new google.visualization.PieChart(document.getElementById(\'piechart\'));

                    chart.draw(data, options);
                  }
                </script>
             <div id="piechart" style="width: 900px; height: 500px;"></div>
            </center>
        ';
    }
Ejemplo n.º 15
0
/**
 * Called by course/reset.php and shows the formdata by coursereset.
 * it prints checkboxes for each feedback available at the given course
 * there are two checkboxes:
 * 1) delete userdata and keep the feedback
 * 2) delete userdata and drop the feedback
 *
 * @global object
 * @uses FEEDBACK_RESETFORM_RESET
 * @uses FEEDBACK_RESETFORM_DROP
 * @param object $course
 * @return void
 */
function feedback_reset_course_form($course) {
    global $DB, $OUTPUT;

    echo get_string('resetting_feedbacks', 'feedback'); echo ':<br />';
    if (!$feedbacks = $DB->get_records('feedback', array('course'=>$course->id), 'name')) {
        return;
    }

    foreach ($feedbacks as $feedback) {
        echo '<p>';
        echo get_string('name', 'feedback').': '.$feedback->name.'<br />';
        echo html_writer::checkbox(FEEDBACK_RESETFORM_RESET.$feedback->id,
                                1, true,
                                get_string('resetting_data', 'feedback'));
        echo '<br />';
        echo html_writer::checkbox(FEEDBACK_RESETFORM_DROP.$feedback->id,
                                1, false,
                                get_string('drop_feedback', 'feedback'));
        echo '</p>';
    }
}
Ejemplo n.º 16
0
/**
 * Display an standard html checkbox with an optional label
 *
 * @deprecated since Moodle 2.0
 *
 * @staticvar int $idcounter
 * @param string $name    The name of the checkbox
 * @param string $value   The valus that the checkbox will pass when checked
 * @param bool $checked The flag to tell the checkbox initial state
 * @param string $label   The label to be showed near the checkbox
 * @param string $alt     The info to be inserted in the alt tag
 * @param string $script If not '', then this is added to the checkbox element
 *                       as an onchange handler.
 * @param bool $return Whether this function should return a string or output
 *                     it (defaults to false)
 * @return string|void If $return=true returns string, else echo's and returns void
 */
function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {

    // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
    global $OUTPUT;

    if (!empty($script)) {
        debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
    }

    $output = html_writer::checkbox($name, $value, $checked, $label);

    if (empty($return)) {
        echo $output;
    } else {
        return $output;
    }

}
Ejemplo n.º 17
0
 /**
  * displays the full report
  * @param \stdClass $scorm full SCORM object
  * @param \stdClass $cm - full course_module object
  * @param \stdClass $course - full course object
  * @param string $download - type of download being requested
  */
 public function display($scorm, $cm, $course, $download)
 {
     global $CFG, $DB, $OUTPUT, $PAGE;
     $contextmodule = \context_module::instance($cm->id);
     $action = optional_param('action', '', PARAM_ALPHA);
     $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
     $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
     $PAGE->set_url(new \moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
     if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
         if (scorm_delete_responses($attemptids, $scorm)) {
             // Delete responses.
             echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
         }
     }
     // Find out current groups mode.
     $currentgroup = groups_get_activity_group($cm, true);
     // Detailed report.
     $mform = new \mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup'));
     if ($fromform = $mform->get_data()) {
         $pagesize = $fromform->pagesize;
         $showobjectivescore = $fromform->objectivescore;
         set_user_preference('scorm_report_pagesize', $pagesize);
         set_user_preference('scorm_report_objectives_score', $showobjectivescore);
     } else {
         $pagesize = get_user_preferences('scorm_report_pagesize', 0);
         $showobjectivescore = get_user_preferences('scorm_report_objectives_score', 0);
     }
     if ($pagesize < 1) {
         $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
     }
     // Select group menu.
     $displayoptions = array();
     $displayoptions['attemptsmode'] = $attemptsmode;
     $displayoptions['objectivescore'] = $showobjectivescore;
     $mform->set_data($displayoptions + array('pagesize' => $pagesize));
     if ($groupmode = groups_get_activity_groupmode($cm)) {
         // Groups are being used.
         if (!$download) {
             groups_print_activity_menu($cm, new \moodle_url($PAGE->url, $displayoptions));
         }
     }
     $formattextoptions = array('context' => \context_course::instance($course->id));
     // We only want to show the checkbox to delete attempts
     // if the user has permissions and if the report mode is showing attempts.
     $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule) && $attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
     // Select the students.
     $nostudents = false;
     if (empty($currentgroup)) {
         // All users who can attempt scoes.
         if (!($students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false))) {
             echo $OUTPUT->notification(get_string('nostudentsyet'));
             $nostudents = true;
             $allowedlist = '';
         } else {
             $allowedlist = array_keys($students);
         }
         unset($students);
     } else {
         // All users who can attempt scoes and who are in the currently selected group.
         $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', $currentgroup, '', false);
         if (!$groupstudents) {
             echo $OUTPUT->notification(get_string('nostudentsingroup'));
             $nostudents = true;
             $groupstudents = array();
         }
         $allowedlist = array_keys($groupstudents);
         unset($groupstudents);
     }
     if (!$nostudents) {
         // Now check if asked download of data.
         $coursecontext = \context_course::instance($course->id);
         if ($download) {
             $filename = clean_filename("{$course->shortname} " . format_string($scorm->name, true, $formattextoptions));
         }
         // Define table columns.
         $columns = array();
         $headers = array();
         if (!$download && $candelete) {
             $columns[] = 'checkbox';
             $headers[] = null;
         }
         if (!$download && $CFG->grade_report_showuserimage) {
             $columns[] = 'picture';
             $headers[] = '';
         }
         $columns[] = 'fullname';
         $headers[] = get_string('name');
         $extrafields = get_extra_user_fields($coursecontext);
         foreach ($extrafields as $field) {
             $columns[] = $field;
             $headers[] = get_user_field_name($field);
         }
         $columns[] = 'attempt';
         $headers[] = get_string('attempt', 'scorm');
         $columns[] = 'start';
         $headers[] = get_string('started', 'scorm');
         $columns[] = 'finish';
         $headers[] = get_string('last', 'scorm');
         $columns[] = 'score';
         $headers[] = get_string('score', 'scorm');
         $scoes = $DB->get_records('scorm_scoes', array("scorm" => $scorm->id), 'sortorder, id');
         foreach ($scoes as $sco) {
             if ($sco->launch != '') {
                 $columns[] = 'scograde' . $sco->id;
                 $headers[] = format_string($sco->title, '', $formattextoptions);
             }
         }
         $params = array();
         list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED);
         // Construct the SQL.
         $select = 'SELECT DISTINCT ' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ' AS uniqueid, ';
         $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . \user_picture::fields('u', array('idnumber'), 'userid') . get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' ';
         // This part is the same for all cases - join users and scorm_scoes_track tables.
         $from = 'FROM {user} u ';
         $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = ' . $scorm->id;
         switch ($attemptsmode) {
             case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
                 // Show only students with attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NOT NULL';
                 break;
             case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
                 // Show only students without attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND st.userid IS NULL';
                 break;
             case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
                 // Show all students with or without attempts.
                 $where = ' WHERE u.id ' . $usql . ' AND (st.userid IS NOT NULL OR st.userid IS NULL)';
                 break;
         }
         $countsql = 'SELECT COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)') . ')) AS nbresults, ';
         $countsql .= 'COUNT(DISTINCT(' . $DB->sql_concat('u.id', '\'#\'', 'st.attempt') . ')) AS nbattempts, ';
         $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
         $countsql .= $from . $where;
         $nbmaincolumns = count($columns);
         // Get number of main columns used.
         $objectives = get_scorm_objectives($scorm->id);
         $nosort = array();
         foreach ($objectives as $scoid => $sco) {
             foreach ($sco as $id => $objectivename) {
                 $colid = $scoid . 'objectivestatus' . $id;
                 $columns[] = $colid;
                 $nosort[] = $colid;
                 if (!$displayoptions['objectivescore']) {
                     // Display the objective name only.
                     $headers[] = $objectivename;
                 } else {
                     // Display the objective status header with a "status" suffix to avoid confusion.
                     $headers[] = $objectivename . ' ' . get_string('status', 'scormreport_objectives');
                     // Now print objective score headers.
                     $colid = $scoid . 'objectivescore' . $id;
                     $columns[] = $colid;
                     $nosort[] = $colid;
                     $headers[] = $objectivename . ' ' . get_string('score', 'scormreport_objectives');
                 }
             }
         }
         $emptycell = '';
         // Used when an empty cell is being printed - in html we add a space.
         if (!$download) {
             $emptycell = '&nbsp;';
             $table = new \flexible_table('mod-scorm-report');
             $table->define_columns($columns);
             $table->define_headers($headers);
             $table->define_baseurl($PAGE->url);
             $table->sortable(true);
             $table->collapsible(true);
             // This is done to prevent redundant data, when a user has multiple attempts.
             $table->column_suppress('picture');
             $table->column_suppress('fullname');
             foreach ($extrafields as $field) {
                 $table->column_suppress($field);
             }
             foreach ($nosort as $field) {
                 $table->no_sorting($field);
             }
             $table->no_sorting('start');
             $table->no_sorting('finish');
             $table->no_sorting('score');
             $table->no_sorting('checkbox');
             $table->no_sorting('picture');
             foreach ($scoes as $sco) {
                 if ($sco->launch != '') {
                     $table->no_sorting('scograde' . $sco->id);
                 }
             }
             $table->column_class('picture', 'picture');
             $table->column_class('fullname', 'bold');
             $table->column_class('score', 'bold');
             $table->set_attribute('cellspacing', '0');
             $table->set_attribute('id', 'attempts');
             $table->set_attribute('class', 'generaltable generalbox');
             // Start working -- this is necessary as soon as the niceties are over.
             $table->setup();
         } else {
             if ($download == 'ODS') {
                 require_once "{$CFG->libdir}/odslib.class.php";
                 $filename .= ".ods";
                 // Creating a workbook.
                 $workbook = new \MoodleODSWorkbook("-");
                 // Sending HTTP headers.
                 $workbook->send($filename);
                 // Creating the first worksheet.
                 $sheettitle = get_string('report', 'scorm');
                 $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');
                 // Here starts workshhet headers.
                 $colnum = 0;
                 foreach ($headers as $item) {
                     $myxls->write(0, $colnum, $item, $formatbc);
                     $colnum++;
                 }
                 $rownum = 1;
             } else {
                 if ($download == '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('report', 'scorm');
                     $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');
                     $colnum = 0;
                     foreach ($headers as $item) {
                         $myxls->write(0, $colnum, $item, $formatbc);
                         $colnum++;
                     }
                     $rownum = 1;
                 } else {
                     if ($download == 'CSV') {
                         $csvexport = new \csv_export_writer("tab");
                         $csvexport->set_filename($filename, ".txt");
                         $csvexport->add_data($headers);
                     }
                 }
             }
         }
         if (!$download) {
             $sort = $table->get_sql_sort();
         } else {
             $sort = '';
         }
         // Fix some wired sorting.
         if (empty($sort)) {
             $sort = ' ORDER BY uniqueid';
         } else {
             $sort = ' ORDER BY ' . $sort;
         }
         if (!$download) {
             // Add extra limits due to initials bar.
             list($twhere, $tparams) = $table->get_sql_where();
             if ($twhere) {
                 $where .= ' AND ' . $twhere;
                 // Initial bar.
                 $params = array_merge($params, $tparams);
             }
             if (!empty($countsql)) {
                 $count = $DB->get_record_sql($countsql, $params);
                 $totalinitials = $count->nbresults;
                 if ($twhere) {
                     $countsql .= ' AND ' . $twhere;
                 }
                 $count = $DB->get_record_sql($countsql, $params);
                 $total = $count->nbresults;
             }
             $table->pagesize($pagesize, $total);
             echo \html_writer::start_div('scormattemptcounts');
             if ($count->nbresults == $count->nbattempts) {
                 echo get_string('reportcountattempts', 'scorm', $count);
             } else {
                 if ($count->nbattempts > 0) {
                     echo get_string('reportcountallattempts', 'scorm', $count);
                 } else {
                     echo $count->nbusers . ' ' . get_string('users');
                 }
             }
             echo \html_writer::end_div();
         }
         // Fetch the attempts.
         if (!$download) {
             $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, $table->get_page_start(), $table->get_page_size());
             echo \html_writer::start_div('', array('id' => 'scormtablecontainer'));
             if ($candelete) {
                 // Start form.
                 $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
                 echo \html_writer::start_tag('form', array('id' => 'attemptsform', 'method' => 'post', 'action' => $PAGE->url->out(false), 'onsubmit' => 'return confirm("' . $strreallydel . '");'));
                 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
                 echo \html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
                 echo \html_writer::start_div('', array('style' => 'display: none;'));
                 echo \html_writer::input_hidden_params($PAGE->url);
                 echo \html_writer::end_div();
                 echo \html_writer::start_div();
             }
             $table->initialbars($totalinitials > 20);
             // Build table rows.
         } else {
             $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params);
         }
         if ($attempts) {
             foreach ($attempts as $scouser) {
                 $row = array();
                 if (!empty($scouser->attempt)) {
                     $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
                 } else {
                     $timetracks = '';
                 }
                 if (in_array('checkbox', $columns)) {
                     if ($candelete && !empty($timetracks->start)) {
                         $row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false);
                     } else {
                         if ($candelete) {
                             $row[] = '';
                         }
                     }
                 }
                 if (in_array('picture', $columns)) {
                     $user = new \stdClass();
                     $additionalfields = explode(',', \user_picture::fields());
                     $user = username_load_fields_from_object($user, $scouser, null, $additionalfields);
                     $user->id = $scouser->userid;
                     $row[] = $OUTPUT->user_picture($user, array('courseid' => $course->id));
                 }
                 if (!$download) {
                     $url = new \moodle_url('/user/view.php', array('id' => $scouser->userid, 'course' => $course->id));
                     $row[] = \html_writer::link($url, fullname($scouser));
                 } else {
                     $row[] = fullname($scouser);
                 }
                 foreach ($extrafields as $field) {
                     $row[] = s($scouser->{$field});
                 }
                 if (empty($timetracks->start)) {
                     $row[] = '-';
                     $row[] = '-';
                     $row[] = '-';
                     $row[] = '-';
                 } else {
                     if (!$download) {
                         $url = new \moodle_url('/mod/scorm/report/userreport.php', array('id' => $cm->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
                         $row[] = \html_writer::link($url, $scouser->attempt);
                     } else {
                         $row[] = $scouser->attempt;
                     }
                     if ($download == 'ODS' || $download == 'Excel') {
                         $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
                     } else {
                         $row[] = userdate($timetracks->start);
                     }
                     if ($download == 'ODS' || $download == 'Excel') {
                         $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
                     } else {
                         $row[] = userdate($timetracks->finish);
                     }
                     $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
                 }
                 // Print out all scores of attempt.
                 foreach ($scoes as $sco) {
                     if ($sco->launch != '') {
                         if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
                             if ($trackdata->status == '') {
                                 $trackdata->status = 'notattempted';
                             }
                             $strstatus = get_string($trackdata->status, 'scorm');
                             if ($trackdata->score_raw != '') {
                                 // If raw score exists, print it.
                                 $score = $trackdata->score_raw;
                                 // Add max score if it exists.
                                 if (isset($trackdata->score_max)) {
                                     $score .= '/' . $trackdata->score_max;
                                 }
                             } else {
                                 // ...else print out status.
                                 $score = $strstatus;
                             }
                             if (!$download) {
                                 $url = new \moodle_url('/mod/scorm/report/userreporttracks.php', array('id' => $cm->id, 'scoid' => $sco->id, 'user' => $scouser->userid, 'attempt' => $scouser->attempt));
                                 $row[] = \html_writer::img($OUTPUT->pix_url($trackdata->status, 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . \html_writer::link($url, $score, array('title' => get_string('details', 'scorm')));
                             } else {
                                 $row[] = $score;
                             }
                             // Iterate over tracks and match objective id against values.
                             $scorm2004 = false;
                             if (scorm_version_check($scorm->version, SCORM_13)) {
                                 $scorm2004 = true;
                                 $objectiveprefix = "cmi.objectives.";
                             } else {
                                 $objectiveprefix = "cmi.objectives_";
                             }
                             $keywords = array(".id", $objectiveprefix);
                             $objectivestatus = array();
                             $objectivescore = array();
                             foreach ($trackdata as $name => $value) {
                                 if (strpos($name, $objectiveprefix) === 0 && strrpos($name, '.id') !== false) {
                                     $num = trim(str_ireplace($keywords, '', $name));
                                     if (is_numeric($num)) {
                                         if ($scorm2004) {
                                             $element = $objectiveprefix . $num . '.completion_status';
                                         } else {
                                             $element = $objectiveprefix . $num . '.status';
                                         }
                                         if (isset($trackdata->{$element})) {
                                             $objectivestatus[$value] = $trackdata->{$element};
                                         } else {
                                             $objectivestatus[$value] = '';
                                         }
                                         if ($displayoptions['objectivescore']) {
                                             $element = $objectiveprefix . $num . '.score.raw';
                                             if (isset($trackdata->{$element})) {
                                                 $objectivescore[$value] = $trackdata->{$element};
                                             } else {
                                                 $objectivescore[$value] = '';
                                             }
                                         }
                                     }
                                 }
                             }
                             // Interaction data.
                             if (!empty($objectives[$trackdata->scoid])) {
                                 foreach ($objectives[$trackdata->scoid] as $name) {
                                     if (isset($objectivestatus[$name])) {
                                         $row[] = s($objectivestatus[$name]);
                                     } else {
                                         $row[] = $emptycell;
                                     }
                                     if ($displayoptions['objectivescore']) {
                                         if (isset($objectivescore[$name])) {
                                             $row[] = s($objectivescore[$name]);
                                         } else {
                                             $row[] = $emptycell;
                                         }
                                     }
                                 }
                             }
                             // End of interaction data.
                         } else {
                             // If we don't have track data, we haven't attempted yet.
                             $strstatus = get_string('notattempted', 'scorm');
                             if (!$download) {
                                 $row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . $strstatus;
                             } else {
                                 $row[] = $strstatus;
                             }
                             // Complete the empty cells.
                             for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) {
                                 $row[] = $emptycell;
                             }
                         }
                     }
                 }
                 if (!$download) {
                     $table->add_data($row);
                 } else {
                     if ($download == 'Excel' or $download == 'ODS') {
                         $colnum = 0;
                         foreach ($row as $item) {
                             $myxls->write($rownum, $colnum, $item, $format);
                             $colnum++;
                         }
                         $rownum++;
                     } else {
                         if ($download == 'CSV') {
                             $csvexport->add_data($row);
                         }
                     }
                 }
             }
             if (!$download) {
                 $table->finish_output();
                 if ($candelete) {
                     echo \html_writer::start_tag('table', array('id' => 'commands'));
                     echo \html_writer::start_tag('tr') . \html_writer::start_tag('td');
                     echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')) . ' / ';
                     echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm'));
                     echo '&nbsp;&nbsp;';
                     echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'scorm'), 'class' => 'btn btn-secondary'));
                     echo \html_writer::end_tag('td') . \html_writer::end_tag('tr') . \html_writer::end_tag('table');
                     // Close form.
                     echo \html_writer::end_tag('div');
                     echo \html_writer::end_tag('form');
                 }
                 echo \html_writer::end_div();
                 if (!empty($attempts)) {
                     echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')) . \html_writer::start_tag('tr');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext'), 'post', ['class' => 'm-t-1']);
                     echo \html_writer::end_tag('td');
                     echo \html_writer::start_tag('td');
                     echo \html_writer::end_tag('td');
                     echo \html_writer::end_tag('tr') . \html_writer::end_tag('table');
                 }
             }
         } else {
             if ($candelete && !$download) {
                 echo \html_writer::end_div();
                 echo \html_writer::end_tag('form');
                 $table->finish_output();
             }
             echo \html_writer::end_div();
         }
         // Show preferences form irrespective of attempts are there to report or not.
         if (!$download) {
             $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
             $mform->display();
         }
         if ($download == 'Excel' or $download == 'ODS') {
             $workbook->close();
             exit;
         } else {
             if ($download == 'CSV') {
                 $csvexport->download_file();
                 exit;
             }
         }
     } else {
         echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
     }
 }
Ejemplo n.º 18
0
    /**
     *  Display all the submissions ready for grading
     *
     * @global object
     * @global object
     * @global object
     * @global object
     * @param string $message
     * @return bool|void
     */
    function display_submissions($message='') {
        global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE;
        require_once($CFG->libdir.'/gradelib.php');

        /* first we check to see if the form has just been submitted
         * to request user_preference updates
         */

       $filters = array(self::FILTER_ALL             => get_string('all'),
                        self::FILTER_SUBMITTED       => get_string('submitted', 'assignment'),
                        self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment'));

        $updatepref = optional_param('updatepref', 0, PARAM_INT);

        if (isset($_POST['updatepref'])){
            $perpage = optional_param('perpage', 10, PARAM_INT);
            $perpage = ($perpage <= 0) ? 10 : $perpage ;
            $filter = optional_param('filter', 0, PARAM_INT);
            set_user_preference('assignment_perpage', $perpage);
            set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
            set_user_preference('assignment_filter', $filter);
        }

        /* next we get perpage and quickgrade (allow quick grade) params
         * from database
         */
        $perpage    = get_user_preferences('assignment_perpage', 10);
        $quickgrade = get_user_preferences('assignment_quickgrade', 0);
        $filter = get_user_preferences('assignment_filter', 0);
        $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);

        if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
            $uses_outcomes = true;
        } else {
            $uses_outcomes = false;
        }

        $page    = optional_param('page', 0, PARAM_INT);
        $strsaveallfeedback = get_string('saveallfeedback', 'assignment');

    /// Some shortcuts to make the code read better

        $course     = $this->course;
        $assignment = $this->assignment;
        $cm         = $this->cm;

        $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
        add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id, $this->assignment->id, $this->cm->id);

        $PAGE->set_title(format_string($this->assignment->name,true));
        $PAGE->set_heading($this->course->fullname);
        echo $OUTPUT->header();

        echo '<div class="usersubmissions">';

        //hook to allow plagiarism plugins to update status/print links.
        plagiarism_update_status($this->course, $this->cm);

        /// Print quickgrade form around the table
        if ($quickgrade) {
            $formattrs = array();
            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
            $formattrs['id'] = 'fastg';
            $formattrs['method'] = 'post';

            echo html_writer::start_tag('form', $formattrs);
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
        }

        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
                . get_string('seeallcoursegrades', 'grades') . '</a></div>';
        }

        if (!empty($message)) {
            echo $message;   // display messages here if any
        }

        $context = get_context_instance(CONTEXT_MODULE, $cm->id);

    /// Check to see if groups are being used in this assignment

        /// find out current groups mode
        $groupmode = groups_get_activity_groupmode($cm);
        $currentgroup = groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);

        /// Get all ppl that are allowed to submit assignments
        list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup);

        if ($filter == self::FILTER_ALL) {
            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "WHERE u.deleted = 0 AND eu.id=u.id ";
        } else {
            $wherefilter = '';
            if($filter == self::FILTER_SUBMITTED) {
               $wherefilter = ' AND s.timemodified > 0';
            } else if($filter == self::FILTER_REQUIRE_GRADING) {
                $wherefilter = ' AND s.timemarked < s.timemodified ';
            }

            $sql = "SELECT u.id FROM {user} u ".
                   "LEFT JOIN ($esql) eu ON eu.id=u.id ".
                   "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " .
                   "WHERE u.deleted = 0 AND eu.id=u.id ".
                   'AND s.assignment = '. $this->assignment->id .
                    $wherefilter;
        }

        $users = $DB->get_records_sql($sql, $params);
        if (!empty($users)) {
            $users = array_keys($users);
        }

        // if groupmembersonly used, remove users who are not in any group
        if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
            if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
                $users = array_intersect($users, array_keys($groupingusers));
            }
        }

        $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
        if ($uses_outcomes) {
            $tablecolumns[] = 'outcome'; // no sorting based on outcomes column
        }

        $tableheaders = array('',
                              get_string('fullname'),
                              get_string('grade'),
                              get_string('comment', 'assignment'),
                              get_string('lastmodified').' ('.get_string('submission', 'assignment').')',
                              get_string('lastmodified').' ('.get_string('grade').')',
                              get_string('status'),
                              get_string('finalgrade', 'grades'));
        if ($uses_outcomes) {
            $tableheaders[] = get_string('outcome', 'grades');
        }

        require_once($CFG->libdir.'/tablelib.php');
        $table = new flexible_table('mod-assignment-submissions');

        $table->define_columns($tablecolumns);
        $table->define_headers($tableheaders);
        $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);

        $table->sortable(true, 'lastname');//sorted by lastname by default
        $table->collapsible(true);
        $table->initialbars(true);

        $table->column_suppress('picture');
        $table->column_suppress('fullname');

        $table->column_class('picture', 'picture');
        $table->column_class('fullname', 'fullname');
        $table->column_class('grade', 'grade');
        $table->column_class('submissioncomment', 'comment');
        $table->column_class('timemodified', 'timemodified');
        $table->column_class('timemarked', 'timemarked');
        $table->column_class('status', 'status');
        $table->column_class('finalgrade', 'finalgrade');
        if ($uses_outcomes) {
            $table->column_class('outcome', 'outcome');
        }

        $table->set_attribute('cellspacing', '0');
        $table->set_attribute('id', 'attempts');
        $table->set_attribute('class', 'submissions');
        $table->set_attribute('width', '100%');
        //$table->set_attribute('align', 'center');

        $table->no_sorting('finalgrade');
        $table->no_sorting('outcome');

        // Start working -- this is necessary as soon as the niceties are over
        $table->setup();

        if (empty($users)) {
            echo $OUTPUT->heading(get_string('nosubmitusers','assignment'));
            echo '</div>';
            return true;
        }
        if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak)
            echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&amp;download=zip">'.get_string('downloadall', 'assignment').'</a></div>';
        }
    /// Construct the SQL

        list($where, $params) = $table->get_sql_where();
        if ($where) {
            $where .= ' AND ';
        }

        if ($filter == self::FILTER_SUBMITTED) {
           $where .= 's.timemodified > 0 AND ';
        } else if($filter == self::FILTER_REQUIRE_GRADING) {
           $where .= 's.timemarked < s.timemodified AND ';
        }

        if ($sort = $table->get_sql_sort()) {
            $sort = ' ORDER BY '.$sort;
        }

        $ufields = user_picture::fields('u');

        $select = "SELECT $ufields,
                          s.id AS submissionid, s.grade, s.submissioncomment,
                          s.timemodified, s.timemarked,
                          COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ";
        $sql = 'FROM {user} u '.
               'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                AND s.assignment = '.$this->assignment->id.' '.
               'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';

        $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());

        $table->pagesize($perpage, count($users));

        ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
        $offset = $page * $perpage;
        $strupdate = get_string('update');
        $strgrade  = get_string('grade');
        $grademenu = make_grades_menu($this->assignment->grade);

        if ($ausers !== false) {
            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
            $endposition = $offset + $perpage;
            $currentposition = 0;
            foreach ($ausers as $auser) {
                if ($currentposition == $offset && $offset < $endposition) {
                    $final_grade = $grading_info->items[0]->grades[$auser->id];
                    $grademax = $grading_info->items[0]->grademax;
                    $final_grade->formatted_grade = round($final_grade->grade,2) .' / ' . round($grademax,2);
                    $locked_overridden = 'locked';
                    if ($final_grade->overridden) {
                        $locked_overridden = 'overridden';
                    }

                /// Calculate user status
                    $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified);
                    $picture = $OUTPUT->user_picture($auser);

                    if (empty($auser->submissionid)) {
                        $auser->grade = -1; //no submission yet
                    }

                    if (!empty($auser->submissionid)) {
                    ///Prints student answer and student modified date
                    ///attach file or print link to student answer, depending on the type of the assignment.
                    ///Refer to print_student_answer in inherited classes.
                        if ($auser->timemodified > 0) {
                            $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id)
                                             . userdate($auser->timemodified).'</div>';
                        } else {
                            $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        }
                    ///Print grade, dropdown or text
                        if ($auser->timemarked > 0) {
                            $teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>';

                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'. $menu .'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }

                        } else {
                            $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                            if ($final_grade->locked or $final_grade->overridden) {
                                $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>';
                            } else if ($quickgrade) {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                                $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                            } else {
                                $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>';
                            }
                        }
                    ///Print Comment
                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';

                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>';
                        }
                    } else {
                        $studentmodified = '<div id="ts'.$auser->id.'">&nbsp;</div>';
                        $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                        $status          = '<div id="st'.$auser->id.'">&nbsp;</div>';

                        if ($final_grade->locked or $final_grade->overridden) {
                            $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>';
                        } else if ($quickgrade) {   // allow editing
                            $attributes = array();
                            $attributes['tabindex'] = $tabindex++;
                            $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes);
                            $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>';
                        } else {
                            $grade = '<div id="g'.$auser->id.'">-</div>';
                        }

                        if ($final_grade->locked or $final_grade->overridden) {
                            $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>';
                        } else if ($quickgrade) {
                            $comment = '<div id="com'.$auser->id.'">'
                                     . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment'
                                     . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>';
                        } else {
                            $comment = '<div id="com'.$auser->id.'">&nbsp;</div>';
                        }
                    }

                    if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1
                        $auser->status = 0;
                    } else {
                        $auser->status = 1;
                    }

                    $buttontext = ($auser->status == 1) ? $strupdate : $strgrade;

                    ///No more buttons, we use popups ;-).
                    $popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id
                               . '&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;filter='.$filter.'&amp;offset='.$offset++;

                    $button = $OUTPUT->action_link($popup_url, $buttontext);

                    $status  = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';

                    $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';

                    $outcomes = '';

                    if ($uses_outcomes) {

                        foreach($grading_info->outcomes as $n=>$outcome) {
                            $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
                            $options = make_grades_menu(-$outcome->scaleid);

                            if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                                $options[0] = get_string('nooutcome', 'grades');
                                $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>';
                            } else {
                                $attributes = array();
                                $attributes['tabindex'] = $tabindex++;
                                $attributes['id'] = 'outcome_'.$n.'_'.$auser->id;
                                $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes);
                            }
                            $outcomes .= '</div>';
                        }
                    }

                    $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>';
                    $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
                    if ($uses_outcomes) {
                        $row[] = $outcomes;
                    }

                    $table->add_data($row);
                }
                $currentposition++;
            }
        }

        $table->print_html();  /// Print the whole table

        /// Print quickgrade form around the table
        if ($quickgrade && $table->started_output){
            $mailinfopref = false;
            if (get_user_preferences('assignment_mailinfo', 1)) {
                $mailinfopref = true;
            }
            $emailnotification =  html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment'));

            $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'assignment');
            echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification'));

            $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'assignment')));
            echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton'));

            echo html_writer::end_tag('form');
        } else if ($quickgrade) {
            echo html_writer::end_tag('form');
        }

        echo '</div>';
        /// End of fast grading form

        /// Mini form for setting user preference

        $formaction = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id));
        $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref'));

        $mform->addElement('hidden', 'updatepref');
        $mform->setDefault('updatepref', 1);
        $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment'));
        $mform->addElement('select', 'filter', get_string('show'),  $filters);

        $mform->setDefault('filter', $filter);

        $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size'=>1));
        $mform->setDefault('perpage', $perpage);

        $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade','assignment'));
        $mform->setDefault('quickgrade', $quickgrade);
        $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment');

        $mform->addElement('submit', 'savepreferences', get_string('savepreferences'));

        $mform->display();

        echo $OUTPUT->footer();
    }
Ejemplo n.º 19
0
/**
 * takes a list of records, the current data, a search string,
 * and mode to display prints the translated template
 *
 * @global object
 * @global object
 * @param string $template
 * @param array $records
 * @param object $data
 * @param string $search
 * @param int $page
 * @param bool $return
 * @param object $jumpurl a moodle_url by which to jump back to the record list (can be null)
 * @return mixed
 */
function data_print_template($template, $records, $data, $search = '', $page = 0, $return = false, moodle_url $jumpurl = null)
{
    global $CFG, $DB, $OUTPUT;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = context_module::instance($cm->id);
    static $fields = array();
    static $dataid = null;
    if (empty($dataid)) {
        $dataid = $data->id;
    } else {
        if ($dataid != $data->id) {
            $fields = array();
        }
    }
    if (empty($fields)) {
        $fieldrecords = $DB->get_records('data_fields', array('dataid' => $data->id));
        foreach ($fieldrecords as $fieldrecord) {
            $fields[] = data_get_field($fieldrecord, $data);
        }
    }
    if (empty($records)) {
        return;
    }
    if (!$jumpurl) {
        $jumpurl = new moodle_url('/mod/data/view.php', array('d' => $data->id));
    }
    $jumpurl = new moodle_url($jumpurl, array('page' => $page, 'sesskey' => sesskey()));
    foreach ($records as $record) {
        // Might be just one for the single template
        // Replacing tags
        $patterns = array();
        $replacement = array();
        // Then we generate strings to replace for normal tags
        foreach ($fields as $field) {
            $patterns[] = '[[' . $field->field->name . ']]';
            $replacement[] = highlight($search, $field->display_browse_field($record->id, $template));
        }
        $canmanageentries = has_capability('mod/data:manageentries', $context);
        // Replacing special tags (##Edit##, ##Delete##, ##More##)
        $patterns[] = '##edit##';
        $patterns[] = '##delete##';
        if (data_user_can_manage_entry($record, $data, $context)) {
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '&amp;rid=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/edit') . '" class="iconsmall" alt="' . get_string('edit') . '" title="' . get_string('edit') . '" /></a>';
            $replacement[] = '<a href="' . $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;delete=' . $record->id . '&amp;sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('t/delete') . '" class="iconsmall" alt="' . get_string('delete') . '" title="' . get_string('delete') . '" /></a>';
        } else {
            $replacement[] = '';
            $replacement[] = '';
        }
        $moreurl = $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '&amp;rid=' . $record->id;
        if ($search) {
            $moreurl .= '&amp;filter=1';
        }
        $patterns[] = '##more##';
        $replacement[] = '<a href="' . $moreurl . '"><img src="' . $OUTPUT->pix_url('t/preview') . '" class="iconsmall" alt="' . get_string('more', 'data') . '" title="' . get_string('more', 'data') . '" /></a>';
        $patterns[] = '##moreurl##';
        $replacement[] = $moreurl;
        $patterns[] = '##delcheck##';
        if ($canmanageentries) {
            $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##user##';
        $replacement[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $record->userid . '&amp;course=' . $data->course . '">' . fullname($record) . '</a>';
        $patterns[] = '##userpicture##';
        $ruser = user_picture::unalias($record, null, 'userid');
        $replacement[] = $OUTPUT->user_picture($ruser, array('courseid' => $data->course));
        $patterns[] = '##export##';
        if (!empty($CFG->enableportfolios) && ($template == 'singletemplate' || $template == 'listtemplate') && (has_capability('mod/data:exportentry', $context) || data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))) {
            require_once $CFG->libdir . '/portfoliolib.php';
            $button = new portfolio_add_button();
            $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), 'mod_data');
            list($formats, $files) = data_portfolio_caller::formats($fields, $record);
            $button->set_formats($formats);
            $replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##timeadded##';
        $replacement[] = userdate($record->timecreated);
        $patterns[] = '##timemodified##';
        $replacement[] = userdate($record->timemodified);
        $patterns[] = '##approve##';
        if (has_capability('mod/data:approve', $context) && $data->approval && !$record->approved) {
            $approveurl = new moodle_url($jumpurl, array('approve' => $record->id));
            $approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon), array('class' => 'approve'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##disapprove##';
        if (has_capability('mod/data:approve', $context) && $data->approval && $record->approved) {
            $disapproveurl = new moodle_url($jumpurl, array('disapprove' => $record->id));
            $disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall'));
            $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon), array('class' => 'disapprove'));
        } else {
            $replacement[] = '';
        }
        $patterns[] = '##approvalstatus##';
        if (!$data->approval) {
            $replacement[] = '';
        } else {
            if ($record->approved) {
                $replacement[] = get_string('approved', 'data');
            } else {
                $replacement[] = get_string('notapproved', 'data');
            }
        }
        $patterns[] = '##comments##';
        if ($template == 'listtemplate' && $data->comments) {
            if (!empty($CFG->usecomments)) {
                require_once $CFG->dirroot . '/comment/lib.php';
                list($context, $course, $cm) = get_context_info_array($context->id);
                $cmt = new stdClass();
                $cmt->context = $context;
                $cmt->course = $course;
                $cmt->cm = $cm;
                $cmt->area = 'database_entry';
                $cmt->itemid = $record->id;
                $cmt->showcount = true;
                $cmt->component = 'mod_data';
                $comment = new comment($cmt);
                $replacement[] = $comment->output(true);
            }
        } else {
            $replacement[] = '';
        }
        // actual replacement of the tags
        $newtext = str_ireplace($patterns, $replacement, $data->{$template});
        // no more html formatting and filtering - see MDL-6635
        if ($return) {
            return $newtext;
        } else {
            echo $newtext;
            // hack alert - return is always false in singletemplate anyway ;-)
            /**********************************
             *    Printing Ratings Form       *
             *********************************/
            if ($template == 'singletemplate') {
                //prints ratings options
                data_print_ratings($data, $record);
            }
            /**********************************
             *    Printing Comments Form       *
             *********************************/
            if ($template == 'singletemplate' && $data->comments) {
                if (!empty($CFG->usecomments)) {
                    require_once $CFG->dirroot . '/comment/lib.php';
                    list($context, $course, $cm) = get_context_info_array($context->id);
                    $cmt = new stdClass();
                    $cmt->context = $context;
                    $cmt->course = $course;
                    $cmt->cm = $cm;
                    $cmt->area = 'database_entry';
                    $cmt->itemid = $record->id;
                    $cmt->showcount = true;
                    $cmt->component = 'mod_data';
                    $comment = new comment($cmt);
                    $comment->output(false);
                }
            }
        }
    }
}
Ejemplo n.º 20
0
$content .= $existinguserselector->display(true);
$cell = new html_table_cell($content);
$cell->attributes['id'] = 'existingcell';
$cells[] = $cell;
$content = html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'submit', 'id' => 'add', 'name' => 'add', 'title' => get_string('add'), 'value' => $OUTPUT->larrow() . ' ' . get_string('add'))), array('id' => 'addcontrols'));
$content .= html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'submit', 'id' => 'remove', 'name' => 'remove', 'title' => get_string('remove'), 'value' => $OUTPUT->rarrow() . ' ' . get_string('remove'))), array('id' => 'removecontrols'));
$cell = new html_table_cell($content);
$cell->attributes['id'] = 'buttonscell';
$cells[] = $cell;
$content = html_writer::start_tag('p') . html_writer::tag('label', get_string('potentialattendees', 'facetoface'), array('for' => 'addselect')) . html_writer::end_tag('p');
$content .= $potentialuserselector->display(true);
$cell = new html_table_cell($content);
$cell->attributes['id'] = 'potentialcell';
$cells[] = $cell;
$table->data[] = new html_table_row($cells);
$content = html_writer::checkbox('suppressemail', 1, $suppressemail, get_string('suppressemail', 'facetoface'), array('id' => 'suppressemail'));
$content .= $OUTPUT->help_icon('suppressemail', 'facetoface');
$cell = new html_table_cell($content);
$cell->attributes['id'] = 'backcell';
$cell->attributes['colspan'] = '3';
$table->data[] = new html_table_row(array($cell));
$out .= html_writer::table($table);
// Get all signed up non-attendees.
$nonattendees = 0;
$usernamefields = get_all_user_name_fields(true, 'u');
$nonattendeesrs = $DB->get_recordset_sql("SELECT\n            u.id,\n            {$usernamefields},\n            u.email,\n            ss.statuscode\n        FROM\n            {facetoface_sessions} s\n        JOIN\n            {facetoface_signups} su\n         ON s.id = su.sessionid\n        JOIN\n            {facetoface_signups_status} ss\n         ON su.id = ss.signupid\n        JOIN\n            {user} u\n         ON u.id = su.userid\n        WHERE\n            s.id = ?\n        AND ss.superceded != 1\n        AND ss.statuscode = ?\n        ORDER BY\n            u.lastname, u.firstname", array($session->id, MDL_F2F_STATUS_REQUESTED));
$table = new html_table();
$table->head = array(get_string('name'), get_string('email'), get_string('status'));
foreach ($nonattendeesrs as $user) {
    $data = array();
    $data[] = new html_table_cell(fullname($user));
Ejemplo n.º 21
0
 /**
  * Returns HTML to display choices result
  * @param object $choices
  * @param bool $forcepublish
  * @return string
  */
 public function display_publish_name_vertical($choices)
 {
     global $PAGE;
     $html = '';
     $html .= html_writer::tag('h2', format_string(get_string("responses", "choice")), array('class' => 'main'));
     $attributes = array('method' => 'POST');
     $attributes['action'] = new moodle_url($PAGE->url);
     $attributes['id'] = 'attemptsform';
     if ($choices->viewresponsecapability) {
         $html .= html_writer::start_tag('form', $attributes);
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $choices->coursemoduleid));
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
         $html .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'mode', 'value' => 'overview'));
     }
     $table = new html_table();
     $table->cellpadding = 0;
     $table->cellspacing = 0;
     $table->attributes['class'] = 'results names ';
     $table->tablealign = 'center';
     $table->data = array();
     $count = 0;
     ksort($choices->options);
     $columns = array();
     foreach ($choices->options as $optionid => $options) {
         $coldata = '';
         if ($choices->showunanswered && $optionid == 0) {
             $coldata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class' => 'option'));
         } else {
             if ($optionid > 0) {
                 $coldata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class' => 'option'));
             }
         }
         $numberofuser = 0;
         if (!empty($options->user) && count($options->user) > 0) {
             $numberofuser = count($options->user);
         }
         $coldata .= html_writer::tag('div', ' (' . $numberofuser . ')', array('class' => 'numberofuser', 'title' => get_string('numberofuser', 'choice')));
         $columns[] = $coldata;
     }
     $table->head = $columns;
     $coldata = '';
     $columns = array();
     foreach ($choices->options as $optionid => $options) {
         $coldata = '';
         if ($choices->showunanswered || $optionid > 0) {
             if (!empty($options->user)) {
                 foreach ($options->user as $user) {
                     $data = '';
                     if (empty($user->imagealt)) {
                         $user->imagealt = '';
                     }
                     if ($choices->viewresponsecapability && $choices->deleterepsonsecapability && $optionid > 0) {
                         $attemptaction = html_writer::checkbox('attemptid[]', $user->id, '');
                         $data .= html_writer::tag('div', $attemptaction, array('class' => 'attemptaction'));
                     }
                     $userimage = $this->output->user_picture($user, array('courseid' => $choices->courseid));
                     $data .= html_writer::tag('div', $userimage, array('class' => 'image'));
                     $userlink = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $choices->courseid));
                     $name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href' => $userlink, 'class' => 'username'));
                     $data .= html_writer::tag('div', $name, array('class' => 'fullname'));
                     $data .= html_writer::tag('div', '', array('class' => 'clearfloat'));
                     $coldata .= html_writer::tag('div', $data, array('class' => 'user'));
                 }
             }
         }
         $columns[] = $coldata;
         $count++;
     }
     $table->data[] = $columns;
     foreach ($columns as $d) {
         $table->colclasses[] = 'data';
     }
     $html .= html_writer::tag('div', html_writer::table($table), array('class' => 'response'));
     $actiondata = '';
     if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {
         $selecturl = new moodle_url('#');
         $selectallactions = new component_action('click', "checkall");
         $selectall = new action_link($selecturl, get_string('selectall'), $selectallactions);
         $actiondata .= $this->output->render($selectall) . ' / ';
         $deselectallactions = new component_action('click', "checknone");
         $deselectall = new action_link($selecturl, get_string('deselectall'), $deselectallactions);
         $actiondata .= $this->output->render($deselectall);
         $actiondata .= html_writer::tag('label', ' ' . get_string('withselected', 'quiz') . ' ', array('for' => 'menuaction'));
         $actionurl = new moodle_url($PAGE->url, array('sesskey' => sesskey(), 'action' => 'delete_confirmation()'));
         $select = new single_select($actionurl, 'action', array('delete' => get_string('delete')), null, array('' => get_string('chooseaction', 'choice')), 'attemptsform');
         $actiondata .= $this->output->render($select);
     }
     $html .= html_writer::tag('div', $actiondata, array('class' => 'responseaction'));
     if ($choices->viewresponsecapability) {
         $html .= html_writer::end_tag('form');
     }
     return $html;
 }
 /**
  * Get the row for this submission in the inbox table
  *
  * @global object $CFG
  * @global type $OUTPUT
  * @param type $cm
  * @param type $turnitintooltwoassignment
  * @param type $parts
  * @param type $partid
  * @param type $submission
  * @param type $useroverallgrades
  * @param type $istutor
  * @return type
  */
 public function get_submission_inbox_row($cm, $turnitintooltwoassignment, $parts, $partid, $submission, &$useroverallgrades, $istutor, $context = 'all')
 {
     global $CFG, $OUTPUT, $USER, $DB;
     $config = turnitintooltwo_admin_config();
     $moodleuserid = substr($submission->userid, 0, 3) != 'nm-' && $submission->userid != 0 ? $submission->userid : 0;
     if (!$istutor) {
         $user = new turnitintooltwo_user($USER->id, "Learner");
     }
     $checkbox = "&nbsp;";
     if (!empty($submission->submission_objectid) && $istutor) {
         $checkbox = html_writer::checkbox('check_' . $submission->submission_objectid, $submission->submission_objectid, false, '', array("class" => "inbox_checkbox"));
     }
     if (!$istutor) {
         // If students viewing it will show 'digital receipt' link
         if (!empty($submission->submission_objectid)) {
             $studentname = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&do=digital_receipt&submissionid=' . $submission->submission_objectid . '&view_context=box', $OUTPUT->pix_icon('receipt', get_string('digitalreceipt', 'turnitintooltwo'), 'mod_turnitintooltwo', array('id' => 'tii_digital_receipt_icon')) . get_string('viewdigitalreceipt', 'turnitintooltwo'), array('class' => 'tii_digital_receipt'));
         } else {
             $studentname = "--";
         }
         //Determine whether the student can see the overall grade, based on the post time of all parts.
         $display_overall_grade = 1;
         foreach (array_keys($parts) as $ar_key => $ar_value) {
             if ($parts[$ar_value]->dtpost > time()) {
                 $display_overall_grade = 0;
             }
         }
     } else {
         if ($turnitintooltwoassignment->turnitintooltwo->anon && $parts[$partid]->unanon != 1) {
             if (empty($submission->submission_unanon) and $parts[$partid]->dtpost > time() and !empty($submission->submission_objectid)) {
                 // Anonymous marking is on, postdate has not passed and a submission has been made.
                 $studentname = html_writer::link('.unanonymise_form', get_string('anonenabled', 'turnitintooltwo'), array("class" => "unanonymise", "id" => "submission_" . $submission->submission_objectid));
             } else {
                 if (($parts[$partid]->dtpost <= time() or !empty($submission->submission_unanon)) and empty($submission->nmoodle)) {
                     // Post date has passed or anonymous marking disabled for user and user is a moodle user.
                     $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname));
                 } else {
                     if (($parts[$partid]->dtpost <= time() or !empty($submission->submission_unanon)) and !empty($submission->nmoodle)) {
                         // Post date has passed or anonymous marking disabled for user and user is a NON moodle user.
                         $studentname = html_writer::tag("span", format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonmoodleuser', 'turnitintooltwo') . ")", array("class" => "italic"));
                     } else {
                         // User has not made a submission.
                         $studentname = html_writer::tag("span", get_string('anonenabled', 'turnitintooltwo'), array("class" => "italic"));
                     }
                 }
             }
         } else {
             if (empty($submission->nmoodle)) {
                 // Link to user profile.
                 $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname));
             } else {
                 if (!empty($submission->nmoodle) && substr($submission->userid, 0, 3) != 'nm-') {
                     // Moodle User not enrolled on this course as a student.
                     $studentname = html_writer::link($CFG->wwwroot . "/user/view.php?id=" . $submission->userid . "&course=" . $turnitintooltwoassignment->turnitintooltwo->course, format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonenrolledstudent', 'turnitintooltwo') . ")", array("class" => "italic"));
                 } else {
                     // Non Moodle user.
                     $studentname = html_writer::tag("span", format_string($submission->lastname) . ", " . format_string($submission->firstname) . " (" . get_string('nonmoodleuser', 'turnitintooltwo') . ")", array("class" => "italic"));
                 }
             }
         }
     }
     // Submission title with link to open DV.
     if (!empty($submission->submission_objectid) and !empty($submission->submission_objectid)) {
         $title = $OUTPUT->box_start('default_open', 'default_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
         $title .= $OUTPUT->box(format_string($submission->submission_title), 'submission_title underline');
         $title .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'default_url_' . $submission->submission_objectid);
         $title .= $OUTPUT->box_end(true);
         $rawtitle = $submission->submission_title;
     } else {
         $title = "--";
         $rawtitle = "--";
     }
     $objectid = !empty($submission->submission_objectid) ? $submission->submission_objectid : "--";
     // Show date of submission or link to submit if it didn't work.
     if (empty($submission->submission_objectid) and !empty($submission->id)) {
         $rawmodified = 1;
         $modified = html_writer::link($CFG->wwwroot . "/mod/turnitintooltwo/view.php?id=" . $cm->id . "&action=manualsubmission" . "&sub=" . $submission->id . '&sesskey=' . sesskey(), $OUTPUT->pix_icon('icon-sml', get_string('submittoturnitin', 'turnitintooltwo'), 'mod_turnitintooltwo') . " " . get_string('submittoturnitin', 'turnitintooltwo'));
     } else {
         if (empty($submission->submission_objectid)) {
             $rawmodified = 0;
             $modified = "--";
         } else {
             $rawmodified = (int) $submission->submission_modified;
             $modified = userdate($submission->submission_modified, get_string('strftimedatetimeshort', 'langconfig'));
             if ($submission->submission_modified > $parts[$partid]->dtdue) {
                 $modified = html_writer::tag('span', $modified, array("class" => "late_submission"));
             }
         }
     }
     // Show Originality score with link to open document viewer.
     if (!empty($submission->id) && is_null($submission->submission_score) && $submission->submission_orcapable == 0) {
         // Don't show if there is no OR score and submission is not OR capable
         $rawscore = null;
         $score = '--';
     } else {
         if (!empty($submission->id) && !empty($submission->submission_objectid) && ($istutor || $turnitintooltwoassignment->turnitintooltwo->studentreports)) {
             // Show score.
             if (is_null($submission->submission_score)) {
                 $score = $OUTPUT->box_start('row_score', 'origreport_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
                 $score .= $OUTPUT->box('&nbsp;', 'score_colour score_colour_');
                 $score .= $OUTPUT->box(get_string('pending', 'turnitintooltwo'), 'origreport_score');
                 $rawscore = null;
             } else {
                 $score = $OUTPUT->box_start('row_score origreport_open', 'origreport_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid);
                 // Put EN flag if translated matching is on and that is the score used.
                 $transmatch = $submission->submission_transmatch == 1 ? 'EN' : '&nbsp;';
                 $score .= $OUTPUT->box($transmatch, 'score_colour score_colour_' . round($submission->submission_score, -1));
                 $score .= $OUTPUT->box($submission->submission_score . '%', 'origreport_score');
                 $rawscore = $submission->submission_score;
             }
             // Put in div placeholder for DV launch form.
             $score .= $OUTPUT->box('', 'launch_form', 'origreport_form_' . $submission->submission_objectid);
             // URL for DV launcher
             $score .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'origreport_url_' . $submission->submission_objectid);
             $score .= $OUTPUT->box_end(true);
         } else {
             $rawscore = null;
             $score = '--';
         }
     }
     // Show grade and link to DV.
     if ($config->usegrademark) {
         if ($turnitintooltwoassignment->turnitintooltwo->grade == 0) {
             //We set the grade column to N/A if there is no grade type set.
             $rawgrade = null;
             $grade = $OUTPUT->box('N/A', '');
         } else {
             if (isset($submission->submission_objectid) && ($istutor || !$istutor && $parts[$partid]->dtpost < time())) {
                 $submissiongrade = !is_null($submission->submission_grade) ? $submission->submission_grade : '';
                 if (is_null($submission->submission_grade) || $submission->submission_gmimaged == 0 && !$istutor) {
                     $submissiongrade = "--";
                 }
                 // Show warning to instructor if student can still resubmit.
                 $canresubmit = $turnitintooltwoassignment->turnitintooltwo->reportgenspeed > 0;
                 $tutorbeforeduedate = $istutor && time() < $parts[$partid]->dtdue;
                 $allowedlate = $turnitintooltwoassignment->turnitintooltwo->allowlate == 1 && empty($submission->nmoodle);
                 $class = $canresubmit && ($tutorbeforeduedate || $allowedlate) ? 'graded_warning' : '';
                 // Output grademark icon.
                 $grade = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-pencil fa-lg gm-blue')), 'grademark_open' . $class, 'grademark_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid, array('title' => $CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id));
                 // Show grade.
                 $grade .= $OUTPUT->box(html_writer::tag('span', $submissiongrade, array("class" => "grade")) . "/" . $parts[$partid]->maxmarks, 'grademark_grade');
                 // Put in div placeholder for DV launch form.
                 $grade .= $OUTPUT->box('', 'launch_form', 'grademark_form_' . $submission->submission_objectid);
                 // URL for DV launcher
                 $grade .= $OUTPUT->box($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id, 'dv_url', 'grademark_url_' . $submission->submission_objectid);
                 $rawgrade = $submissiongrade == "--" ? null : $submissiongrade;
             } else {
                 if (!isset($submission->submission_objectid) && empty($submission->id) && $istutor) {
                     // Allow nothing submission if no submission has been made and this is a tutor
                     $grade = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-pencil fa-lg grey')), 'submit_nothing', 'submitnothing_0_' . $partid . '_' . $submission->userid);
                     $rawgrade = null;
                 } else {
                     $rawgrade = null;
                     $grade = $OUTPUT->box('--', '');
                 }
             }
         }
         // Show average grade if more than 1 part.
         if (count($parts) > 1 || $turnitintooltwoassignment->turnitintooltwo->grade < 0) {
             $overallgrade = '--';
             if ($submission->nmoodle != 1 && ($istutor || !$istutor && $parts[$partid]->dtpost < time())) {
                 if (!isset($useroverallgrades[$submission->userid])) {
                     $usersubmissions = $turnitintooltwoassignment->get_user_submissions($submission->userid, $turnitintooltwoassignment->turnitintooltwo->id);
                     $useroverallgrades[$submission->userid] = $turnitintooltwoassignment->get_overall_grade($usersubmissions);
                 }
                 if ($turnitintooltwoassignment->turnitintooltwo->grade == 0 || $useroverallgrades[$submission->userid] === '--' || !$istutor && $display_overall_grade == 0) {
                 } else {
                     if ($turnitintooltwoassignment->turnitintooltwo->grade < 0) {
                         // Scale.
                         $scale = $DB->get_record('scale', array('id' => $turnitintooltwoassignment->turnitintooltwo->grade * -1));
                         $scalearray = explode(",", $scale->scale);
                         $overallgrade = $scalearray[$useroverallgrades[$submission->userid] - 1];
                     } else {
                         $overallgrade = round($useroverallgrades[$submission->userid] / $turnitintooltwoassignment->turnitintooltwo->grade * 100, 1) . '%';
                     }
                 }
                 if ($overallgrade != '--') {
                     $overallgrade = html_writer::tag("span", $overallgrade, array("class" => "overallgrade_" . $submission->userid));
                 }
             }
         }
     }
     // Indicate whether student has seen grademark image.
     if ($istutor) {
         if (isset($submission->submission_objectid)) {
             $submissionattempts = !empty($submission->submission_attempts) ? $submission->submission_attempts : 0;
             if ($submissionattempts > 0) {
                 $studentread = $OUTPUT->pix_icon('icon-student-read', get_string('student_read', 'turnitintooltwo') . ' ' . userdate($submissionattempts), 'mod_turnitintooltwo', array("class" => "student_read_icon"));
             } else {
                 $studentread = $OUTPUT->pix_icon('icon-dot', get_string('student_notread', 'turnitintooltwo'), 'mod_turnitintooltwo', array("class" => "student_dot_icon"));
             }
         } else {
             $studentread = "--";
         }
     }
     // Upload Submission.
     if ((!isset($submission->submission_objectid) || $turnitintooltwoassignment->turnitintooltwo->reportgenspeed != 0) && empty($submission->nmoodle) && time() > $parts[$partid]->dtstart) {
         if (empty($submission->submission_objectid)) {
             $submission->submission_objectid = 0;
         }
         $uploadtext = !$istutor ? html_writer::tag('span', get_string('submitpaper', 'turnitintooltwo')) : '';
         $eulaaccepted = 0;
         if ($submission->userid == $USER->id) {
             $submission_user = new turnitintooltwo_user($submission->userid, "Learner");
             $coursedata = $turnitintooltwoassignment->get_course_data($turnitintooltwoassignment->turnitintooltwo->course);
             $submission_user->join_user_to_class($coursedata->turnitin_cid);
             $eulaaccepted = $submission_user->user_agreement_accepted == 0 ? $submission_user->get_accepted_user_agreement() : $submission_user->user_agreement_accepted;
         }
         $upload = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&part=' . $partid . '&user='******'&do=submitpaper&view_context=box_solid', $uploadtext . ' ' . html_writer::tag('i', '', array('class' => 'fa fa-cloud-upload fa-lg')), array("class" => "upload_box nowrap", "id" => "upload_" . $submission->submission_objectid . "_" . $partid . "_" . $submission->userid, 'data-eula' => $eulaaccepted, 'data-user-type' => $istutor));
         if (time() > $parts[$partid]->dtdue && $turnitintooltwoassignment->turnitintooltwo->allowlate == 0 && !$istutor) {
             $upload = "&nbsp;";
         }
     } else {
         $upload = "&nbsp;";
     }
     // Download submission in original format.
     if (!empty($submission->submission_objectid) && !empty($submission->id) && !$submission->submission_acceptnothing) {
         $download = $OUTPUT->box(html_writer::tag('i', '', array('class' => 'fa fa-cloud-download fa-lg')), 'download_original_open', 'downloadoriginal_' . $submission->submission_objectid . "_" . $partid . "_" . $moodleuserid);
         $download .= $OUTPUT->box('', 'launch_form', 'downloadoriginal_form_' . $submission->submission_objectid);
         // Add in LTI launch form incase Javascript is disabled.
         if (!$istutor) {
             $download .= html_writer::tag('noscript', $this->output_dv_launch_form("downloadoriginal", $submission->submission_objectid, $user->tii_user_id, "Learner", get_string('downloadsubmission', 'turnitintooltwo')));
         }
     } else {
         $download = "--";
     }
     $refresh = '--';
     if (!empty($submission->id) && $istutor) {
         $refresh = html_writer::tag('div', html_writer::tag('i', '', array('class' => 'fa fa-refresh fa-lg', 'title' => get_string('turnitinrefreshsubmissions', 'turnitintooltwo'))) . html_writer::tag('i', '', array('class' => 'fa fa-spinner fa-spin')), array('class' => 'refresh_row', 'id' => 'refreshrow_' . $submission->submission_objectid . '_' . $partid . '_' . $moodleuserid));
     }
     // Delete Link.
     $delete = "--";
     if ($istutor) {
         if (!empty($submission->id)) {
             $fnd = array("\n", "\r");
             $rep = array('\\n', '\\r');
             $confirmstring = empty($submission->submission_objectid) ? 'deleteconfirm' : 'turnitindeleteconfirm';
             $string = str_replace($fnd, $rep, get_string($confirmstring, 'turnitintooltwo'));
             $attributes = array("onclick" => "return confirm('" . $string . "');");
             $delete = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&action=deletesubmission&sub=' . $submission->id . '&sesskey=' . sesskey(), html_writer::tag('i', '', array('class' => 'fa fa-trash-o fa-lg')), $attributes);
         }
     } else {
         if (empty($submission->submission_objectid) && !empty($submission->id)) {
             $fnd = array("\n", "\r");
             $rep = array('\\n', '\\r');
             $string = str_replace($fnd, $rep, get_string('deleteconfirm', 'turnitintooltwo'));
             $attributes = array("onclick" => "return confirm('" . $string . "');");
             $delete = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/view.php?id=' . $cm->id . '&action=deletesubmission&sub=' . $submission->id . '&sesskey=' . sesskey(), html_writer::tag('i', '', array('class' => 'fa fa-trash-o fa-lg')), $attributes);
         }
     }
     $data = array($partid, $checkbox, $studentname, $rawtitle, $title, $objectid, $rawmodified, $modified);
     if ($istutor || !$istutor && $turnitintooltwoassignment->turnitintooltwo->studentreports) {
         $data[] = $rawscore;
         $data[] = $score;
     }
     if ($config->usegrademark) {
         $data[] = $rawgrade;
         $data[] = $grade;
         if (count($parts) > 1 || $turnitintooltwoassignment->turnitintooltwo->grade < 0) {
             $data[] = $overallgrade;
         }
     }
     if ($istutor) {
         $data[] = $studentread;
     }
     $data[] = $upload;
     $data[] = $download;
     if ($istutor) {
         $data[] = $refresh;
     }
     $data[] = $delete;
     return $data;
 }
 public function show_file_errors_table($page = 0)
 {
     global $CFG, $OUTPUT;
     $limit = 100;
     $offset = $page * $limit;
     $plagiarismpluginturnitin = new plagiarism_plugin_turnitin();
     $filescount = $plagiarismpluginturnitin->get_file_upload_errors(0, 0, true);
     $files = $plagiarismpluginturnitin->get_file_upload_errors($offset, $limit);
     $baseurl = new moodle_url('/plagiarism/turnitin/settings.php', array('do' => 'errors'));
     $pagingbar = $OUTPUT->paging_bar($filescount, $page, $limit, $baseurl);
     // Do the table headers.
     $cells = array();
     $selectall = html_writer::checkbox('errors_select_all', false, false, '', array("class" => "select_all_checkbox"));
     $cells["checkbox"] = new html_table_cell($selectall);
     $cells["id"] = new html_table_cell(get_string('id', 'plagiarism_turnitin'));
     $cells["user"] = new html_table_cell(get_string('student', 'plagiarism_turnitin'));
     $cells["user"]->attributes['class'] = 'left';
     $cells["course"] = new html_table_cell(get_string('course', 'plagiarism_turnitin'));
     $cells["module"] = new html_table_cell(get_string('module', 'plagiarism_turnitin'));
     $cells["file"] = new html_table_cell(get_string('file'));
     $cells["error"] = new html_table_cell(get_string('error'));
     $cells["delete"] = new html_table_cell('&nbsp;');
     $cells["delete"]->attributes['class'] = 'centered_cell';
     $table = new html_table();
     $table->head = $cells;
     $i = 0;
     $rows = array();
     if (count($files) == 0) {
         $cells = array();
         $cells["checkbox"] = new html_table_cell(get_string('semptytable', 'plagiarism_turnitin'));
         $cells["checkbox"]->colspan = 8;
         $cells["checkbox"]->attributes['class'] = 'centered_cell';
         $rows[0] = new html_table_row($cells);
     } else {
         foreach ($files as $k => $v) {
             $cells = array();
             if (!empty($v->moduletype) && $v->moduletype != "forum") {
                 $cm = get_coursemodule_from_id($v->moduletype, $v->cm);
                 $checkbox = html_writer::checkbox('check_' . $k, $k, false, '', array("class" => "errors_checkbox"));
                 $cells["checkbox"] = new html_table_cell($checkbox);
                 $cells["id"] = new html_table_cell($k);
                 $cells["user"] = new html_table_cell($v->firstname . " " . $v->lastname . " (" . $v->email . ")");
                 $courselink = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $v->courseid));
                 $cells["course"] = new html_table_cell(html_writer::link($courselink, $v->coursename, array('title' => $v->coursename)));
                 $modulelink = new moodle_url($CFG->wwwroot . '/mod/' . $v->moduletype . '/view.php', array('id' => $v->cm));
                 $cells["module"] = new html_table_cell(html_writer::link($modulelink, $cm->name, array('title' => $cm->name)));
                 if ($v->submissiontype == "file") {
                     $fs = get_file_storage();
                     if ($file = $fs->get_file_by_hash($v->identifier)) {
                         $cells["file"] = new html_table_cell(html_writer::link($CFG->wwwroot . '/pluginfile.php/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . '/' . $file->get_itemid() . '/' . $file->get_filename(), $OUTPUT->pix_icon('fileicon', 'open ' . $file->get_filename(), 'plagiarism_turnitin') . " " . $file->get_filename()));
                     } else {
                         $cells["file"] = get_string('filedoesnotexist', 'plagiarism_turnitin');
                     }
                 } else {
                     $cells["file"] = str_replace('_', ' ', ucfirst($v->submissiontype));
                 }
                 $errorcode = $v->errorcode;
                 // Deal with legacy error issues.
                 if (is_null($errorcode)) {
                     $errorcode = 0;
                     if ($v->submissiontype == 'file') {
                         if (is_object($file) && $file->get_filesize() > TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE) {
                             $errorcode = 2;
                         }
                     }
                 }
                 // Show error message if there is one.
                 $errormsg = $v->errormsg;
                 if ($errorcode == 0) {
                     $errorstring = is_null($errormsg) ? get_string('ppsubmissionerrorseelogs', 'plagiarism_turnitin') : $errormsg;
                 } else {
                     $errorstring = get_string('errorcode' . $v->errorcode, 'plagiarism_turnitin', display_size(TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE));
                 }
                 $cells["error"] = $errorstring;
                 $fnd = array("\n", "\r");
                 $rep = array('\\n', '\\r');
                 $string = str_replace($fnd, $rep, get_string('deleteconfirm', 'plagiarism_turnitin'));
                 $attributes["onclick"] = "return confirm('" . $string . "');";
                 $cells["delete"] = new html_table_cell(html_writer::link($CFG->wwwroot . '/plagiarism/turnitin/settings.php?do=errors&action=deletefile&id=' . $k, $OUTPUT->pix_icon('delete', get_string('deletesubmission', 'plagiarism_turnitin'), 'plagiarism_turnitin'), $attributes));
                 $cells["delete"]->attributes['class'] = 'centered_cell';
                 $rows[$i] = new html_table_row($cells);
                 $i++;
             }
         }
         if ($i == 0) {
             $cells = array();
             $cells["checkbox"] = new html_table_cell(get_string('semptytable', 'plagiarism_turnitin'));
             $cells["checkbox"]->colspan = 8;
             $cells["checkbox"]->attributes['class'] = 'centered_cell';
             $rows[0] = new html_table_row($cells);
         } else {
             $table->id = "ppErrors";
         }
     }
     $table->data = $rows;
     $output = html_writer::table($table);
     return $pagingbar . $output . $pagingbar;
 }
Ejemplo n.º 24
0
    echo '<p>' . html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')) . '</p>';
} else {
    echo '<p>';
    print_string('codecoveragedisabled', 'tool_unittest');
    echo '<input type="hidden" name="codecoverage" value="0" /></p>';
}
echo '<p><strong>' . "Databases:" . '</strong></p>';
echo '<ul>';
foreach ($dbinfos as $i => $dbinfo) {
    $name = $dbinfo['name'];
    if ($dbinfo['installed']) {
        if (!$dbinfo['configured']) {
            $name = "{$name} (misconfigured)";
            // TODO: localise
        }
        echo '<li>' . html_writer::checkbox('selected[' . $i . ']', 1, intval(!empty($selected[$i])), $name) . '</li>';
    } else {
        echo '<li>' . "{$name}: driver not installed" . '</li>';
        // TODO: localise
    }
}
echo '</ul>';
echo '<p>External databases are configured in config.php, add lines:</p>
<pre>
$CFG->func_test_db_1 = array("native", "pgsql", "localhost", "moodleuser", "password", "moodle", "test", null);
$CFG->func_test_db_2 = array("native", "mssql", "localhost", "moodleuser", "password", "moodle", "test", null);
</pre>
<p>where order of parameters is: dblibrary, dbtype, dbhost, dbuser, dbpass, dbname, prefix, dboptions</p>';
echo '<p><input type="submit" value="' . get_string('runtests', 'tool_unittest') . '" /></p>';
echo '</div>';
echo '</form>';
     }
     $output = '';
     $output .= "<br /><br />\n";
     $output .= $questionnaire->renderer->help_icon('downloadtextformat', 'questionnaire');
     $output .= '&nbsp;' . get_string('downloadtext') . ':&nbsp;' . get_string('responses', 'questionnaire') . '&nbsp;' . $groupname;
     $output .= $questionnaire->renderer->heading(get_string('textdownloadoptions', 'questionnaire'));
     $output .= $questionnaire->renderer->box_start();
     $output .= "<form action=\"{$CFG->wwwroot}/mod/questionnaire/report.php\" method=\"GET\">\n";
     $output .= "<input type=\"hidden\" name=\"instance\" value=\"{$instance}\" />\n";
     $output .= "<input type=\"hidden\" name=\"user\" value=\"{$user}\" />\n";
     $output .= "<input type=\"hidden\" name=\"sid\" value=\"{$sid}\" />\n";
     $output .= "<input type=\"hidden\" name=\"action\" value=\"dcsv\" />\n";
     $output .= "<input type=\"hidden\" name=\"group\" value=\"{$currentgroupid}\" />\n";
     $output .= html_writer::checkbox('choicecodes', 1, true, get_string('includechoicecodes', 'questionnaire'));
     $output .= "<br />\n";
     $output .= html_writer::checkbox('choicetext', 1, true, get_string('includechoicetext', 'questionnaire'));
     $output .= "<br />\n";
     $output .= "<br />\n";
     $output .= "<input type=\"submit\" name=\"submit\" value=\"" . get_string('download', 'questionnaire') . "\" />\n";
     $output .= "</form>\n";
     $output .= $questionnaire->renderer->box_end();
     $questionnaire->page->add_to_page('respondentinfo', $output);
     echo $questionnaire->renderer->render($questionnaire->page);
     echo $questionnaire->renderer->footer('none');
     // Log saved as text action.
     $params = array('objectid' => $questionnaire->id, 'context' => $questionnaire->context, 'courseid' => $course->id, 'other' => array('action' => $action, 'instance' => $instance, 'currentgroupid' => $currentgroupid));
     $event = \mod_questionnaire\event\all_responses_saved_as_text::create($params);
     $event->trigger();
     exit;
     break;
 case 'dcsv':
Ejemplo n.º 26
0
    }
    $formheader = get_string('retest', 'tool_unittest');
} else {
    $displaypath = '';
    echo $OUTPUT->header();
    $formheader = get_string('rununittests', 'tool_unittest');
}
// Print the form for adjusting options.
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
echo $OUTPUT->heading($formheader);
echo '<form method="get" action="index.php">';
echo '<fieldset class="invisiblefieldset">';
echo '<p>' . html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')) . '</p>';
echo '<p>' . html_writer::checkbox('showsearch', 1, $showsearch, get_string('showsearch', 'tool_unittest')) . '</p>';
if (moodle_coverage_recorder::can_run_codecoverage()) {
    echo '<p>' . html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')) . '</p>';
} else {
    echo '<p>';
    print_string('codecoveragedisabled', 'tool_unittest');
    echo '<input type="hidden" name="codecoverage" value="0" /></p>';
}
echo '<p>';
echo '<label for="path">', get_string('onlytest', 'tool_unittest'), '</label> ';
echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="40" />';
echo '</p>';
echo '<input type="submit" value="' . get_string('runtests', 'tool_unittest') . '" />';
echo '</fieldset>';
echo '</form>';
echo $OUTPUT->box_end();
$otherpages = array();
$otherpages['PDF lib test'] = new moodle_url('/admin/tool/unittest/other/pdflibtestpage.php');
Ejemplo n.º 27
0
     $createassigncheckbox = html_writer::checkbox('create_assign', 1, false, get_string('createmoodleassignments', 'turnitintooltwo'), array("class" => "create_assignment_checkbox"));
     $createassign = html_writer::tag('div', $createassigncheckbox, array("class" => "create_assign_checkbox_container"));
     $createbutton = html_writer::tag('button', get_string('createmoodlecourses', 'turnitintooltwo'), array("id" => "create_classes_button"));
     $output .= $OUTPUT->box($categoryselectlabel . " " . $categoryselect . $createassign . $createbutton, 'create_checkboxes navbar');
     $table = new html_table();
     $table->id = "courseBrowserTable";
     $rows = array();
     // Make up json array for drop down in table.
     $integrationidsjson = array();
     foreach ($tiiintegrationids as $k => $v) {
         $integrationidsjson[] = array('value' => $k, 'label' => $v);
     }
     $output .= html_writer::script('var integration_ids = ' . json_encode($integrationidsjson));
     // Do the table headers.
     $cells = array();
     $cells[0] = new html_table_cell(html_writer::checkbox('selectallcb', 1, false));
     $cells[1] = new html_table_cell(get_string('coursetitle', 'turnitintooltwo'));
     $cells[2] = new html_table_cell(get_string('integration', 'turnitintooltwo'));
     $cells[3] = new html_table_cell(get_string('ced', 'turnitintooltwo'));
     $cells[4] = new html_table_cell(get_string('turnitinid', 'turnitintooltwo'));
     $cells[5] = new html_table_cell(get_string('moodlelinked', 'turnitintooltwo'));
     $cells[6] = new html_table_cell('&nbsp;');
     $table->head = $cells;
     $output .= $OUTPUT->box(html_writer::table($table), '');
     $output .= turnitintooltwo_show_edit_course_end_date_form();
     break;
 case "multiple_class_recreation":
     if (!confirm_sesskey()) {
         throw new moodle_exception('invalidsesskey', 'error');
     }
     $PAGE->set_pagelayout('embedded');
Ejemplo n.º 28
-1
echo html_writer::tag('p', 'To render a normal single select:');
$options = array(1 => 'One', 2 => 'Two', 3 => 'Three');
echo html_writer::select($options, 'name3', 1, array('' => 'choosedots'), $attr);
echo html_writer::tag('p', 'Or a single select with option grouping:');
$optoptions = array(array('Group 1' => array(1 => 'Option 1a', 2 => 'Option 1b', 3 => 'Option 1c')), array('Group 2' => array(4 => 'Option 2a', 5 => 'Option 2b', 6 => 'Option 2c')));
echo html_writer::select($optoptions, 'name4');
echo html_writer::tag('p', 'To render a time selector - you can choose the units (years, months, days, hours, minutes):');
echo html_writer::select_time('years', 'name5', time(), 5, $attr);
echo html_writer::tag('p', 'Generate a hidden input field for every parameter in a moodle_url object (output displayed below instead of rendered):');
$url = new moodle_url('index.php', array('a' => 1, 'b' => 2, 'exclude' => 'this'));
echo html_writer::tag('pre', htmlentities(html_writer::input_hidden_params($url, array('exclude'))));
echo html_writer::tag('p', 'Generate a script tag (output displayed below instead of rendered):');
echo html_writer::tag('pre', htmlentities(html_writer::script('alert(\'hi\');')));
echo html_writer::tag('p', 'Generate a form label:');
echo html_writer::label('Label text', 'checkbox1');
echo html_writer::checkbox('name', 'value', false, null, array('id' => 'checkbox1'));
echo html_writer::tag('p', 'A confirm form with continue/cancel options (just providing urls to go to):');
$continueurl = new moodle_url('index.php');
$cancelurl = new moodle_url('index.php');
echo $OUTPUT->confirm('This is the message', $continueurl, $cancelurl);
echo html_writer::tag('p', 'A confirm form with continue/cancel options (with custom buttons):');
$continueurl = new moodle_url('index.php');
$cancelurl = new moodle_url('index.php');
$continuebutton = new single_button($continueurl, 'Custom Button text', 'post');
$cancelbutton = new single_button($cancelurl, 'Something else', 'get');
echo $OUTPUT->confirm('This is another message', $continuebutton, $cancelbutton);
echo html_writer::tag('p', 'A standalone single button. This is still wrapped in a form so you can submit it. There are a couple of ways to generate, via a function call:');
echo $OUTPUT->single_button($continueurl, 'A disabled button', 'post', array('disabled' => true));
echo html_writer::tag('p', 'Or manually create object then render. Note this uses a confirm dialog, try pressing to see popup (needs styling)');
// render directly
$button = new single_button($continueurl, 'Manually rendered button', 'post');
Ejemplo n.º 29
-1
/**
 * Displays the entry form and toc if required.
 *
 * @param  stdClass $user   user object
 * @param  stdClass $scorm  scorm object
 * @param  string   $action base URL for the organizations select box
 * @param  stdClass $cm     course module object
 */
function scorm_print_launch ($user, $scorm, $action, $cm) {
    global $CFG, $DB, $PAGE, $OUTPUT, $COURSE;

    if ($scorm->updatefreq == SCORM_UPDATE_EVERYTIME) {
        scorm_parse($scorm, false);
    }

    $organization = optional_param('organization', '', PARAM_INT);

    if ($scorm->displaycoursestructure == 1) {
        echo $OUTPUT->box_start('generalbox boxaligncenter toc', 'toc');
        echo html_writer::div(get_string('contents', 'scorm'), 'structurehead');
    }
    if (empty($organization)) {
        $organization = $scorm->launch;
    }
    if ($orgs = $DB->get_records_select_menu('scorm_scoes', 'scorm = ? AND '.
                                         $DB->sql_isempty('scorm_scoes', 'launch', false, true).' AND '.
                                         $DB->sql_isempty('scorm_scoes', 'organization', false, false),
                                         array($scorm->id), 'sortorder, id', 'id,title')) {
        if (count($orgs) > 1) {
            $select = new single_select(new moodle_url($action), 'organization', $orgs, $organization, null);
            $select->label = get_string('organizations', 'scorm');
            $select->class = 'scorm-center';
            echo $OUTPUT->render($select);
        }
    }
    $orgidentifier = '';
    if ($sco = scorm_get_sco($organization, SCO_ONLY)) {
        if (($sco->organization == '') && ($sco->launch == '')) {
            $orgidentifier = $sco->identifier;
        } else {
            $orgidentifier = $sco->organization;
        }
    }

    $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR));   // Just to be safe.
    if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
        $scorm->version = 'scorm_12';
    }
    require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');

    $result = scorm_get_toc($user, $scorm, $cm->id, TOCFULLURL, $orgidentifier);
    $incomplete = $result->incomplete;

    // Do we want the TOC to be displayed?
    if ($scorm->displaycoursestructure == 1) {
        echo $result->toc;
        echo $OUTPUT->box_end();
    }

    // Is this the first attempt ?
    $attemptcount = scorm_get_attempt_count($user->id, $scorm);

    // Do not give the player launch FORM if the SCORM object is locked after the final attempt.
    if ($scorm->lastattemptlock == 0 || $result->attemptleft > 0) {
            echo html_writer::start_div('scorm-center');
            echo html_writer::start_tag('form', array('id' => 'scormviewform',
                                                        'method' => 'post',
                                                        'action' => $CFG->wwwroot.'/mod/scorm/player.php'));
        if ($scorm->hidebrowse == 0) {
            print_string('mode', 'scorm');
            echo ': '.html_writer::empty_tag('input', array('type' => 'radio', 'id' => 'b', 'name' => 'mode', 'value' => 'browse')).
                        html_writer::label(get_string('browse', 'scorm'), 'b');
            echo html_writer::empty_tag('input', array('type' => 'radio',
                                                        'id' => 'n', 'name' => 'mode',
                                                        'value' => 'normal', 'checked' => 'checked')).
                    html_writer::label(get_string('normal', 'scorm'), 'n');

        } else {
            echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'mode', 'value' => 'normal'));
        }
        if ($scorm->forcenewattempt == 1) {
            if ($incomplete === false) {
                echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'newattempt', 'value' => 'on'));
            }
        } else if (!empty($attemptcount) && ($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {
                echo html_writer::empty_tag('br');
                echo html_writer::checkbox('newattempt', 'on', false, '', array('id' => 'a'));
                echo html_writer::label(get_string('newattempt', 'scorm'), 'a');
        }
        if (!empty($scorm->popup)) {
            echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'display', 'value' => 'popup'));
        }

        echo html_writer::empty_tag('br');
        echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scoid', 'value' => $scorm->launch));
        echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'cm', 'value' => $cm->id));
        echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'currentorg', 'value' => $orgidentifier));
        echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('enter', 'scorm')));
        echo html_writer::end_tag('form');
        echo html_writer::end_div();
    }
}
Ejemplo n.º 30
-1
        $actions = array();
        $deleteurl = new moodle_url('/mod/emarking/print/orphanpages.php', array('id' => $cm->id, 'delete' => $file->get_id()));
        $rotateurl = new moodle_url('/mod/emarking/print/orphanpages.php', array('id' => $cm->id, 'file' => $file->get_id(), 'rotate' => true));
        if ($usercanupload) {
            $actions[] = $OUTPUT->action_icon($rotateurl, new pix_icon('i/return', get_string('rotatepage', 'mod_emarking')));
            $actions[] = $OUTPUT->pix_icon('i/edit', get_string('rotatepage', 'mod_emarking'), '', array('style' => 'cursor:pointer;', 'onclick' => 'showfixform(' . $file->get_id() . ')'));
        }
        if (isset($file->anonymous)) {
            $actions[] = $OUTPUT->action_icon(moodle_url::make_pluginfile_url($context->id, 'mod_emarking', 'orphanpages', $emarking->id, '/', $file->anonymous->get_filename()), new pix_icon('i/show', get_string('anonymousfile', 'mod_emarking')));
        }
        $actions[] = html_writer::div(html_writer::div(get_string('student', 'grades'), NULL, array('id' => 'error-student-' . $file->get_id())) . html_writer::tag('input', NULL, array('name' => 'student-' . $file->get_id(), 'type' => 'text', 'class' => 'studentname', 'tabindex' => $shown * 2, 'fileid' => $file->get_id())) . '<br/>' . html_writer::div(get_string('page', 'mod_emarking'), NULL, array('id' => 'error-pagenumber-' . $file->get_id())) . html_writer::select($options, 'page-' . $file->get_id(), '', false, array('tabindex' => $shown * 2 + 1, 'id' => 'page-' . $file->get_id())) . '<br/>' . html_writer::tag('button', get_string('cancel'), array('class' => 'btn', 'onclick' => 'return cancelchanges(' . $file->get_id() . ');')) . html_writer::tag('button', get_string('submit'), array('class' => 'btn', 'onclick' => 'return savechanges(' . $file->get_id() . ');')) . html_writer::tag('input', NULL, array('type' => 'hidden', 'name' => 'studentid-' . $file->get_id(), 'id' => 's' . $file->get_id())), 'fixorphanpage', array('id' => 'fix-' . $file->get_id())) . html_writer::div('', '', array('id' => 'content-' . $file->get_id()));
        $imgurl = moodle_url::make_pluginfile_url($context->id, 'mod_emarking', 'orphanpages', $emarking->id, '/', $file->get_filename());
        $imgurl .= '?r=' . random_string();
        $data = array($OUTPUT->action_link($imgurl, html_writer::div(html_writer::img($imgurl, $file->get_filename()), '', array('style' => 'height:100px; overflow:hidden; max-width:600px;'))), implode(' ', $actions));
        if ($usercanupload) {
            $data[] = html_writer::checkbox('d[]', $file->get_id(), false, '');
        }
        $table->data[] = $data;
    }
    echo html_writer::table($table);
    echo $OUTPUT->paging_bar($numorphanpages, $page, $perpage, $url);
    if ($usercanupload) {
        echo html_writer::start_tag('input', array('type' => 'submit', 'value' => get_string('deleteselectedpages', 'mod_emarking'), 'style' => 'float:right;'));
        echo "</form>";
    }
}
$students = get_enrolled_users($context, 'mod/emarking:submit');
?>
<script type="text/javascript">
// Course module id.
var cmid = <?php