Various little fixes.

This commit is contained in:
moodler 2006-03-26 05:03:10 +00:00
parent 3620b8dccf
commit 473dd2888b
7 changed files with 58 additions and 85 deletions

View file

@ -1,39 +0,0 @@
<?php // $Id$
require_once('../../config.php');
require_once('lib.php');
require_login();
$recordid = required_param('recordid',PARAM_INT);
$page = optional_param('page','0',PARAM_INT);
$rid = optional_param('rid','0', PARAM_INT);
$search = optional_param('search','',PARAM_ALPHA);
$sort = optional_param('sort','',PARAM_ALPHA);
$order = optional_param('order','',PARAM_ALPHA);
if (! $record = get_record('data_records', 'id', $recordid)) {
error('Record ID is incorrect');
}
if (! $data = get_record('data', 'id', $record->dataid)) {
error('Data ID is incorrect');
}
if (! $course = get_record('course', 'id', $data->course)) {
error('Course is misconfigured');
}
if (!isteacher($course->id)) {
error(get_string('errormustbeteacher', 'data'));
}
if (confirm_sesskey()) { /* Approve it! */
$newrecord->id = $record->id;
$newrecord->approved = 1;
update_record('data_records', $newrecord);
}
redirect('view.php?d='.$d.'&amp;approved=1&amp;page='.$page.'&amp;rid='.$rid.'&amp;search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;', get_string('recordapproved','data'));
?>

View file

@ -80,27 +80,31 @@ class data_field_picture extends data_field_file {
$contents[1] = $content->content1;
}
if (empty($contents[0])) { // Nothing to show
return '';
}
$alt = empty($contents[1])? '':$contents[1];
$title = empty($contents[1])? '':$contents[1];
$src = empty($contents[0])? '':$contents[0];
$src = $contents[0];
$path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
if ($CFG->slasharguments) {
$source = $CFG->wwwroot.'/file.php/'.$path;
$source = $CFG->wwwroot.'/file.php/'.$path.'/'.$src;
} else {
$source = $CFG->wwwroot.'/file.php?file=/'.$path;
$source = $CFG->wwwroot.'/file.php?file=/'.$path.'/'.$src;
}
if ($template == 'listtemplate') {
$width = $this->field->param4 ? ' width="'.$this->field->param4.'" ' : ' ';
$height = $this->field->param5 ? ' height="'.$this->field->param5.'" ' : ' ';
$str = '<a href="view.php?d='.$this->field->dataid.'&amp;rid='.$recordid.'"><img '.
$width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" border="0" /></a>';
$width.$height.' src="'.$source.'" alt="'.$alt.'" title="'.$title.'" border="0" /></a>';
} else {
$width = $this->field->param1 ? ' width="'.$this->field->param1.'" ':' ';
$height = $this->field->param2 ? ' height="'.$this->field->param2.'" ':' ';
$str = '<img '.$width.$height.' src="'.$source.'/'.$src.'" alt="'.$alt.'" title="'.$title.'" />';
$str = '<a href="'.$source.'"><img '.$width.$height.' src="'.$source.'" alt="'.$alt.'" title="'.$title.'" border="0"/></a>';
}
return $str;
}

View file

