Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/renderer.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 defined('MOODLE_INTERNAL') || die();
00027 
00028 require_once($CFG->libdir . '/pluginlib.php');
00029 
00033 class core_admin_renderer extends plugin_renderer_base {
00034 
00040     public function install_licence_page() {
00041         global $CFG;
00042         $output = '';
00043 
00044         $copyrightnotice = text_to_html(get_string('gpl3'));
00045         $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
00046 
00047         $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
00048 
00049         $output .= $this->header();
00050         $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
00051         $output .= $this->heading(get_string('copyrightnotice'));
00052         $output .= $this->box($copyrightnotice, 'copyrightnotice');
00053         $output .= html_writer::empty_tag('br');
00054         $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
00055         $output .= $this->footer();
00056 
00057         return $output;
00058     }
00059 
00068     public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
00069         global $CFG;
00070         $output = '';
00071 
00072         $output .= $this->header();
00073         $output .= $this->maturity_warning($maturity);
00074         $output .= $this->heading("Moodle $release");
00075         $output .= $this->release_notes_link();
00076 
00077         $output .= $this->environment_check_table($envstatus, $environment_results);
00078 
00079         if (!$envstatus) {
00080             $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
00081         } else {
00082             $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
00083             $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
00084         }
00085 
00086         $output .= $this->footer();
00087         return $output;
00088     }
00089 
00097     public function upgrade_confirm_page($strnewversion, $maturity) {
00098         $output = '';
00099 
00100         $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
00101         $cancelurl = new moodle_url('index.php');
00102 
00103         $output .= $this->header();
00104         $output .= $this->maturity_warning($maturity);
00105         $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
00106         $output .= $this->footer();
00107 
00108         return $output;
00109     }
00110 
00118     public function upgrade_environment_page($release, $envstatus, $environment_results) {
00119         global $CFG;
00120         $output = '';
00121 
00122         $output .= $this->header();
00123         $output .= $this->heading("Moodle $release");
00124         $output .= $this->release_notes_link();
00125         $output .= $this->environment_check_table($envstatus, $environment_results);
00126 
00127         if (!$envstatus) {
00128             $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
00129 
00130         } else {
00131             $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
00132 
00133             if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
00134                 $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
00135             }
00136 
00137             $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
00138         }
00139 
00140         $output .= $this->footer();
00141 
00142         return $output;
00143     }
00144 
00154     public function upgrade_plugin_check_page(plugin_manager $pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
00155         $output = '';
00156 
00157         $output .= $this->header();
00158         $output .= $this->box_start('generalbox');
00159         $output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
00160         $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
00161         $output .= $this->box_end();
00162         $output .= $this->upgrade_reload($reloadurl);
00163 
00164         if ($pluginman->all_plugins_ok($version)) {
00165             $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
00166             $button->class = 'continuebutton';
00167             $output .= $this->render($button);
00168         } else {
00169             $output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
00170         }
00171 
00172         $output .= $this->footer();
00173 
00174         return $output;
00175     }
00176 
00187     public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
00188             $cronoverdue, $dbproblems, $maintenancemode) {
00189         $output = '';
00190 
00191         $output .= $this->header();
00192         $output .= $this->maturity_info($maturity);
00193         $output .= $this->insecure_dataroot_warning($insecuredataroot);
00194         $output .= $this->display_errors_warning($errorsdisplayed);
00195         $output .= $this->cron_overdue_warning($cronoverdue);
00196         $output .= $this->db_problems($dbproblems);
00197         $output .= $this->maintenance_mode_warning($maintenancemode);
00198 
00201         $output .= $this->moodle_copyright();
00203 
00204         $output .= $this->footer();
00205 
00206         return $output;
00207     }
00208 
00214     public function plugin_management_page(plugin_manager $pluginman) {
00215         $output = '';
00216 
00217         $output .= $this->header();
00218         $output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
00219         $output .= $this->box_start('generalbox');
00220         $output .= $this->plugins_control_panel($pluginman);
00221         $output .= $this->box_end();
00222         $output .= $this->footer();
00223 
00224         return $output;
00225     }
00226 
00235     public function environment_check_page($versions, $version, $envstatus, $environment_results) {
00236         $output = '';
00237         $output .= $this->header();
00238 
00239         // Print the component download link
00240         $output .= html_writer::tag('div', html_writer::link(
00241                     new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
00242                     get_string('updatecomponent', 'admin')),
00243                 array('class' => 'reportlink'));
00244 
00245         // Heading.
00246         $output .= $this->heading(get_string('environment', 'admin'));
00247 
00248         // Box with info and a menu to choose the version.
00249         $output .= $this->box_start();
00250         $output .= html_writer::tag('div', get_string('adminhelpenvironment'));
00251         $select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
00252         $select->label = get_string('moodleversion');
00253         $output .= $this->render($select);
00254         $output .= $this->box_end();
00255 
00256         // The results
00257         $output .= $this->environment_check_table($envstatus, $environment_results);
00258 
00259         $output .= $this->footer();
00260         return $output;
00261     }
00262 
00269     protected function warning($message, $type = 'warning') {
00270         return $this->box($message, 'generalbox admin' . $type);
00271     }
00272 
00278     protected function insecure_dataroot_warning($insecuredataroot) {
00279         global $CFG;
00280 
00281         if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
00282             return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
00283 
00284         } else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
00285             return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
00286 
00287         } else {
00288             return '';
00289         }
00290     }
00291 
00297     protected function display_errors_warning($errorsdisplayed) {
00298         if (!$errorsdisplayed) {
00299             return '';
00300         }
00301 
00302         return $this->warning(get_string('displayerrorswarning', 'admin'));
00303     }
00304 
00310     public function cron_overdue_warning($cronoverdue) {
00311         if (!$cronoverdue) {
00312             return '';
00313         }
00314 
00315         return $this->warning(get_string('cronwarning', 'admin') . '&nbsp;' .
00316                 $this->help_icon('cron', 'admin'));
00317     }
00318 
00324     public function db_problems($dbproblems) {
00325         if (!$dbproblems) {
00326             return '';
00327         }
00328 
00329         return $this->warning($dbproblems);
00330     }
00331 
00337     public function maintenance_mode_warning($maintenancemode) {
00338         if (!$maintenancemode) {
00339             return '';
00340         }
00341 
00342         $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
00343         $url = $url->out(); // get_string() does not support objects in params
00344 
00345         return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
00346     }
00347 
00353     protected function maturity_warning($maturity) {
00354         if ($maturity == MATURITY_STABLE) {
00355             return ''; // No worries.
00356         }
00357 
00358         $maturitylevel = get_string('maturity' . $maturity, 'admin');
00359         return $this->box(
00360                     $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
00361                     $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
00362                 'generalbox maturitywarning');
00363     }
00364 
00369     protected function moodle_copyright() {
00370         global $CFG;
00371 
00374         $copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
00375                          '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
00376                          'Copyright &copy; 1999 onwards, Martin Dougiamas<br />'.
00377                          'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.<br />'.
00378                          '<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
00380 
00381         return $this->box($copyrighttext, 'copyright');
00382     }
00383 
00389     protected function maturity_info($maturity) {
00390         if ($maturity == MATURITY_STABLE) {
00391             return ''; // No worries.
00392         }
00393 
00394         $maturitylevel = get_string('maturity' . $maturity, 'admin');
00395         return $this->box(
00396                     get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
00397                     $this->doc_link('admin/versions', get_string('morehelp')),
00398                 'generalbox adminwarning maturityinfo');
00399     }
00400 
00405     protected function release_notes_link() {
00406         $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
00407         $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
00408         return $this->box($releasenoteslink, 'generalbox releasenoteslink');
00409     }
00410 
00415     function upgrade_reload($url) {
00416         return html_writer::empty_tag('br') .
00417                 html_writer::tag('div',
00418                     html_writer::link($url, $this->pix_icon('i/reload', '') .
00419                             get_string('reload'), array('title' => get_string('reload'))),
00420                 array('class' => 'continuebutton')) . html_writer::empty_tag('br');
00421     }
00422 
00435     public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
00436         $plugininfo = $pluginman->get_plugins();
00437 
00438         if (empty($plugininfo)) {
00439             return '';
00440         }
00441 
00442         if (empty($options)) {
00443             $options = array(
00444                 'full' => false,
00445             );
00446         }
00447 
00448         $table = new html_table();
00449         $table->id = 'plugins-check';
00450         $table->head = array(
00451             get_string('displayname', 'core_plugin'),
00452             get_string('rootdir', 'core_plugin'),
00453             get_string('source', 'core_plugin'),
00454             get_string('versiondb', 'core_plugin'),
00455             get_string('versiondisk', 'core_plugin'),
00456             get_string('requires', 'core_plugin'),
00457             get_string('status', 'core_plugin'),
00458         );
00459         $table->colclasses = array(
00460             'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
00461         );
00462         $table->data = array();
00463 
00464         $numofhighlighted = array();    // number of highlighted rows per this subsection
00465 
00466         foreach ($plugininfo as $type => $plugins) {
00467 
00468             $header = new html_table_cell($pluginman->plugintype_name_plural($type));
00469             $header->header = true;
00470             $header->colspan = count($table->head);
00471             $header = new html_table_row(array($header));
00472             $header->attributes['class'] = 'plugintypeheader type-' . $type;
00473 
00474             $numofhighlighted[$type] = 0;
00475 
00476             if (empty($plugins) and $options['full']) {
00477                 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
00478                 $msg->colspan = count($table->head);
00479                 $row = new html_table_row(array($msg));
00480                 $row->attributes['class'] .= 'msg msg-noneinstalled';
00481                 $table->data[] = $header;
00482                 $table->data[] = $row;
00483                 continue;
00484             }
00485 
00486             $plugintyperows = array();
00487 
00488             foreach ($plugins as $name => $plugin) {
00489                 $row = new html_table_row();
00490                 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
00491 
00492                 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
00493                     $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
00494                 } else {
00495                     $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
00496                 }
00497                 $displayname  = $icon . ' ' . $plugin->displayname;
00498                 $displayname = new html_table_cell($displayname);
00499 
00500                 $rootdir = new html_table_cell($plugin->get_dir());
00501 
00502                 if ($isstandard = $plugin->is_standard()) {
00503                     $row->attributes['class'] .= ' standard';
00504                     $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
00505                 } else {
00506                     $row->attributes['class'] .= ' extension';
00507                     $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
00508                 }
00509 
00510                 $versiondb = new html_table_cell($plugin->versiondb);
00511                 $versiondisk = new html_table_cell($plugin->versiondisk);
00512 
00513                 $statuscode = $plugin->get_status();
00514                 $row->attributes['class'] .= ' status-' . $statuscode;
00515 
00516                 $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));
00517 
00518                 $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
00519 
00520                 $statusisboring = in_array($statuscode, array(
00521                         plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
00522                 $dependenciesok = $pluginman->are_dependencies_satisfied(
00523                         $plugin->get_other_required_plugins());
00524                 if ($isstandard and $statusisboring and $dependenciesok) {
00525                     if (empty($options['full'])) {
00526                         continue;
00527                     }
00528                 } else {
00529                     $numofhighlighted[$type]++;
00530                 }
00531 
00532                 $row->cells = array($displayname, $rootdir, $source,
00533                     $versiondb, $versiondisk, $requires, $status);
00534                 $plugintyperows[] = $row;
00535             }
00536 
00537             if (empty($numofhighlighted[$type]) and empty($options['full'])) {
00538                 continue;
00539             }
00540 
00541             $table->data[] = $header;
00542             $table->data = array_merge($table->data, $plugintyperows);
00543         }
00544 
00545         $sumofhighlighted = array_sum($numofhighlighted);
00546 
00547         if ($sumofhighlighted == 0) {
00548             $out  = $this->output->container_start('nonehighlighted', 'plugins-check-info');
00549             $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
00550             if (empty($options['full'])) {
00551                 $out .= html_writer::link(new moodle_url('/admin/index.php',
00552                     array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
00553                     get_string('nonehighlightedinfo', 'core_plugin'));
00554             }
00555             $out .= $this->output->container_end();
00556 
00557         } else {
00558             $out  = $this->output->container_start('somehighlighted', 'plugins-check-info');
00559             $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
00560             if (empty($options['full'])) {
00561                 $out .= html_writer::link(new moodle_url('/admin/index.php',
00562                     array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
00563                     get_string('somehighlightedinfo', 'core_plugin'));
00564             }
00565             $out .= $this->output->container_end();
00566         }
00567 
00568         if ($sumofhighlighted > 0 or $options['full']) {
00569             $out .= html_writer::table($table);
00570         }
00571 
00572         return $out;
00573     }
00574 
00582     protected function required_column(plugin_information $plugin, plugin_manager $pluginman, $version) {
00583         $requires = array();
00584 
00585         if (!empty($plugin->versionrequires)) {
00586             if ($plugin->versionrequires <= $version) {
00587                 $class = 'requires-ok';
00588             } else {
00589                 $class = 'requires-failed';
00590             }
00591             $requires[] = html_writer::tag('li',
00592                 get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
00593                 array('class' => $class));
00594         }
00595 
00596         foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
00597             $ok = true;
00598             $otherplugin = $pluginman->get_plugin_info($component);
00599 
00600             if (is_null($otherplugin)) {
00601                 $ok = false;
00602             } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
00603                 $ok = false;
00604             }
00605 
00606             if ($ok) {
00607                 $class = 'requires-ok';
00608             } else {
00609                 $class = 'requires-failed';
00610             }
00611 
00612             if ($requiredversion != ANY_VERSION) {
00613                 $str = 'otherpluginversion';
00614             } else {
00615                 $str = 'otherplugin';
00616             }
00617             $requires[] = html_writer::tag('li',
00618                     get_string($str, 'core_plugin',
00619                             array('component' => $component, 'version' => $requiredversion)),
00620                     array('class' => $class));
00621         }
00622 
00623         if (!$requires) {
00624             return '';
00625         }
00626         return html_writer::tag('ul', implode("\n", $requires));
00627     }
00628 
00637     public function plugins_control_panel(plugin_manager $pluginman) {
00638         $plugininfo = $pluginman->get_plugins();
00639 
00640         if (empty($plugininfo)) {
00641             return '';
00642         }
00643 
00644         $table = new html_table();
00645         $table->id = 'plugins-control-panel';
00646         $table->head = array(
00647             get_string('displayname', 'core_plugin'),
00648             get_string('systemname', 'core_plugin'),
00649             get_string('source', 'core_plugin'),
00650             get_string('version', 'core_plugin'),
00651             get_string('availability', 'core_plugin'),
00652             get_string('settings', 'core_plugin'),
00653             get_string('uninstall','core_plugin'),
00654         );
00655         $table->colclasses = array(
00656             'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall',
00657         );
00658 
00659         foreach ($plugininfo as $type => $plugins) {
00660 
00661             $header = new html_table_cell($pluginman->plugintype_name_plural($type));
00662             $header->header = true;
00663             $header->colspan = count($table->head);
00664             $header = new html_table_row(array($header));
00665             $header->attributes['class'] = 'plugintypeheader type-' . $type;
00666             $table->data[] = $header;
00667 
00668             if (empty($plugins)) {
00669                 $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
00670                 $msg->colspan = count($table->head);
00671                 $row = new html_table_row(array($msg));
00672                 $row->attributes['class'] .= 'msg msg-noneinstalled';
00673                 $table->data[] = $row;
00674                 continue;
00675             }
00676 
00677             foreach ($plugins as $name => $plugin) {
00678                 $row = new html_table_row();
00679                 $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
00680 
00681                 if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
00682                     $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
00683                 } else {
00684                     $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
00685                 }
00686                 if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
00687                     $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
00688                     $row->attributes['class'] .= ' missingfromdisk';
00689                 } else {
00690                     $msg = '';
00691                 }
00692                 $displayname  = $icon . ' ' . $plugin->displayname . ' ' . $msg;
00693                 $displayname = new html_table_cell($displayname);
00694 
00695                 $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
00696 
00697                 if ($plugin->is_standard()) {
00698                     $row->attributes['class'] .= ' standard';
00699                     $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
00700                 } else {
00701                     $row->attributes['class'] .= ' extension';
00702                     $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
00703                 }
00704 
00705                 $version = new html_table_cell($plugin->versiondb);
00706 
00707                 $isenabled = $plugin->is_enabled();
00708                 if (is_null($isenabled)) {
00709                     $availability = new html_table_cell('');
00710                 } else if ($isenabled) {
00711                     $row->attributes['class'] .= ' enabled';
00712                     $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
00713                     $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
00714                 } else {
00715                     $row->attributes['class'] .= ' disabled';
00716                     $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
00717                     $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
00718                 }
00719 
00720                 $settingsurl = $plugin->get_settings_url();
00721                 if (is_null($settingsurl)) {
00722                     $settings = new html_table_cell('');
00723                 } else {
00724                     $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
00725                     $settings = new html_table_cell($settings);
00726                 }
00727 
00728                 $uninstallurl = $plugin->get_uninstall_url();
00729                 $requriedby = $pluginman->other_plugins_that_require($plugin->component);
00730                 if (is_null($uninstallurl)) {
00731                     $uninstall = new html_table_cell('');
00732                 } else if ($requriedby) {
00733                     $uninstall = new html_table_cell(get_string('requiredby', 'core_plugin', implode(', ', $requriedby)));
00734                     $uninstall->attributes['class'] = 'requiredby';
00735                 } else {
00736                     $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
00737                     $uninstall = new html_table_cell($uninstall);
00738                 }
00739 
00740                 $row->cells = array(
00741                     $displayname, $systemname, $source, $version, $availability, $settings, $uninstall
00742                 );
00743                 $table->data[] = $row;
00744             }
00745         }
00746 
00747         return html_writer::table($table);
00748     }
00749 
00758     public function environment_check_table($result, $environment_results) {
00759         global $CFG;
00760 
00761         // Table headers
00762         $servertable = new html_table();//table for server checks
00763         $servertable->head  = array(
00764             get_string('name'),
00765             get_string('info'),
00766             get_string('report'),
00767             get_string('status'),
00768         );
00769         $servertable->align = array('center', 'center', 'left', 'center');
00770         $servertable->wrap  = array('nowrap', '', '', 'nowrap');
00771         $servertable->size  = array('10', 10, '100%', '10');
00772         $servertable->attributes['class'] = 'environmenttable generaltable';
00773 
00774         $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
00775 
00776         $othertable = new html_table();//table for custom checks
00777         $othertable->head  = array(
00778             get_string('info'),
00779             get_string('report'),
00780             get_string('status'),
00781         );
00782         $othertable->align = array('center', 'left', 'center');
00783         $othertable->wrap  = array('', '', 'nowrap');
00784         $othertable->size  = array(10, '100%', '10');
00785         $othertable->attributes['class'] = 'environmenttable generaltable';
00786 
00787         $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
00788 
00789         // Iterate over each environment_result
00790         $continue = true;
00791         foreach ($environment_results as $environment_result) {
00792             $errorline   = false;
00793             $warningline = false;
00794             $stringtouse = '';
00795             if ($continue) {
00796                 $type = $environment_result->getPart();
00797                 $info = $environment_result->getInfo();
00798                 $status = $environment_result->getStatus();
00799                 $error_code = $environment_result->getErrorCode();
00800                 // Process Report field
00801                 $rec = new stdClass();
00802                 // Something has gone wrong at parsing time
00803                 if ($error_code) {
00804                     $stringtouse = 'environmentxmlerror';
00805                     $rec->error_code = $error_code;
00806                     $status = get_string('error');
00807                     $errorline = true;
00808                     $continue = false;
00809                 }
00810 
00811                 if ($continue) {
00812                     if ($rec->needed = $environment_result->getNeededVersion()) {
00813                         // We are comparing versions
00814                         $rec->current = $environment_result->getCurrentVersion();
00815                         if ($environment_result->getLevel() == 'required') {
00816                             $stringtouse = 'environmentrequireversion';
00817                         } else {
00818                             $stringtouse = 'environmentrecommendversion';
00819                         }
00820 
00821                     } else if ($environment_result->getPart() == 'custom_check') {
00822                         // We are checking installed & enabled things
00823                         if ($environment_result->getLevel() == 'required') {
00824                             $stringtouse = 'environmentrequirecustomcheck';
00825                         } else {
00826                             $stringtouse = 'environmentrecommendcustomcheck';
00827                         }
00828 
00829                     } else if ($environment_result->getPart() == 'php_setting') {
00830                         if ($status) {
00831                             $stringtouse = 'environmentsettingok';
00832                         } else if ($environment_result->getLevel() == 'required') {
00833                             $stringtouse = 'environmentmustfixsetting';
00834                         } else {
00835                             $stringtouse = 'environmentshouldfixsetting';
00836                         }
00837 
00838                     } else {
00839                         if ($environment_result->getLevel() == 'required') {
00840                             $stringtouse = 'environmentrequireinstall';
00841                         } else {
00842                             $stringtouse = 'environmentrecommendinstall';
00843                         }
00844                     }
00845 
00846                     // Calculate the status value
00847                     if ($environment_result->getBypassStr() != '') {            //Handle bypassed result (warning)
00848                         $status = get_string('bypassed');
00849                         $warningline = true;
00850                     } else if ($environment_result->getRestrictStr() != '') {   //Handle restricted result (error)
00851                         $status = get_string('restricted');
00852                         $errorline = true;
00853                     } else {
00854                         if ($status) {                                          //Handle ok result (ok)
00855                             $status = get_string('ok');
00856                         } else {
00857                             if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
00858                                 $status = get_string('check');
00859                                 $warningline = true;
00860                             } else {                                            //Handle error result (error)
00861                                 $status = get_string('check');
00862                                 $errorline = true;
00863                             }
00864                         }
00865                     }
00866                 }
00867 
00868                 // Build the text
00869                 $linkparts = array();
00870                 $linkparts[] = 'admin/environment';
00871                 $linkparts[] = $type;
00872                 if (!empty($info)){
00873                    $linkparts[] = $info;
00874                 }
00875                 if (empty($CFG->docroot)) {
00876                     $report = get_string($stringtouse, 'admin', $rec);
00877                 } else {
00878                     $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
00879                 }
00880 
00881                 // Format error or warning line
00882                 if ($errorline || $warningline) {
00883                     $messagetype = $errorline? 'error':'warn';
00884                 } else {
00885                     $messagetype = 'ok';
00886                 }
00887                 $status = '<span class="'.$messagetype.'">'.$status.'</span>';
00888                 // Here we'll store all the feedback found
00889                 $feedbacktext = '';
00890                 // Append the feedback if there is some
00891                 $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), $messagetype);
00892                 //Append the bypass if there is some
00893                 $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'warn');
00894                 //Append the restrict if there is some
00895                 $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'error');
00896 
00897                 $report .= $feedbacktext;
00898 
00899                 // Add the row to the table
00900                 if ($environment_result->getPart() == 'custom_check'){
00901                     $otherdata[$messagetype][] = array ($info, $report, $status);
00902                 } else {
00903                     $serverdata[$messagetype][] = array ($type, $info, $report, $status);
00904                 }
00905             }
00906         }
00907 
00908         //put errors first in
00909         $servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
00910         $othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
00911 
00912         // Print table
00913         $output = '';
00914         $output .= $this->heading(get_string('serverchecks', 'admin'));
00915         $output .= html_writer::table($servertable);
00916         if (count($othertable->data)){
00917             $output .= $this->heading(get_string('customcheck', 'admin'));
00918             $output .= html_writer::table($othertable);
00919         }
00920 
00921         // Finally, if any error has happened, print the summary box
00922         if (!$result) {
00923             $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'environmentbox errorbox');
00924         }
00925 
00926         return $output;
00927     }
00928 }
 All Data Structures Namespaces Files Functions Variables Enumerations