course = sloodle_get_record('course', 'id', $id)) error('Could not find course.'); $this->sloodle_course = new SloodleCourse(); if (!$this->sloodle_course->load($this->course)) error(s(get_string('failedcourseload', 'sloodle'))); } function process_form() { //mode is for the different editing tasks of the currency screen (add, modify, delete) $mode = optional_param('mode', "view", PARAM_TEXT); if ( ($mode != 'view') && (!$this->can_edit) ) { print_error('Permission denied'); } switch($mode) { case "modify": //get vars $currencyid = required_param('currencyid', PARAM_INT); $currencyname = required_param('currencyname', PARAM_TEXT); $imageurl = required_param('imageurl', PARAM_URL); $displayorder = required_param('displayorder', PARAM_INT); //create update object $currency = new stdClass(); $currency->id = $currencyid; $currency->name = $currencyname; $currency->displayorder = $displayorder; $currency->imageurl = ($imageurl != "") ? $imageurl : null; //update $result = sloodle_update_record('sloodle_currency_types',$currency); if (!$result) { $errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}"; print_error(get_string('general:fail','sloodle'),$errorlink); } break; case "add": //get vars $currencyname = required_param('currencyname', PARAM_TEXT); $imageurl = optional_param('imageurl', '', PARAM_URL); $displayorder = optional_param('displayorder', 0, PARAM_INT); //create update object $currency = new stdClass(); $currency->name=$currencyname; $currency->displayorder = $displayorder; $currency->imageurl = $imageurl; //update $result = sloodle_insert_record('sloodle_currency_types',$currency); if (!$result) { $errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}"; print_error(get_string('general:fail','sloodle'),$errorlink); } break; case "confirmdelete": $currencyid= required_param('currencyid', PARAM_INT); $result = sloodle_delete_records('sloodle_currency_types','id',$currencyid); if (!$result) { $errorlink = $CFG->wwwroot."/mod/sloodle/view.php?_type=currency&id={$id}"; print_error(get_string('general:fail','sloodle'),$errorlink); } break; default: break; } } /** * Check that the user is logged-in and has permission to alter course settings. */ function check_permission() { // Ensure the user logs in require_login($this->course->id); if (isguestuser()) error(get_string('noguestaccess', 'sloodle')); add_to_log($this->course->id, 'course', 'view sloodle data', '', "{$this->course->id}"); // Ensure the user is allowed to update information on this course $this->course_context = get_context_instance(CONTEXT_COURSE, $this->course->id); if (has_capability('moodle/course:update', $this->course_context)) $this->can_edit = true; } /** * Print the course settings page header. */ function sloodle_print_header() { global $CFG; $id = required_param('id', PARAM_INT); $navigation = "wwwroot}/mod/sloodle/view.php?&_type=currency&mode=allcurrencies&id={$id}\">".get_string('currencies:view', 'sloodle').""; sloodle_print_header_simple(get_string('backpack','sloodle'), " ", $navigation, "", "", true, '', false); } /** * Render the view of the module or feature. * This MUST be overridden to provide functionality. */ function render() { $view = optional_param('view', "", PARAM_TEXT); $mode= optional_param('mode', "allcurrencies", PARAM_TEXT); switch ($mode){ case "allcurrencies": $this->render_all_currencies(); break; case "editcurrency": $this->render_edit_currency(); break; case "deletecurrency": $this->delete_currency(); break; default: $this->render_all_currencies(); break; } } function render_all_currencies() { global $CFG; global $COURSE; $id = required_param('id', PARAM_INT); // Display instrutions for this page echo "
"; sloodle_print_box_start('generalbox boxaligncenter center boxheightnarrow leftpara'); echo '
'; echo ''; echo ''; echo get_string('currency:currencies', 'sloodle'); echo ''; echo ''; echo ''; echo get_string('backpacks:viewbackpacks', 'sloodle').'
'; echo '
'; echo '
'; echo '
'; //create an html table to display the users $sloodletable = new stdClass(); $sloodletable->head = array( s(get_string('currencies:displayorder', 'sloodle')), s(get_string('currencies:icon', 'sloodle')), s(get_string('currencies:name', 'sloodle')), "" ); //set alignment of table cells $sloodletable->align = array('left','left','left'); $sloodletable->width="95%"; //set size of table cells $sloodletable->size = array('10%','5%','50%','45%','25%'); //get currencies //sloodle_get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') $currencyTypes = SloodleCurrency::FetchAll(); foreach ($currencyTypes as $c){ $rowData=array(); //cell 1 - display order $rowData[]= $c->displayorder; //cell 2 - image icon if (isset($c->imageurl)){ $rowData[] = ''; } else { $rowData[] = ""; } //cell 3 - currency name $rowData[]= $c->name; //cell 4 - image url // $rowData[]= $c->imageurl; //cell 5 - edit action $editText= "wwwroot}/mod/sloodle/view.php?&"; $editText.= "_type=currency"; $editText.= "¤cyid=".$c->id; $editText.= "¤cyname=".urlencode($c->name); $editText.= "&mode=editcurrency"; $editText.= "&id={$COURSE->id}"; $editText.= "\">"; $editText.="\"".get_string('currencies:edit', "; $editText.= ""; $editText.= "  "; $editText.= "id; $editText.= "¤cyname=".urlencode($c->name); $editText.= "&mode=deletecurrency"; $editText.= "&id={$COURSE->id}"; $editText.= "\">"; $editText.="\"".s(get_string('currencies:delete', "; $editText.= ""; $rowData[]= $this->can_edit ? $editText : ' '; $sloodletable->data[]=$rowData; } sloodle_print_table($sloodletable); sloodle_print_box_end(); //create an html table to display the users $sloodletable = new stdClass(); $sloodletable->head = array( s(get_string('currencies:displayorder', 'sloodle')), s(get_string('currencies:icon', 'sloodle')), s(get_string('currencies:name', 'sloodle')), s(get_string('currencies:imageurl', 'sloodle')), "" ); //set alignment of table cells $sloodletable->align = array('left','left','left'); $sloodletable->width="55%"; //set size of table cells $sloodletable->size = array('10%','5%','50%','45%','25%'); if ($this->can_edit) { print('
'); //create cells for add row $cells = array(); //cell 1 -display order $cells[]=' '; //cell 2 - icon - blank $cells[]=""; //cell 3 - name $cells[]=''; //cell 4 - imageurl $cells[]=''; //cell 5- add $cells[]=''; $sloodletable->data[]=$cells; sloodle_print_box_start('generalbox boxaligncenter center boxheightnarrow leftpara'); print "

"; print s(get_string('currency:addnew','sloodle')); print "

"; sloodle_print_table($sloodletable); print("
"); } sloodle_print_box_end(); } function delete_currency() { global $CFG; global $COURSE; $id = required_param('id', PARAM_INT); $currencyname= optional_param('currencyname', '', PARAM_TEXT); $currencyid= required_param('currencyid', PARAM_INT); echo "
"; //print header box sloodle_print_box_start('generalbox boxaligncenter right boxwidthnarrow boxheightnarrow rightpara'); echo "

"; echo get_string('currency:confirmdelete', 'sloodle')."

"; sloodle_print_box_end(); //display all currencies sloodle_print_box_start('generalbox boxaligncenter boxwidthfull leftpara'); print('
'); $c = sloodle_get_record('sloodle_currency_types','id',$currencyid); $sloodletable = new stdClass(); //set up column headers table data $sloodletable->head = array( s(get_string('currencies:icon', 'sloodle')), s(get_string('currencies:name', 'sloodle')), " " ); $sloodletable->align = array('left','left','left'); $sloodletable->width="95%"; $sloodletable->size = array('10%','50%','30%'); //create cells for row $row = array(); //cell 1 -icon if (isset($c->imageurl)&&!empty($c->imageurl)){ $row[]= ''; } else { $row[]= " "; } //cell 2 - name $row[]=' '.s($c->name); //cell 4 - submit $row[]=''; $sloodletable->data[]=$row; sloodle_print_table($sloodletable); } function render_edit_currency() { global $CFG; global $COURSE; $id = required_param('id', PARAM_INT); $currencyname= required_param('currencyname', PARAM_TEXT); $currencyid= required_param('currencyid', PARAM_INT); echo "
"; //print header box sloodle_print_box_start('generalbox boxaligncenter center boxwidthnarrow boxheightnarrow leftpara'); echo "

"; echo get_string('currency:editcurrency', 'sloodle')."

"; sloodle_print_box_end(); //display all currencies sloodle_print_box_start('generalbox boxaligncenter boxwidthfull leftpara'); print(''); $c= sloodle_get_record('sloodle_currency_types','id',$currencyid); $sloodletable = new stdClass(); //set up column headers table data $sloodletable->head = array( s(get_string('currencies:displayorder', 'sloodle')), s(get_string('currencies:imageurl', 'sloodle')), s(get_string('currencies:name', 'sloodle')), " " ); $sloodletable->align = array('left','left','left'); $sloodletable->width="95%"; $sloodletable->size = array('10%','50%','30%','15%'); //create cells for row $row = array(); //cell 1 -display order $row[]=' '; //cell 2 - imageurl $row[]=' '; //cell 3 - name $row[]=''; //cell 4 - submit $row[]=''; $sloodletable->data[]=$row; sloodle_print_table($sloodletable); print("
"); } }