}
require_course_login($course, false, $cm);
+
+ if (!isloggedin() or isguest()) {
+ redirect('view.php?d='.$data->id);
+ }
/// If it's hidden then it's don't show anything. :)
if (empty($cm->visible) and !isteacher($course->id)) {
/// Check to see if groups are being used here
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
- $currentgroup = setup_and_print_groups($course, $groupmode, 'add.php?d='.$data->id.'&sesskey='.sesskey().'&');
+ $currentgroup = setup_and_print_groups($course, $groupmode, 'edit.php?d='.$data->id.'&sesskey='.sesskey().'&');
} else {
$currentgroup = 0;
}
/// Process incoming data for adding/updating records
- if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/add.php') and confirm_sesskey()) {
+ if ($datarecord = data_submitted($CFG->wwwroot.'/mod/data/edit.php') and confirm_sesskey()) {
$ignorenames = array('MAX_FILE_SIZE','sesskey','d','rid'); // strings to be ignored in input data
add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&rid=$recordid", $data->id, $cm->id);
notify(get_string('entrysaved','data'));
+
+ if (!empty($datarecord->saveandview)) {
+ redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$rid);
+ }
}
}
} // End of form processing
$replacement = array(); //html to replace those yucky tags
//form goes here first in case add template is empty
- echo '<form enctype="multipart/form-data" action="add.php" method="post">';
+ echo '<form enctype="multipart/form-data" action="edit.php" method="post">';
echo '<input name="d" value="'.$data->id.'" type="hidden" />';
echo '<input name="rid" value="'.$rid.'" type="hidden" />';
echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
}
echo $newtext;
- echo '<div align="center"><input type="submit" value="'.get_string('save','data').'" />';
- if ($rid){
- echo ' <input type="submit" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)">';
+ echo '<div align="center"><input type="submit" name="saveandview" value="'.get_string('saveandview','data').'" />';
+ if ($rid) {
+ echo ' <input type="submit" name="cancel" value="'.get_string('cancel').'" onclick="javascript:history.go(-1)">';
+ } else {
+ echo '<input type="submit" value="'.get_string('saveandadd','data').'" />';
}
echo '</div>';
print_simple_box_end();
print_simple_box_end();
} else {
echo '<div align="center">';
- echo '<a href="add.php?d='.$data->id.'&import=1">'.get_string('uploadrecords', 'data').'</a>';
+ echo '<a href="edit.php?d='.$data->id.'&import=1">'.get_string('uploadrecords', 'data').'</a>';
echo '</div>';
}
}
}
}
+ function get_sort_sql($fieldname) {
+ return 'CAST('.$fieldname.' AS unsigned)';
+ }
+
}
$table->align = array ('center', 'center', 'center', 'center');
}
+ $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
+
+ if ($rss) {
+ require_once($CFG->libdir."/rsslib.php");
+ array_push($table->head, 'RSS');
+ array_push($table->align, 'center');
+ }
+
$currentgroup = get_current_group($course->id);
if ($currentgroup and isteacheredit($course->id)) {
$group = get_record("groups", "id", $currentgroup);
} else {
$numunapprovedrecords = get_string('noapprovalrequired', 'data');
}
+
+ $rsslink = '';
+ if ($rss && $data->rssarticles > 0) {
+ $rsslink = rss_get_link($course->id, $USER->id, 'data', $data->id, 'RSS');
+ }
if ($course->format == 'weeks' or $course->format == 'topics') {
if ($data->section !== $currentsection) {
}
$currentsection = $data->section;
}
+ $row = array ($printsection, $link, $data->intro, $numrecords, $numunapprovedrecords);
- $table->data[] = array ($printsection, $link, $data->intro, $numrecords, $numunapprovedrecords);
} else {
- $table->data[] = array ($link, $data->intro, $numrecords, $numunapprovedrecords);
+ $row = array ($link, $data->intro, $numrecords, $numunapprovedrecords);
}
+
+ if ($rss) {
+ array_push($row, $rsslink);
+ }
+
+ $table->data[] = $row;
}
echo "<br />";
return 'content';
}
+/// Returns the SQL needed to refer to the column. Some fields may need to CAST() etc.
+ function get_sort_sql($fieldname) {
+ return $fieldname;
+ }
+
/// Returns the name/type of the field
function name(){
return get_string('name'.$this->type, 'data');
* @param string $template *
* output null *
************************************************************************/
-function data_print_template($template, $records, $data, $search='',$page=0, $return=false){
+function data_print_template($template, $records, $data, $search='',$page=0, $return=false) {
global $CFG;
static $fields = NULL;
$isteacher = isteacher($data->course);
}
- foreach ($records as $record) { //only 1 record for single mode
+ if (empty($records)) {
+ return;
+ }
+
+ foreach ($records as $record) { /// Might be just one for the single template
/// Replacing tags
$patterns = array();
$patterns[]='/\#\#Edit\#\#/i';
$patterns[]='/\#\#Delete\#\#/i';
if ($isteacher or data_isowner($record->id)) {
- $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/add.php?d='
+ $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/edit.php?d='
.$data->id.'&rid='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.get_string('edit').'" /></a>';
$replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='
.$data->id.'&delete='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.get_string('delete').'" /></a>';
$patterns[]='/\#\#MoreURL\#\#/i';
$replacement[] = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&rid='.$record->id;
+ $patterns[]='/\#\#User\#\#/i';
+ $replacement[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$record->userid.
+ '&course='.$data->course.'">'.fullname($record).'</a>';
$patterns[]='/\#\#Approve\#\#/i';
if ($isteacher && ($data->approval) && (!$record->approved)){
- $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/show.gif" height="11" width="11" border="0" alt="'.get_string('approve').'" /></a>';
+ $replacement[] = '<a href="'.$CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&approve='.$record->id.'&sesskey='.sesskey().'"><img src="'.$CFG->pixpath.'/i/approve.gif" height="11" width="11" border="0" alt="'.get_string('approve').'" /></a>';
} else {
$replacement[] = '';
}
- $patterns[]='/\#\#Comment\#\#/i';
+ $patterns[]='/\#\#Comments\#\#/i';
if (($template == 'listtemplate') && ($data->comments)) {
$comments = count_records('data_comments','recordid',$record->id);
- $replacement[] = '<a href="comment.php?rid='.$record->id.'&page='.$page.'">'.$comments.' '.get_string('comment','data').'</a>';
+ $replacement[] = '<a href="view.php?rid='.$record->id.'#comments">'.get_string('comments','data', $comments).'</a>';
} else {
$replacement[] = '';
}
//prints all comments + a text box for adding additional comment
function data_print_comments($data, $record, $page=0) {
+ echo '<a name="comments"></a>';
+
if ($comments = get_records('data_comments','recordid',$record->id)) {
foreach ($comments as $comment) {
data_print_comment($data, $comment, $page);
if (!$firstfield = get_record_sql('SELECT id,name from '.$CFG->prefix.'data_fields WHERE dataid = '.$data->id.' ORDER by id', true)) {
continue;
}
-
+
+
// Get the data_records out.
+ $approved = ($data->approval) ? ' AND dr.approved = 1 ' : ' ';
+
$sql = 'SELECT dr.* ' .
"FROM {$CFG->prefix}data_records AS dr " .
- "WHERE dr.dataid = {$data->id} " .
+ "WHERE dr.dataid = {$data->id} " .$approved.
'ORDER BY dr.timecreated DESC ' .
"LIMIT {$data->rssarticles}";
$row[] = new tabobject('single', $CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&mode=single', get_string('single','data'), '', true);
}
- if (isteacher($course->id) or ($data->participants == DATA_STUDENTS_ONLY) or ($data->participants == DATA_TEACHERS_AND_STUDENTS)){
- $addstring = empty($editentry) ? get_string('add', 'data') : get_string('editentry', 'data');
- $row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/add.php?d='.$data->id, $addstring, '', true);
- }
- if (isteacher($course->id)) {
- if ($currenttab == 'list') {
- $defaultemplate = 'listtemplate';
- } else if ($currenttab == 'add') {
- $defaultemplate = 'addtemplate';
- } else {
- $defaultemplate = 'singletemplate';
+ if (isloggedin() and !isguest()) {
+ if (isteacher($course->id) or ($data->participants == DATA_STUDENTS_ONLY) or
+ ($data->participants == DATA_TEACHERS_AND_STUDENTS)){
+ $addstring = empty($editentry) ? get_string('add', 'data') : get_string('editentry', 'data');
+ $row[] = new tabobject('add', $CFG->wwwroot.'/mod/data/edit.php?d='.$data->id, $addstring, '', true);
+ }
+ if (isteacher($course->id)) {
+ if ($currenttab == 'list') {
+ $defaultemplate = 'listtemplate';
+ } else if ($currenttab == 'add') {
+ $defaultemplate = 'addtemplate';
+ } else {
+ $defaultemplate = 'singletemplate';
+ }
+
+ $row[] = new tabobject('templates', $CFG->wwwroot.'/mod/data/templates.php?d='.$data->id.
+ '&mode='.$defaultemplate, get_string('templates','data'));
+ $row[] = new tabobject('fields', $CFG->wwwroot.'/mod/data/field.php?d='.$data->id,
+ get_string('fields','data'), '', true);
}
-
- $row[] = new tabobject('templates', $CFG->wwwroot.'/mod/data/templates.php?d='.$data->id.'&mode='.$defaultemplate, get_string('templates','data'));
- $row[] = new tabobject('fields', $CFG->wwwroot.'/mod/data/field.php?d='.$data->id, get_string('fields','data'), '', true);
}
$tabs[] = $row;
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>';
+ echo '<option value="##user##">##' .get_string('user'). '##</option>';
echo '</select>';
echo '<br /><br /><br /><br /><input type="submit" name="defaultform" value="'.get_string('resettemplate','data').'" />';
echo '</td>';
/// RSS and CSS meta
$meta = '';
- if (isset($CFG->enablerssfeeds) && isset($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
+ if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
$rsspath = rss_get_url($course->id, $USER->id, 'data', $data->id);
$meta .= '<link rel="alternate" type="application/rss+xml" ';
$meta .= 'title ="'.$course->shortname.': %fullname%" href="'.$rsspath.'" />';
print_heading(format_string($data->name));
// Do we need to show a link to the RSS feed for the records?
- if (isset($CFG->enablerssfeeds) && isset($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
+ if (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds) && $data->rssarticles > 0) {
echo '<div style="float:right;">';
rss_print_link($course->id, $USER->id, 'data', $data->id, get_string('rsstype'));
echo '</div>';
echo '<div style="clear:both;"></div>';
}
- if ($data->intro and empty($sort) and empty($search) and empty($page) and empty($record)) {
+ if ($data->intro and empty($page) and empty($record)) {
print_simple_box(format_text($data->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
}
$currentgroup = 0;
}
-
-/// Print the tabs
-
- if ($record or $mode == 'single') {
- $currenttab = 'single';
- } else {
- $currenttab = 'list';
- }
- include('tabs.php');
-
-
-/// Approve any requested records
-
- if ($approve && confirm_sesskey() && isteacher($course->id)) {
- if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
- if ($approverecord->dataid == $data->id) { // Must be from this database
- $newrecord->id = $approverecord->id;
- $newrecord->approved = 1;
- if (update_record('data_records', $newrecord)) {
- notify(get_string('recordapproved','data'), 'notifysuccess');
- }
- }
- }
- }
-
/// Delete any requested records
if ($delete && confirm_sesskey() && (isteacher($course->id) or data_isowner($delete))) {
}
} else { // Print a confirmation page
- notice_yesno(get_string('confirmdeleterecord','data'),
- 'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
- 'view.php?d='.$data->id);
+ if ($deleterecord = get_record('data_records', 'id', $delete)) { // Need to check this is valid
+ if ($deleterecord->dataid == $data->id) { // Must be from this database
+ notice_yesno(get_string('confirmdeleterecord','data'),
+ 'view.php?d='.$data->id.'&delete='.$delete.'&confirm=1&sesskey='.sesskey(),
+ 'view.php?d='.$data->id);
- print_footer($course);
- exit;
+ $records[] = $deleterecord;
+ data_print_template('singletemplate', $records, $data);
+
+ print_footer($course);
+ exit;
+ }
+ }
+ }
+ }
+
+
+
+/// Print the tabs
+
+ if ($record or $mode == 'single') {
+ $currenttab = 'single';
+ } else {
+ $currenttab = 'list';
+ }
+ include('tabs.php');
+
+
+/// Approve any requested records
+
+ if ($approve && confirm_sesskey() && isteacher($course->id)) {
+ if ($approverecord = get_record('data_records', 'id', $approve)) { // Need to check this is valid
+ if ($approverecord->dataid == $data->id) { // Must be from this database
+ $newrecord->id = $approverecord->id;
+ $newrecord->approved = 1;
+ if (update_record('data_records', $newrecord)) {
+ notify(get_string('recordapproved','data'), 'notifysuccess');
+ }
+ }
}
}
$groupselect = ' ';
}
-
/// Find the field we are sorting on
if ($sort) {
$sortfield = data_get_field_from_id($sort, $data);
$sortcontent = $sortfield->get_sort_field();
+ $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
- $what = ' DISTINCT r.id, r.approved ';
+ $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(DISTINCT c.recordid) ';
- $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1 ';
+ $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r,'.$CFG->prefix.'data_content c1, '.$CFG->prefix.'user u ';
$where = 'WHERE c.recordid = r.id
AND c.fieldid = '.$sort.'
AND r.dataid = '.$data->id.'
+ AND r.userid = u.id
AND c1.recordid = r.id ';
- $sortorder = ' ORDER BY c.'.$sortcontent.' '.$order.' ';
+ $sortorder = ' ORDER BY '.$sortcontentfull.' '.$order.' ';
+ if ($search) {
+ $searchselect = ' AND (c1.content LIKE "%'.$search.'%") ';
+ } else {
+ $searchselect = ' ';
+ }
} else if ($search) {
- $what = ' DISTINCT r.id, r.approved ';
+ $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(DISTINCT c.recordid) ';
- $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r ';
+ $tables = $CFG->prefix.'data_content c,'.$CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
$where = 'WHERE c.recordid = r.id
+ AND r.userid = u.id
AND r.dataid = '.$data->id;
$sortorder = ' ORDER BY r.id ';
+ $searchselect = ' AND (c.content LIKE "%'.$search.'%") ';
} else {
- $what = ' DISTINCT r.id, r.approved ';
+ $what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(r.id) ';
- $tables = $CFG->prefix.'data_records r ';
- $where = 'WHERE r.dataid = '.$data->id;
- $sortorder = ' ORDER BY r.id ';
- }
-
-/// Restrict by a search if we have one
-
- if ($search) {
- $searchselect = ' AND (c.content LIKE "%'.$search.'%") ';
- } else {
+ $tables = $CFG->prefix.'data_records r, '.$CFG->prefix.'user u ';
+ $where = 'WHERE r.dataid = '.$data->id. ' AND r.userid = u.id ';
+ $sortorder = ' ORDER BY r.timecreated '.$order. ' ';
$searchselect = ' ';
}
+
/// To actually fetch the records
$fromsql = ' FROM '.$tables.$where.$groupselect.$approveselect.$searchselect;
if ($record) { // We need to just show one, so where is it in context?
$nowperpage = 1;
$mode = 'single';
- if ($sort) { // We need to search by that field
- if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
- $content = addslashes($content);
- if ($order == 'ASC') {
- $lessthan = " AND c.$sortcontent < '$content' ";
- } else {
- $lessthan = " AND c.$sortcontent > '$content' ";
- }
- } else { // Failed to find data (shouldn't happen), so fall back to something easy
- $lessthan = " r.id < '$record->id' ";
+# if ($sort) { // We need to search by that field
+# if ($content = get_field('data_content', 'content', 'recordid', $record->id, 'fieldid', $sort)) {
+# $content = addslashes($content);
+# if ($order == 'ASC') {
+# $lessthan = " AND $sortcontentfull < '$content' ";
+# } else {
+# $lessthan = " AND $sortcontentfull > '$content' ";
+# }
+# } else { // Failed to find data (shouldn't happen), so fall back to something easy
+# $lessthan = " r.id < '$record->id' ";
+# }
+# } else {
+# $lessthan = " r.id < '$record->id' ";
+# }
+# $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
+# $page = count_records_sql($sqlindex);
+
+ $allrecords = get_records_sql($sqlselect); // Kludgey but accurate at least!
+ $page = 0;
+ foreach ($allrecords as $key => $allrecord) {
+ if ($key == $record->id) {
+ break;
}
- } else {
- $lessthan = " r.id < '$record->id' ";
+ $page++;
}
- $sqlindex = 'SELECT COUNT(DISTINCT c.recordid) '.$fromsql.$lessthan.$sortorder;
- $page = count_records_sql($sqlindex);
} else if ($mode == 'single') { // We rely on ambient $page settings
$nowperpage = 1;
print_paging_bar($totalcount, $page, $nowperpage, $baseurl, $pagevar='page');
}
- }
- data_print_preference_form($data, $perpage, $search, $sort, $order);
+ data_print_preference_form($data, $perpage, $search, $sort, $order);
+ }
print_footer($course);
?>