[svn r16482] fix tables into most visited pages

add tables to all pages and search
skala
Juan Carlos Raña 17 years ago
parent 594c5caa88
commit ddf5e51eb8
  1. 230
      main/wiki/index.php

@ -545,11 +545,11 @@ if ($_GET['action']=='mvisited')
if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
{ {
$sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY tsum DESC, reflink'; $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink'; // warning GROUP BY reflink don't return the last version, always the first id
} }
else else
{ {
$sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink ORDER BY tsum DESC, reflink'; $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink'; // warning GROUP BY reflink don't return the last version, always the first id
} }
$allpages=api_sql_query($sql,__FILE__,__LINE__); $allpages=api_sql_query($sql,__FILE__,__LINE__);
@ -560,17 +560,6 @@ if ($_GET['action']=='mvisited')
$row = array (); $row = array ();
while ($obj = mysql_fetch_object($allpages)) while ($obj = mysql_fetch_object($allpages))
{ {
//get author
$userinfo=Database::get_user_info_from_id($obj->user_id);
//get time
$year = substr($obj->timestamp, 0, 4);
$month = substr($obj->timestamp, 5, 2);
$day = substr($obj->timestamp, 8, 2);
$hours = substr($obj->timestamp, 11,2);
$minutes = substr($obj->timestamp, 14,2);
$seconds = substr($obj->timestamp, 17,2);
//get type assignment icon //get type assignment icon
if($obj->assignment==1) if($obj->assignment==1)
{ {
@ -588,19 +577,15 @@ if ($_GET['action']=='mvisited')
$row = array (); $row = array ();
$row[] =$ShowAssignment; $row[] =$ShowAssignment;
$row[] = '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>'; $row[] = '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
$row[] ='<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>';
$row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
$row[] = $obj->tsum; $row[] = $obj->tsum;
$rows[] = $row; $rows[] = $row;
} }
$table = new SortableTableFromArrayConfig($rows,4,10,'MostVisitedPages_table','','','DESC'); $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC');
$table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id']))); $table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id'])));
$table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
$table->set_header(1,get_lang('Title'), true); $table->set_header(1,get_lang('Title'), true);
$table->set_header(2,get_lang('Author'), true); $table->set_header(2,get_lang('Visits'), true);
$table->set_header(3,get_lang('Date'), true);
$table->set_header(4,get_lang('Visits'), true);
$table->display(); $table->display();
} }
} }
@ -620,6 +605,7 @@ if ($_GET['action']=='wanted')
//get name pages //get name pages
$sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC';
$allpages=api_sql_query($sql,__FILE__,__LINE__); $allpages=api_sql_query($sql,__FILE__,__LINE__);
while ($row=Database::fetch_array($allpages)) while ($row=Database::fetch_array($allpages))
{ {
$pages[] = $row['reflink']; $pages[] = $row['reflink'];
@ -798,6 +784,7 @@ if ($_GET['action']=='deletewiki')
/////////////////////// search pages /////////////////////// Juan Carlos Raña Trabado /////////////////////// search pages /////////////////////// Juan Carlos Raña Trabado
//// 1 Searchpages: input search
if ($_GET['action']=='searchpages') if ($_GET['action']=='searchpages')
{ {
@ -807,92 +794,98 @@ if ($_GET['action']=='searchpages')
if (!$_POST['Skeyword']) if (!$_POST['Skeyword'])
{ {
echo '<form id="fsearch" method="POST" action="index.php?action=searchpages">'; echo '<form id="fsearch" method="POST" action="index.php?action=showsearchpages">';
echo '<input type="text" name="Skeyword" >'; echo '<input type="text" name="Skeyword" >';
echo '<input type="submit" value="'.get_lang('Search').'"/></br></br>'; echo '<input type="submit" value="'.get_lang('Search').'"/></br></br>';
echo '<input type="checkbox" name="Scontent" value="1"> '.get_lang('AlsoSearchContent'); echo '<input type="checkbox" name="Scontent" value="1"> '.get_lang('AlsoSearchContent');
echo '</form>'; echo '</form>';
} }
else
{
if($_POST['Scontent']=="1")
{
$sql="SELECT * FROM ".$tbl_wiki." WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' OR content LIKE '%".$_POST['Skeyword']."%' GROUP BY reflink ORDER BY title ASC";
}
else
{
$sql="SELECT * FROM ".$tbl_wiki." WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' GROUP BY reflink ORDER BY title ASC";
} }
//show result //// 2 SearchPages: find and show pages
$_clean['group_id']=(int)$_SESSION['_gid'];
$result=api_sql_query($sql,__LINE__,__FILE__);
echo '<ul>';
while ($row=Database::fetch_array($result)) if ($_GET['action']=='showsearchpages')
{ {
$userinfo=Database::get_user_info_from_id($row['user_id']); echo '<br>';
echo '<b>'.$Search.'</b>: '.$_POST['Skeyword']; //TODO: post is lost when a table has some pages
echo '<hr>';
//Show page to students if not is hidden. Show page to all teachers if is hidden. Mode assignments: show pages to student only if student it the author $_clean['group_id']=(int)$_SESSION['_gid'];
if($row['visibility']==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility']==0 && (api_get_user_id()==$row['user_id'])))
{
$year = substr($row['timestamp'], 0, 4);
$month = substr($row['timestamp'], 5, 2);
$day = substr($row['timestamp'], 8, 2);
$hours=substr($row['timestamp'], 11,2);
$minutes=substr($row['timestamp'], 14,2);
$seconds=substr($row['timestamp'], 17,2);
//show teacher assignment if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
if($row['assignment']==1)
{ {
//teachers assigment pages only list for teachers if($_POST['Scontent']=="1")
if(api_is_allowed_to_edit() || api_is_platform_admin())
{ {
$ShowAssignment='<img src="../img/wiki/assignment.gif" />'; $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' OR content LIKE '%".$_POST['Skeyword']."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
echo '<li>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$row['reflink'].'&group_id='.$_clean['group_id'].'">'.$ShowAssignment.$row['title'].'</a>';
echo '...'.$userinfo['lastname'].', '.$userinfo['firstname'];
echo '...'.$day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds.'</li>';
} }
else
{
$sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
} }
//show student assignment }
if ($row['assignment']==2) else
{ {
//student assignment pages only list for each student author and for teachers if($_POST['Scontent']=="1")
if ($row['user_id']==(int)api_get_user_id() || api_is_allowed_to_edit() || api_is_platform_admin())
{ {
$ShowAssignment='<img src="../img/wiki/works.gif" />';
echo '<li>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$row['reflink'].'&group_id='.$_clean['group_id'].'">'.$ShowAssignment.$row['title'].'</a>';
echo '...'.$userinfo['lastname'].', '.$userinfo['firstname']; $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND visibility=1 AND title LIKE '%".$_POST['Skeyword']."%' OR content LIKE '%".$_POST['Skeyword']."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
echo '...'.$day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds.'</li>';
} }
else
{
$sql="SELECT * FROM ".$tbl_wiki." s1 WHERE ".$groupfilter." AND visibility=1 AND title LIKE '%".$_POST['Skeyword']."%' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink)";// warning don't use group by reflink because don't return the last version
} }
//show wiki pages standard }
if ($row['assignment']==0)
$result=api_sql_query($sql,__LINE__,__FILE__);
//show table
if (mysql_num_rows($result) > 0)
{ {
$ShowAssignment='<img src="../img/wiki/trans.gif" />'; $row = array ();
echo '<li>'; while ($obj = mysql_fetch_object($result))
echo '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$row['reflink'].'&group_id='.$_clean['group_id'].'">'.$ShowAssignment.$row['title'].'</a>'; {
//get author
$userinfo=Database::get_user_info_from_id($obj->user_id);
if ($row['user_id']<>0) //get time
$year = substr($obj->timestamp, 0, 4);
$month = substr($obj->timestamp, 5, 2);
$day = substr($obj->timestamp, 8, 2);
$hours = substr($obj->timestamp, 11,2);
$minutes = substr($obj->timestamp, 14,2);
$seconds = substr($obj->timestamp, 17,2);
//get type assignment icon
if($obj->assignment==1)
{ {
echo '...'.$userinfo['lastname'].', '.$userinfo['firstname']; $ShowAssignment='<img src="../img/wiki/assignment.gif" alt="'.get_lang('AssignmentDesc').'" />';
} }
else elseif ($obj->assignment==2)
{ {
echo get_lang('Anonymous').' ('.$row[user_ip].')'; $ShowAssignment='<img src="../img/wiki/works.gif" alt="'.get_lang('AssignmentWork').'" />';
}
echo '...'.$day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds.'</li>';
} }
elseif ($obj->assignment==0)
{
$ShowAssignment='<img src="../img/wiki/trans.gif" />';
} }
$row = array ();
$row[] =$ShowAssignment;
$row[] = '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
$row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
$row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
$rows[] = $row;
} }
echo '</ul>';
$table = new SortableTableFromArrayConfig($rows,1,10,'SearchPages_table','','','ASC');
$table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id'])));
$table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
$table->set_header(1,get_lang('Title'), true);
$table->set_header(2,get_lang('Author'), true);
$table->set_header(3,get_lang('Date'), true);
$table->display();
} }
} }
@ -1494,65 +1487,74 @@ if ($_GET['action']=='recentchanges')
if ($_GET['action']=='allpages') if ($_GET['action']=='allpages')
{ {
$_clean['group_id']=(int)$_SESSION['_gid'];
$sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY title ASC'; //tasks grouped by reflink instead of tilte, because there may be pages with the same name but with different reflink. This is true of the tasks
$result=api_sql_query($sql,__LINE__,__FILE__);
echo '<br>'; echo '<br>';
echo '<b>'.get_lang('AllPages').'</b>'; echo '<b>'.get_lang('AllPages').'</b>';
echo '<hr>'; echo '<hr>';
echo '<ul>'; $_clean['group_id']=(int)$_SESSION['_gid'];
while ($row=Database::fetch_array($result))
{
$userinfo=Database::get_user_info_from_id($row['user_id']);
$year = substr($row['timestamp'], 0, 4);
$month = substr($row['timestamp'], 5, 2);
$day = substr($row['timestamp'], 8, 2);
$hours=substr($row['timestamp'], 11,2);
$minutes=substr($row['timestamp'], 14,2);
$seconds=substr($row['timestamp'], 17,2);
$url_enc=urlencode($row['reflink']);
//Show page to students if isn't hidden. Show page to all teachers if is hidden. Mode assignments: If is hidden, show pages to student only if student is the author if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
if($row['visibility']==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility']==0 && (api_get_user_id()==$row['user_id'])))
{
if($row['assignment']==1)
{
if(api_is_allowed_to_edit() || api_is_platform_admin()) //Mode assignments: show pages assignment (task) only for teachers
{ {
$ShowAssignment='<img src="../img/wiki/assignment.gif" />'; $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; // warning don't use group by reflink because don't return the last version
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$url_enc.'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$ShowAssignment.$row['title'].'</a> ('.get_lang('AssignmentDesc').' '.$userinfo['firstname'].' '.$userinfo['lastname'].' )</li>';
} }
else
{
$sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE '.$groupfilter.' AND visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink)'; // warning don't use group by reflink because don't return the last version
} }
if ($row['assignment']==2) $allpages=api_sql_query($sql,__LINE__,__FILE__);
//show table
if (mysql_num_rows($allpages) > 0)
{ {
//Mode assignments: show pages assignment (works) only for teachers. Also show pages to student only if student is the author. $row = array ();
if ($row['user_id']==(int)api_get_user_id() || api_is_allowed_to_edit() || api_is_platform_admin()) while ($obj = mysql_fetch_object($allpages))
{ {
$ShowAssignment='<img src="../img/wiki/works.gif" />'; //get author
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$url_enc.'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$ShowAssignment.$row['title'].'</a> ('.get_lang('AssignmentWork').' '.$userinfo['firstname'].' '.$userinfo['lastname'].' )</li>'; $userinfo=Database::get_user_info_from_id($obj->user_id);
//get time
$year = substr($obj->timestamp, 0, 4);
$month = substr($obj->timestamp, 5, 2);
$day = substr($obj->timestamp, 8, 2);
$hours = substr($obj->timestamp, 11,2);
$minutes = substr($obj->timestamp, 14,2);
$seconds = substr($obj->timestamp, 17,2);
//get type assignment icon
if($obj->assignment==1)
{
$ShowAssignment='<img src="../img/wiki/assignment.gif" alt="'.get_lang('AssignmentDesc').'" />';
} }
elseif ($obj->assignment==2)
{
$ShowAssignment='<img src="../img/wiki/works.gif" alt="'.get_lang('AssignmentWork').'" />';
} }
if ($row['assignment']==0) elseif ($obj->assignment==0)
{ {
$ShowAssignment='<img src="../img/wiki/trans.gif" />'; $ShowAssignment='<img src="../img/wiki/trans.gif" />';
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.$url_enc.'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$ShowAssignment.$row['title'].'</a></li>';
} }
$row = array ();
$row[] =$ShowAssignment;
$row[] = '<a href="'.$_SERVER['PHP_SELF'].'?cidReq='.$_course[id].'&action=showpage&title='.urlencode($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.$obj->title.'</a>';
$row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.$userinfo['lastname'].', '.$userinfo['firstname'].'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
$row[] = $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds;
$rows[] = $row;
} }
$table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
$table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id'])));
$table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
$table->set_header(1,get_lang('Title'), true);
$table->set_header(2,get_lang('Author'), true);
$table->set_header(3,get_lang('Date'), true);
$table->display();
} }
echo '</ul>';
} }
/////////////////////// discuss pages /////////////////////// /////////////////////// discuss pages ///////////////////////

Loading…
Cancel
Save