Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/portfolio.php
Go to the documentation of this file.
00001 <?php
00002 
00003 require_once(dirname(dirname(__FILE__)) . '/config.php');
00004 require_once($CFG->libdir . '/portfoliolib.php');
00005 require_once($CFG->libdir . '/portfolio/forms.php');
00006 require_once($CFG->libdir . '/adminlib.php');
00007 
00008 $portfolio     = optional_param('pf', '', PARAM_FORMAT);
00009 $action        = optional_param('action', '', PARAM_ALPHA);
00010 $sure          = optional_param('sure', '', PARAM_ALPHA);
00011 
00012 $display = true; // fall through to normal display
00013 
00014 $pagename = 'manageportfolios';
00015 
00016 if ($action == 'edit') {
00017     $pagename = 'portfoliosettings' . $portfolio;
00018 } else if ($action == 'delete') {
00019     $pagename = 'portfoliodelete';
00020 } else if (($action == 'newon') || ($action == 'newoff')) {
00021     $pagename = 'portfolionew';
00022 }
00023 
00024 // Need to remember this for form
00025 $formaction = $action;
00026 
00027 // Check what visibility to show the new repository
00028 if ($action == 'newon') {
00029     $action = 'new';
00030     $visible = 1;
00031 } else if ($action == 'newoff') {
00032     $action = 'new';
00033     $visible = 0;
00034 }
00035 
00036 admin_externalpage_setup($pagename);
00037 
00038 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
00039 
00040 $baseurl    = "$CFG->wwwroot/$CFG->admin/portfolio.php";
00041 $sesskeyurl = "$CFG->wwwroot/$CFG->admin/portfolio.php?sesskey=" . sesskey();
00042 $configstr  = get_string('manageportfolios', 'portfolio');
00043 
00044 $return = true; // direct back to the main page
00045 
00050 function portfolio_action_url($portfolio) {
00051     global $baseurl;
00052     return new moodle_url($baseurl, array('sesskey'=>sesskey(), 'pf'=>$portfolio));
00053 }
00054 
00055 if (($action == 'edit') || ($action == 'new')) {
00056     if (($action == 'edit')) {
00057         $instance = portfolio_instance($portfolio);
00058         $plugin = $instance->get('plugin');
00059 
00060         // Since visible is being passed to form
00061         // and used to set the value when a new
00062         // instance is created - we must also
00063         // place the currently visibility into the
00064         // form as well
00065         $visible = $instance->get('visible');
00066     } else {
00067         $instance = null;
00068         $plugin = $portfolio;
00069     }
00070 
00071     $PAGE->set_pagetype('admin-portfolio-' . $plugin);
00072 
00073     // Display the edit form for this instance
00074     $mform = new portfolio_admin_form('', array('plugin' => $plugin, 'instance' => $instance, 'portfolio' => $portfolio, 'action' => $formaction, 'visible' => $visible));
00075     // End setup, begin output
00076     if ($mform->is_cancelled()){
00077         redirect($baseurl);
00078         exit;
00079     } else if (($fromform = $mform->get_data()) && (confirm_sesskey())) {
00080         // Unset whatever doesn't belong in fromform
00081         foreach (array('pf', 'action', 'plugin', 'sesskey', 'submitbutton') as $key) {
00082             unset($fromform->{$key});
00083         }
00084         // This branch is where you process validated data.
00085         if ($action == 'edit') {
00086             $instance->set_config((array)$fromform);
00087             $instance->save();
00088         } else {
00089             portfolio_static_function($plugin, 'create_instance', $plugin, $fromform->name, $fromform);
00090         }
00091         $savedstr = get_string('instancesaved', 'portfolio');
00092         redirect($baseurl, $savedstr, 1);
00093         exit;
00094     } else {
00095         echo $OUTPUT->header();
00096         echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
00097         echo $OUTPUT->box_start();
00098         $mform->display();
00099         echo $OUTPUT->box_end();
00100         $return = false;
00101     }
00102 } else if (($action == 'hide') || ($action == 'show')) {
00103     require_sesskey();
00104 
00105     $instance = portfolio_instance($portfolio);
00106     $current = $instance->get('visible');
00107     if (empty($current) && $instance->instance_sanity_check()) {
00108         print_error('cannotsetvisible', 'portfolio', $baseurl);
00109     }
00110 
00111     if ($action == 'show') {
00112         $visible = 1;
00113     } else {
00114         $visible = 0;
00115     }
00116 
00117     $instance->set('visible', $visible);
00118     $instance->save();
00119     $return = true;
00120 } else if ($action == 'delete') {
00121     $instance = portfolio_instance($portfolio);
00122     if ($sure) {
00123         if (!confirm_sesskey()) {
00124             print_error('confirmsesskeybad', '', $baseurl);
00125         }
00126         if ($instance->delete()) {
00127             $deletedstr = get_string('instancedeleted', 'portfolio');
00128             redirect($baseurl, $deletedstr, 1);
00129         } else {
00130             print_error('instancenotdeleted', 'portfolio', $baseurl);
00131         }
00132         exit;
00133     } else {
00134         echo $OUTPUT->header();
00135         echo $OUTPUT->confirm(get_string('sure', 'portfolio', $instance->get('name')), $sesskeyurl . '&pf='.$portfolio.'&action=delete&sure=yes', $baseurl);
00136         $return = false;
00137     }
00138 } else {
00139     // If page is loaded directly
00140     echo $OUTPUT->header();
00141     echo $OUTPUT->heading(get_string('manageportfolios', 'portfolio'));
00142 
00143     // Get strings that are used
00144     $strshow = get_string('on', 'portfolio');
00145     $strhide = get_string('off', 'portfolio');
00146     $strdelete = get_string('disabledinstance', 'portfolio');
00147     $strsettings = get_string('settings');
00148 
00149     $actionchoicesforexisting = array(
00150         'show' => $strshow,
00151         'hide' => $strhide,
00152         'delete' => $strdelete
00153     );
00154 
00155     $actionchoicesfornew = array(
00156         'newon' => $strshow,
00157         'newoff' => $strhide,
00158         'delete' => $strdelete
00159     );
00160 
00161     $output = $OUTPUT->box_start('generalbox');
00162 
00163     $plugins = get_plugin_list('portfolio');
00164     $plugins = array_keys($plugins);
00165     $instances = portfolio_instances(false, false);
00166     $usedplugins = array();
00167 
00168     // to avoid notifications being sent out while admin is editing the page
00169     define('ADMIN_EDITING_PORTFOLIO', true);
00170 
00171     $insane = portfolio_plugin_sanity_check($plugins);
00172     $insaneinstances = portfolio_instance_sanity_check($instances);
00173 
00174     $table = new html_table();
00175     $table->head = array(get_string('plugin', 'portfolio'), '', '');
00176     $table->data = array();
00177 
00178     foreach ($instances as $i) {
00179         $settings = '<a href="' . $sesskeyurl . '&amp;action=edit&amp;pf=' . $i->get('id') . '">' . $strsettings .'</a>';
00180         // Set some commonly used variables
00181         $pluginid = $i->get('id');
00182         $plugin = $i->get('plugin');
00183         $pluginname = $i->get('name');
00184 
00185         // Check if the instance is misconfigured
00186         if (array_key_exists($plugin, $insane) || array_key_exists($pluginid, $insaneinstances)) {
00187             if (!empty($insane[$plugin])) {
00188                 $information = $insane[$plugin];
00189             } else if (!empty($insaneinstances[$pluginid])) {
00190                 $information = $insaneinstances[$pluginid];
00191             }
00192             $table->data[] = array($pluginname, $strdelete  . " " . $OUTPUT->help_icon($information, 'portfolio_' .  $plugin), $settings);
00193         } else {
00194             if ($i->get('visible')) {
00195                 $currentaction = 'show';
00196             } else {
00197                 $currentaction = 'hide';
00198             }
00199             $select = new single_select(portfolio_action_url($pluginid, 'pf'), 'action', $actionchoicesforexisting, $currentaction, null, 'applyto' . $pluginid);
00200             $table->data[] = array($pluginname, $OUTPUT->render($select), $settings);
00201         }
00202         if (!in_array($plugin, $usedplugins)) {
00203             $usedplugins[] = $plugin;
00204         }
00205     }
00206 
00207     // Create insane plugin array
00208     $insaneplugins = array();
00209     if (!empty($plugins)) {
00210         foreach ($plugins as $p) {
00211             // Check if it can not have multiple instances and has already been used
00212             if (!portfolio_static_function($p, 'allows_multiple_instances') && in_array($p, $usedplugins)) {
00213                 continue;
00214             }
00215 
00216             // Check if it is misconfigured - if so store in array then display later
00217             if (array_key_exists($p, $insane)) {
00218                 $insaneplugins[] = $p;
00219             } else {
00220                 $select = new single_select(portfolio_action_url($p, 'pf'), 'action', $actionchoicesfornew, 'delete', null, 'applyto' . $p);
00221                 $table->data[] = array(portfolio_static_function($p, 'get_name'), $OUTPUT->render($select), '');
00222             }
00223         }
00224     }
00225 
00226     // Loop through all the insane plugins
00227     if (!empty($insaneplugins)) {
00228         foreach ($insaneplugins as $p) {
00229             $table->data[] = array(portfolio_static_function($p, 'get_name'), $strdelete . " " . $OUTPUT->help_icon($insane[$p], 'portfolio_' .  $p), '');
00230         }
00231     }
00232 
00233     $output .= html_writer::table($table);
00234 
00235     $output .= $OUTPUT->box_end();
00236 
00237     echo $output;
00238     $return = false;
00239 }
00240 
00241 if ($return) {
00242     // Redirect to base
00243     redirect($baseurl);
00244 }
00245 
00246 echo $OUTPUT->footer();
00247 
 All Data Structures Namespaces Files Functions Variables Enumerations