@ -45,7 +45,7 @@ class data_field_url extends data_field_base {
$url = empty($url) ? 'http://' : $url;
$str = '<div title="'.$this->field->description.'">';
if (!empty($this->field->param1)) {
if (!empty($this->field->param1) and empty($this->field->param2)) {
$str .= '<table><tr><td align="right">';
$str .= get_string('url','data').':</td><td><input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.$url.'" size="60" /></td></tr>';
$str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.$text.'" size="60" /></td></tr>';
@ -63,6 +63,14 @@ class data_field_url extends data_field_base {
$url = empty($content->content)? '':$content->content;
$text = empty($content->content1)? '':$content->content1;
if (empty($url) or ($url == 'http://')) {
return '';
}
if (!empty($this->field->param2)) { // param2 forces the text to something
$text = $this->field->param2;
}
if ($this->field->param1) { // param1 defines whether we want to autolink the url.
if (!empty($text)) {
$str = '<a href="'.$url.'">'.$text.'</a>';

View file

@ -7,6 +7,10 @@
<td class="c0"> <?php echo get_string('fielddescription', 'data'); ?>: </td>
<td class="c1"> <input class="fielddescription" type="text" name="description" id="description" value = "<?php echo ($this->field->description);?>" /> </td>
</tr>
<tr>
<td class="c0"> <?php echo get_string('forcelinkname', 'data'); ?>: </td>
<td class="c1"> <input class="forcelinkname" type="text" name="param2" id="forcelinkname" value = "<?php echo ($this->field->param2);?>" /> </td>
</tr>
<tr>
<td class="c0"><?php echo get_string('autolinkurl', 'data') ?></td>
<td class="c1"><input type="checkbox" name="param1" id="param1" <?php if($this->field->param1) {echo 'checked="checked"';} ?> value="1" /></td>

View file

@ -828,12 +828,8 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
$record = get_record('data_records','id',$record->id);
///replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='/\#\#Edit\#\#/i';
$patterns[]='/\#\#Delete\#\#/i';
$patterns[]='/\#\#More\#\#/i';
$patterns[]='/\#\#Approve\#\#/i';
$patterns[]='/\#\#Comment\#\#/i';
$patterns[]='/\#\#Edit\#\#/i';
if (data_isowner($record->id) or isteacheredit($course->id)){
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/add.php?d='
.$data->id.'&amp;rid='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.get_string('edit').'" /></a>';
@ -841,20 +837,28 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
$replacement[] = '';
}
$patterns[]='/\#\#Delete\#\#/i';
if (data_isowner($record->id) or isteacheredit($course->id)){
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
.$data->id.'&amp;delete='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.get_string('delete').'" /></a>';
.$data->id.'&amp;rid='.$record->id.'&amp;delete='.$record->id.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.get_string('delete').'" /></a>';
}else {
$replacement[] = '';
}
$patterns[]='/\#\#More\#\#/i';
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$record->id.'&amp;search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;group='.$group.'&amp;"><img src="'.$CFG->pixpath.'/i/search.gif" height="11" width="11" border="0" alt="'.get_string('more').'" /></a>';
$patterns[]='/\#\#MoreURL\#\#/i';
$replacement[] = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$record->id.'&amp;search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;group='.$group;
$patterns[]='/\#\#Approve\#\#/i';
if (isteacher($course->id) && ($data->approval) && (!$record->approved)){
$replacement[] = data_print_approve_button($record->id, $data->id, $page, $rid, $search, $sort, $order);
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$record->id.'&amp;approve='.$record->id.'&search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;group='.$group.'&amp;sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/show.gif" height="11" width="11" border="0" alt="'.get_string('approve').'" /></a>';
} else {
$replacement[] = '';
}
$patterns[]='/\#\#Comment\#\#/i';
if (($template == 'listtemplate') && ($data->comments)) {
$comments = count_records('data_comments','recordid',$record->id);
$replacement[] = '<a href="comment.php?recordid='.$record->id.'&amp;d='.$data->id.'&amp;search='.$search.'&amp;sort='.$sort.'&amp;order='.$order.'&amp;group='.$group.'&amp;page='.$page.'">'.$comments.' '.get_string('comment','data').'</a>';
@ -884,7 +888,6 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
data_print_comments($data, $record, $search, $template, $sort, $page, $rid, $order, $group);
}
//if this record is not yet approved, and database requires approval, print silly button
}
}
@ -899,8 +902,9 @@ function data_print_template($records, $data, $search, $template, $sort, $page=0
************************************************************************/
function data_print_preference_form($data, $perpage, $search, $sort='', $order='ASC'){
echo '<br />';
echo '<form name="options" action="view.php?d='.$data->id.'&amp;search='.s($search).'&amp;sort='.s($sort).'&amp;order='.s($order).'" method="post">';
echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
echo '<form name="options" action="view.php" method="get">';
echo '<input type="hidden" name="d" value="'.$data->id.'" />';
echo '<input type="hidden" name="updatepref" value="1" />';
echo '<table id="sortsearch" align="center">';
echo '<tr>'.
'<td class="c0 r1">'.get_string('pagesize','data').':</td>';
@ -945,27 +949,10 @@ function data_print_preference_form($data, $perpage, $search, $sort='', $order='
echo '<td colspan="2" align="center" class="r3">';
echo '<input type="submit" value="'.get_string('savesettings','data').'" />';
echo '</td></tr></table>';
echo '<input type="hidden" name="updatepref" value="1" />';
echo '</form>';
}
//silly function that prints a button
function data_print_approve_button($recordid, $d, $page='0', $rid='0', $search='', $sort='', $order='') {
$str= '<div align="center"><form action="approve.php" method="get">';
$str.= '<input type="hidden" name="d" value="'.$d.'" />';
$str.= '<input type="hidden" name="rid" value="'.$rid.'" />';
$str.= '<input type="hidden" name="page" value="'.$page.'" />';
$str.= '<input type="hidden" name="search" value="'.$search.'" />';
$str.= '<input type="hidden" name="sort" value="'.$sort.'" />';
$str.= '<input type="hidden" name="order" value="'.$order.'" />';
$str.= '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
$str.= '<input type="hidden" name="recordid" value="'.$recordid.'" />';
$str.= '<input type="submit" value="'.get_string('approve').'" />';
$str.= '</form></div>';
return $str;
}
//silly function that prints the a form to do ratings
function data_print_ratings($data, $record) {
global $USER, $course;
$ratingsmenuused = false;
@ -1118,7 +1105,6 @@ function data_print_comments($data, $record , $search, $template, $sort, $page=0
}
}
//prints silly comment form
echo '<p /><div align="center"><form method="post" action="comment.php">';
echo '<input type="hidden" name="mode" value="add" />';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';

View file

@ -178,6 +178,7 @@
// Print special tags.
echo '<option value="##edit##">##' .get_string('edit', 'data'). '##</option>';
echo '<option value="##more##">##' .get_string('more', 'data'). '##</option>';
echo '<option value="##moreurl##">##' .get_string('moreurl', 'data'). '##</option>';
echo '<option value="##delete##">##' .get_string('delete', 'data'). '##</option>';
echo '<option value="##approve##">##' .get_string('approve', 'data'). '##</option>';
echo '<option value="##comments##">##' .get_string('comments', 'data'). '##</option>';

View file

@ -35,6 +35,8 @@
$search = optional_param('search','',PARAM_NOTAGS); //search string
$page = optional_param('page', 0, PARAM_INT); //offset of the current record
$rid = optional_param('rid', 0, PARAM_INT); //record id
$approve = optional_param('approve', 0, PARAM_INT); //approval recordid
$delete = optional_param('delete', 0, PARAM_INT); //delete recordid
$perpagemenu = optional_param('perpage1', 0, PARAM_INT); //value from drop down
$sort = optional_param('sort',0,PARAM_INT); //sort by field
$order = optional_param('order','ASC',PARAM_ALPHA); //sort order
@ -71,7 +73,7 @@
}
//set user preference if available
if (isset($_POST['updatepref'])){
if (isset($_GET['updatepref'])){
if (!$perpage = $perpagemenu){ //if menu not in use, use the text field
$perpage = (int)optional_param('perpage',10);
@ -156,16 +158,23 @@
$currenttab = 'browse';
include('tabs.php');
/// Print the browsing interface
/// Approve any requested records
if (optional_param('approved','0',PARAM_INT)) {
print_heading(get_string('recordapproved','data'));
if ($approve && confirm_sesskey() && isteacher($course->id)) {
if ($record = get_record('data_records', 'id', $approve)) { // Need to check this is valid
if ($record->dataid == $data->id) { // Must be from this database
$newrecord->id = $record->id;
$newrecord->approved = 1;
if (update_record('data_records', $newrecord)) {
notify(get_string('recordapproved','data'), 'notifysuccess');
}
}
}
}
/***************************
* code to delete a record *
***************************/
if (($delete = optional_param('delete',0,PARAM_INT)) && confirm_sesskey()) {
/// Delete any requested records
if ($delete && confirm_sesskey()) {
if (isteacheredit($course) or data_isowner($delete)){
if ($confirm = optional_param('confirm',0,PARAM_INT)) {
if ($contents = get_records('data_content','recordid', $delete)) {
@ -193,7 +202,7 @@
}
}
//if not editting teacher, check whether user has sufficient records to view
// If not editting teacher, check whether user has sufficient records to view
if (!isteacheredit($course->id) and data_numentries($data) < $data->requiredentriestoview){
notify (($data->requiredentriestoview - data_numentries($data)).'&nbsp;'.get_string('insufficiententries','data'));
echo '</td></tr></table>';