";
+
+/** Actions bar (= action of the wiki tool, not of the page)**/
+echo '';
+
+
+/*
+-----------------------------------------------------------
+MAIN WIKI AREA
+-----------------------------------------------------------
+*/
+
+echo "
";
+/** menuwiki (= actions of the page, not of the wiki tool) **/
+if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted')))
+{
+ echo "
';
+}
+
+/////////////////////// more options /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='more')
+{
+
+ echo '
'.get_lang('More').'
';
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ //TODO: config area and private stats
+
+ }
+
+ echo '
';
+ echo '';
+ echo '| ';
+ echo '';
+ echo ' | ';
+ echo '';
+ echo '';
+ echo' | ';
+ echo '
';
+ echo '
';
+
+
+ //Submenu Most linked pages
+ //echo '
'.get_lang('MostLinkedPages').'';//TODO
+
+ //Submenu Dead end pages
+ //echo '
'.get_lang('DeadEndPages').'';//TODO
+
+ //Submenu Most new pages (not versions)
+ //echo '
'.get_lang('MostNewPages').'';//TODO
+
+ //Submenu Most long pages
+ //echo '
'.get_lang('MostLongPages').'';//TODO
+
+ //Submenu Protected pages
+ //echo '
'.get_lang('ProtectedPages').'';//TODO
+
+ //Submenu Hidden pages
+ //echo '
'.get_lang('HiddenPages').'';//TODO
+
+ //Submenu Most discuss pages
+ //echo '
'.get_lang('MostDiscussPages').'';//TODO
+
+ //Submenu Best scored pages
+ //echo '
'.get_lang('BestScoredPages').'';//TODO
+
+ //Submenu Pages with more progress
+ //echo '
'.get_lang('MProgressPages').'';//TODO
+
+ //Submenu Most active users in discuss
+ //echo '
'.get_lang('MostDiscussUsers').'';//TODO
+
+ //Submenu Individual assignments
+ //echo '
'.get_lang('Assignments').'';//TODO
+
+ //Submenu Delayed assignments
+ //echo '
'.get_lang('DelayedAssignments').'';//TODO
+
+ //Submenu Random page
+ //echo '
'.get_lang('RandomPage').'';//TODO
+
+}
+
+/////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='mactiveusers')
+{
+ echo '
'.get_lang('MostActiveUsers').'
';
+
+ $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY user_id';
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ $userinfo=Database::get_user_info_from_id($obj->user_id);
+ $row = array ();
+
+ $row[] = $obj->user_id <>0 ? '
'.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')';
+ $row[] ='
'.$obj->NUM_EDIT.'';
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
+ $table->set_header(0,get_lang('Author'), true, array ('style' => 'width:30px;'));
+ $table->set_header(1,get_lang('Contributions'), true);
+ $table->display();
+ }
+}
+
+
+/////////////////////// User contributions /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='usercontrib')
+{
+ $userinfo=Database::get_user_info_from_id(Security::remove_XSS($_GET['user_id']));
+
+ echo '
';
+
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'"';
+ }
+ else
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'" AND visibility=1';
+ }
+
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get author
+ $userinfo=Database::get_user_info_from_id($obj->user_id);
+
+ //get time
+ $year = substr($obj->dtime, 0, 4);
+ $month = substr($obj->dtime, 5, 2);
+ $day = substr($obj->dtime, 8, 2);
+ $hours = substr($obj->dtime, 11,2);
+ $minutes = substr($obj->dtime, 14,2);
+ $seconds = substr($obj->dtime, 17,2);
+
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
+ $row[] =$ShowAssignment;
+
+ $row[] = '
'.$obj->title.'';
+ $row[] =$obj->version;
+ $row[] =$obj->comment;
+ //$row[] = api_strlen($obj->comment)>30 ? api_substr($obj->comment,0,30).'...' : $obj->comment;
+ $row[] =$obj->progress.' %';
+ $row[] =$obj->score;
+ //if(api_is_allowed_to_edit() || api_is_platform_admin())
+ //{
+ //$row[] =$obj->user_ip;
+ //}
+
+ $rows[] = $row;
+
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'user_id'=>Security::remove_XSS($_GET['user_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
+
+ $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
+ $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
+ $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;'));
+ $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;'));
+ $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;'));
+ $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;'));
+ $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;'));
+ //if(api_is_allowed_to_edit() || api_is_platform_admin())
+ //{
+ //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;'));
+ //}
+
+ $table->display();
+ }
+}
+
+/////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='mostchanged')
+{
+ echo '
'.get_lang('MostChangedPages').'
';
+
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink';
+ }
+ else
+ {
+ $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink';
+ }
+
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] =$ShowAssignment;
+ $row[] = '
'.$obj->title.'';
+ $row[] = $obj->MAX;
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_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('Changes'), true);
+ $table->display();
+ }
+
+}
+
+/////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='mvisited')
+{
+ echo '
'.get_lang('MostVisitedPages').'
';
+
+ 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';
+ }
+ else
+ {
+ $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink';
+ }
+
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] =$ShowAssignment;
+ $row[] = '
'.$obj->title.'';
+ $row[] = $obj->tsum;
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_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('Visits'), true);
+ $table->display();
+ }
+}
+
+/////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='wanted')
+{
+ echo '
'.get_lang('WantedPages').'
';
+
+ $pages = array();
+ $refs = array();
+ $sort_wanted=array();
+
+ //get name pages
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC';
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ while ($row=Database::fetch_array($allpages))
+ {
+ $pages[] = $row['reflink'];
+ }
+
+ //get name refs in last pages and make a unique list
+ $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')';
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+ while ($row=Database::fetch_array($allpages))
+ {
+ //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check
+ $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " "
+ $refs = array_merge($refs, $rf);
+ if ($n++ > 299)
+ {
+ $refs = array_unique($refs);
+ $n=0;
+ } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
+ }
+
+ //sort linksto. Find linksto into reflink. If not found ->page is wanted
+ natcasesort($refs);
+ echo '
';
+ foreach($refs as $v)
+ {
+ if(!in_array($v, $pages))
+ {
+ if (trim($v)!="")
+ {
+ echo '- '.str_replace('_',' ',$v).'
';
+ }
+ }
+ }
+ echo '
';
+}
+
+/////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='orphaned')
+{
+ echo '
'.get_lang('OrphanedPages').'
';
+
+ $pages = array();
+ $refs = array();
+ $orphaned = array();
+
+ //get name pages
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC';
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+ while ($row=Database::fetch_array($allpages))
+ {
+ $pages[] = $row['reflink'];
+ }
+
+ //get name refs in last pages and make a unique list
+ $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')';
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+ while ($row=Database::fetch_array($allpages))
+ {
+ //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check
+ $rf = explode(" ", trim($row["linksto"])); //fix replace explode("\n", trim($row["linksto"])) with explode(" ", trim($row["linksto"]))
+
+ $refs = array_merge($refs, $rf);
+ if ($n++ > 299)
+ {
+ $refs = array_unique($refs);
+ $n=0;
+ } // (clean-up only every 300th loop). Thanks to Erfurt Wiki
+ }
+
+ //search each name of list linksto into list reflink
+ foreach($pages as $v)
+ {
+ if(!in_array($v, $refs))
+ {
+ $orphaned[] = $v;
+ }
+ }
+
+ //change reflink by title
+ foreach($orphaned as $vshow)
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" GROUP BY reflink';
+ }
+ else
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" AND visibility=1 GROUP BY reflink';
+ }
+
+ $allpages=api_sql_query($sql,__FILE__,__LINE__);
+
+ echo '
';
+ while ($row=Database::fetch_array($allpages))
+ {
+ //fix assignment icon
+ if($row['assignment']==1)
+ {
+ $ShowAssignment='
';
+ }
+ elseif ($row['assignment']==2)
+ {
+ $ShowAssignment='
';
+ }
+ elseif ($row['assignment']==0)
+ {
+ $ShowAssignment='
';
+ }
+
+ echo '- '.$ShowAssignment.''.$row['title'].'
';
+ }
+ echo '
';
+ }
+
+}
+
+/////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='delete')
+{
+
+ if(!$_GET['title'])
+ {
+ Display::display_error_message(get_lang('MustSelectPage'));
+ exit;
+ }
+
+ echo '
';
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ echo '
'.get_lang('DeletePageHistory').'
';
+
+ if($page=="index")
+ {
+ Display::display_warning_message(get_lang('WarningDeleteMainPage'),false);
+ }
+
+ $message = get_lang('ConfirmDeletePage').""."
"."".get_lang("No").""." | "."".get_lang("Yes").""."
";
+
+ if (!isset ($_GET['delete']))
+ {
+ Display::display_warning_message($message,false);
+ }
+
+ if ($_GET['delete'] == 'yes')
+ {
+ $sql='DELETE '.$tbl_wiki_discuss.' FROM '.$tbl_wiki.', '.$tbl_wiki_discuss.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_discuss.'.publication_id='.$tbl_wiki.'.id';
+ api_sql_query($sql,__FILE__,__LINE__);
+
+ $sql='DELETE '.$tbl_wiki_mailcue.' FROM '.$tbl_wiki.', '.$tbl_wiki_mailcue.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_mailcue.'.id='.$tbl_wiki.'.id';
+ api_sql_query($sql,__FILE__,__LINE__);
+
+ $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.'';
+ api_sql_query($sql,__FILE__,__LINE__);
+
+ check_emailcue(0, 'E');
+
+ Display::display_confirmation_message(get_lang('WikiPageDeleted'));
+ }
+ }
+ else
+ {
+ Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki"));
+ }
+
+ echo '
';
+}
+
+
+/////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='deletewiki')
+{
+
+ echo '
'.get_lang('DeleteWiki').'
';
+ echo '
';
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $message = get_lang('ConfirmDeleteWiki');
+ $message .= '
+ '.get_lang('No').'
+ |
+ '.get_lang('Yes').'
+
';
+
+ if (!isset($_GET['delete']))
+ {
+ Display::display_warning_message($message,false);
+ }
+ }
+ else
+ {
+ Display::display_normal_message(get_lang("OnlyAdminDeleteWiki"));
+ }
+ echo '
';
+}
+
+/////////////////////// search wiki pages ///////////////////////
+if ($_GET['action']=='searchpages')
+{
+ echo '
'.get_lang('SearchPages').'
';
+ echo '
';
+ // initiate the object
+ $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action='.Security::remove_XSS($_GET['action']).'&group_id='.Security::remove_XSS($_GET['group_id']));
+
+ // settting the form elements
+
+ $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles"');
+ $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent'));
+ $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"');
+
+ // setting the rules
+ $form->addRule('search_term', '
'.get_lang('ThisFieldIsRequired'), 'required');
+ $form->addRule('search_term', get_lang('TooShort'),'minlength',3);
+
+ if ($form->validate())
+ {
+ $form->display();
+ $values = $form->exportValues();
+ display_wiki_search_results($values['search_term'], $values['search_content']);
+ }
+ else
+ {
+ $form->display();
+ }
+ echo '
';
+}
+
+
+/////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado
+
+if ($_GET['action']=='links')
+{
+
+ if (!$_GET['title'])
+ {
+ Display::display_error_message(get_lang("MustSelectPage"));
+ }
+ else
+ {
+
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.'';
+ $result=api_sql_query($sql,__FILE__,__LINE__);
+ $row=Database::fetch_array($result);
+
+ //get type assignment icon
+
+ if($row['assignment']==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($row['assignment']==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($row['assignment']==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ //fix Title to reflink (link Main Page)
+
+ if ($page==get_lang('DefaultTitle'))
+ {
+ $page='index';
+ }
+
+ echo '
';
+
+ //fix index to title Main page into linksto
+ if ($page=='index')
+ {
+ $page=str_replace(' ','_',get_lang('DefaultTitle'));
+ }
+
+ //table
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word.
+ }
+ else
+ {
+ $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE visibility=1 AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word
+ }
+
+ $allpages=api_sql_query($sql,__LINE__,__FILE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get author
+ $userinfo=Database::get_user_info_from_id($obj->user_id);
+
+ //get time
+ $year = substr($obj->dtime, 0, 4);
+ $month = substr($obj->dtime, 5, 2);
+ $day = substr($obj->dtime, 8, 2);
+ $hours = substr($obj->dtime, 11,2);
+ $minutes = substr($obj->dtime, 14,2);
+ $seconds = substr($obj->dtime, 17,2);
+
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] =$ShowAssignment;
+ $row[] = '
'.Security::remove_XSS($obj->title).'';
+ $row[] = $obj->user_id <>0 ? '
'.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')';
+ $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_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();
+ }
+ }
+}
+
+
+/////////////////////// adding a new page ///////////////////////
+
+
+// Display the form for adding a new wiki page
+if ($_GET['action']=='addnew')
+{
+
+ echo '
'.get_lang('AddNew').'
';
+
+ //first, check if page index was created. chektitle=false
+ if (checktitle('index'))
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
+ {
+ Display::display_normal_message(get_lang('GoAndEditMainPage'));
+ }
+ else
+ {
+ return Display::display_normal_message(get_lang('WikiStandBy'));
+ }
+ }
+
+ elseif (check_addnewpagelock() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false))
+ {
+ Display::display_error_message(get_lang('AddPagesLocked'));
+ }
+ else
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0)
+ {
+ display_new_wiki_form();
+ }
+ else
+ {
+ Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers'));
+ }
+ }
+
+}
+
+
+
+/////////////////////// show home page ///////////////////////
+
+if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew']))
+{
+ display_wiki_entry();
+}
+
+/////////////////////// show current page ///////////////////////
+
+if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew']))
+{
+ if($_GET['title'])
+ {
+ display_wiki_entry();
+ }
+ else
+ {
+ Display::display_error_message(get_lang('MustSelectPage'));
+ }
+}
+
+
+/////////////////////// edit current page ///////////////////////
+
+if ($_GET['action']=='edit')
+{
+ $_clean['group_id']=(int)$_SESSION['_gid'];
+
+ $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
+ $result=api_sql_query($sql,__LINE__,__FILE__);
+ $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
+
+
+
+ if ($row['content']=='' AND $row['title']=='' AND $page=='')
+ {
+ Display::display_error_message(get_lang('MustSelectPage'));
+ exit;
+ }
+ elseif ($row['content']=='' AND $row['title']=='' AND $page=='index')
+ {
+ $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH));
+ $title=get_lang('DefaultTitle');
+ $page_id=0;
+ }
+ else
+ {
+ $content=$row['content'];
+ $title=$row['title'];
+ $page_id=$row['page_id'];
+ }
+
+ //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher. And users in groups
+ if(($row['reflink']=='index' || $row['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit() && $_clean['group_id']==0))
+ {
+ Display::display_error_message(get_lang('OnlyEditPagesCourseManager'));
+ }
+ else
+ {
+ $PassEdit=false;
+
+ //check if is a wiki group
+ if($_clean['group_id']!=0)
+ {
+ //Only teacher, platform admin and group members can edit a wiki group
+ if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']))
+ {
+ $PassEdit=true;
+ }
+ else
+ {
+ Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
+ }
+ }
+ else
+ {
+ $PassEdit=true;
+ }
+
+ // check if is a assignment
+ if(stripslashes($row['assignment'])==1)
+ {
+ Display::display_normal_message(get_lang('EditAssignmentWarning'));
+ $icon_assignment='

';
+ }
+ elseif(stripslashes($row['assignment'])==2)
+ {
+ $icon_assignment='

';
+ if((api_get_user_id()==$row['user_id'])==false)
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $PassEdit=true;
+ }
+ else
+ {
+ Display::display_warning_message(get_lang('LockByTeacher'));
+ $PassEdit=false;
+ }
+ }
+ else
+ {
+ $PassEdit=true;
+ }
+ }
+
+ if($PassEdit) //show editor if edit is allowed
+ {
+ if (check_protect_page() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false))
+ {
+ Display::display_normal_message(get_lang('PageLockedExtra'));
+ }
+ else
+ {
+
+ //previous checking for concurrent editions
+ if($row['is_editing']==0)
+ {
+ Display::display_normal_message(get_lang('WarningMaxEditingTime'));
+
+ $time_edit = date("Y-m-d H:i:s");
+ $sql='UPDATE '.$tbl_wiki.' SET is_editing="'.$_user['user_id'].'", time_edit="'.$time_edit.'" WHERE id="'.$row['id'].'"';
+ api_sql_query($sql,__FILE__,__LINE__);
+ }
+ elseif($row['is_editing']!=$_user['user_id'])
+ {
+ $timestamp_edit=convert_date_to_number($row['time_edit']);
+ $time_editing=time()-$timestamp_edit;
+ $max_edit_time=1200; // 20 minutes
+ $rest_time=$max_edit_time-$time_editing;
+
+ $userinfo=Database::get_user_info_from_id($row['is_editing']);
+
+ $is_being_edited= get_lang('ThisPageisBeginEditedBy').'
'.$userinfo['lastname'].', '.$userinfo['firstname'].'. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
+ Display::display_normal_message($is_being_edited);
+ exit;
+ }
+
+ echo '
';
+ echo $icon_assignment.' '.$title.'
';
+ echo '
';
+ echo '';
+ echo '
';
+ }
+ }
+ }
+}
+
+/////////////////////// page history ///////////////////////
+
+
+if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences']))
+{
+ if (!$_GET['title'])
+ {
+ Display::display_error_message(get_lang("MustSelectPage"));
+ exit;
+ }
+
+ echo '
';
+ $_clean['group_id']=(int)$_SESSION['_gid'];
+
+ //First, see the property visibility that is at the last register and therefore we should select descending order. But to give ownership to each record, this is no longer necessary except for the title. TODO: check this
+
+ $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
+ $result=api_sql_query($sql,__LINE__,__FILE__);
+
+ while ($row=Database::fetch_array($result))
+ {
+ $KeyVisibility=$row['visibility'];
+ $KeyAssignment=$row['assignment'];
+ $KeyTitle=$row['title'];
+ $KeyUserId=$row['user_id'];
+ }
+
+ if($KeyAssignment==1)
+ {
+ $icon_assignment='

';
+ }
+ elseif($KeyAssignment==2)
+ {
+ $icon_assignment='

';
+ }
+
+
+ //Second, show
+
+ //if the page is hidden and is a job only sees its author and professor
+ if($KeyVisibility==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($KeyAssignment==2 && $KeyVisibility==0 && (api_get_user_id()==$KeyUserId)))
+ {
+ // We show the complete history
+ if (!$_POST['HistoryDifferences'] && !$_POST['HistoryDifferences2'] )
+ {
+
+ $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
+ $result=api_sql_query($sql,__LINE__,__FILE__);
+
+ $title = Security::remove_XSS($_GET['title']);
+ $group_id = Security::remove_XSS($_GET['group_id']);
+
+ echo '
';
+ echo $icon_assignment.' '.$KeyTitle;
+ echo '
';
+ echo '
';
+ }
+ // We show the differences between two versions
+ else
+ {
+ $sql_old="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['old'])."'";
+ $result_old=api_sql_query($sql_old,__LINE__,__FILE__);
+ $version_old=Database::fetch_array($result_old);
+
+
+ $sql_new="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['new'])."'";
+ $result_new=api_sql_query($sql_new,__LINE__,__FILE__);
+ $version_new=Database::fetch_array($result_new);
+
+ if(isset($_POST['HistoryDifferences']))
+ {
+ include('diff.inc.php');
+ //title
+ echo '
'.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedLine).' '.get_lang(WikiDiffDeletedLine).' '.get_lang(WikiDiffMovedLine).'
';
+ }
+ if(isset($_POST['HistoryDifferences2']))
+ {
+ require_once 'Text/Diff.php';
+ require_once 'Text/Diff/Renderer/inline.php';
+ //title
+ echo '
'.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedTex).' '.get_lang(WikiDiffDeletedTex).'
';
+ }
+
+ echo '
';
+
+ if(isset($_POST['HistoryDifferences']))
+ {
+ echo '
'.diff( stripslashes($version_old['content']), stripslashes($version_new['content']), true, 'format_table_line' ).'
'; // format_line mode is better for words
+ echo '
';
+
+ echo '
';
+ echo '
'.get_lang('Legend').'' . "\n";
+ echo '
';
+ echo '| ';
+ echo ' | ';
+ echo ''.get_lang('WikiDiffUnchangedLine').' ';
+ echo ''.get_lang('WikiDiffAddedLine').' ';
+ echo ''.get_lang('WikiDiffDeletedLine').' ';
+ echo ''.get_lang('WikiDiffMovedLine').' ';
+ echo ' | ';
+ echo '
';
+
+ echo '
';
+
+ }
+
+ if(isset($_POST['HistoryDifferences2']))
+ {
+
+ $lines1 = array(strip_tags($version_old['content'])); //without <> tags
+ $lines2 = array(strip_tags($version_new['content'])); //without <> tags
+
+ $diff = &new Text_Diff($lines1, $lines2);
+
+ $renderer = &new Text_Diff_Renderer_inline();
+ echo ''.$renderer->render($diff); // Code inline
+ //echo '
'.html_entity_decode($renderer->render($diff)).'
'; // Html inline. By now, turned off by problems in comparing pages separated by more than one version
+ echo '
';
+
+ echo '
';
+ echo '
'.get_lang('Legend').'' . "\n";
+ echo '
';
+ echo '| ';
+ echo ' | ';
+ echo ''.get_lang('WikiDiffAddedTex').' ';
+ echo ''.get_lang('WikiDiffDeletedTex').' ';
+ echo ' | ';
+ echo '
';
+
+ echo '
';
+
+ }
+ }
+ }
+ echo '
';
+}
+
+
+/////////////////////// recent changes ///////////////////////
+
+//
+//rss feed. TODO
+//
+
+if ($_GET['action']=='recentchanges')
+{
+ $_clean['group_id']=(int)$_SESSION['_gid'];
+
+ if (check_notify_all())
+ {
+ $notify_all= '
'.get_lang('NotNotifyChanges').'';
+ }
+ else
+ {
+ $notify_all= '
'.get_lang('NotifyChanges').'';
+ }
+
+ echo '
'.$notify_all.''.get_lang('RecentChanges').'
';
+
+
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY dtime DESC';
+ }
+ else
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 ORDER BY dtime DESC';
+ }
+
+ $allpages=api_sql_query($sql,__LINE__,__FILE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get author
+ $userinfo=Database::get_user_info_from_id($obj->user_id);
+
+ //get time
+ $year = substr($obj->dtime, 0, 4);
+ $month = substr($obj->dtime, 5, 2);
+ $day = substr($obj->dtime, 8, 2);
+ $hours = substr($obj->dtime, 11,2);
+ $minutes = substr($obj->dtime, 14,2);
+ $seconds = substr($obj->dtime, 17,2);
+
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.":".$seconds;
+ $row[] = $ShowAssignment;
+ $row[] = '
'.$obj->title.'';
+ $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
+ $row[] = $obj->user_id <>0 ? '
'.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')';
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
+ $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
+ $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
+ $table->set_header(2,get_lang('Title'), true);
+ $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;'));
+ $table->set_header(4,get_lang('Author'), true);
+
+ $table->display();
+ }
+}
+
+
+/////////////////////// all pages ///////////////////////
+
+
+if ($_GET['action']=='allpages')
+{
+ echo '
'.get_lang('AllPages').'
';
+
+ $_clean['group_id']=(int)$_SESSION['_gid'];
+
+
+ if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version
+ }
+ else
+ {
+ $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version
+ }
+
+ $allpages=api_sql_query($sql,__LINE__,__FILE__);
+
+ //show table
+ if (mysql_num_rows($allpages) > 0)
+ {
+ $row = array ();
+ while ($obj = mysql_fetch_object($allpages))
+ {
+ //get author
+ $userinfo=Database::get_user_info_from_id($obj->user_id);
+
+ //get time
+ $year = substr($obj->dtime, 0, 4);
+ $month = substr($obj->dtime, 5, 2);
+ $day = substr($obj->dtime, 8, 2);
+ $hours = substr($obj->dtime, 11,2);
+ $minutes = substr($obj->dtime, 14,2);
+ $seconds = substr($obj->dtime, 17,2);
+
+ //get type assignment icon
+ if($obj->assignment==1)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==2)
+ {
+ $ShowAssignment='

';
+ }
+ elseif ($obj->assignment==0)
+ {
+ $ShowAssignment='

';
+ }
+
+ $row = array ();
+ $row[] =$ShowAssignment;
+ $row[] = '
'.Security::remove_XSS($obj->title).'';
+ $row[] = $obj->user_id <>0 ? '
'.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')';
+ $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
+
+ if(api_is_allowed_to_edit()|| api_is_platform_admin())
+ {
+ $showdelete='
';
+ }
+
+ $row[] = '

'.$showdelete;
+ $rows[] = $row;
+ }
+
+ $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
+ $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_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').' ('.get_lang('LastVersion').')', true);
+ $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
+ $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:100px;'));
+ $table->display();
+ }
+}
+
+/////////////////////// discuss pages ///////////////////////
+
+
+if ($_GET['action']=='discuss')
+{
+ if (!$_GET['title'])
+ {
+ Display::display_error_message(get_lang("MustSelectPage"));
+ exit;
+ }
+
+ //first extract the date of last version
+ $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC';
+ $result=api_sql_query($sql,__LINE__,__FILE__);
+ $row=Database::fetch_array($result);
+ $lastversiondate=$row['dtime'];
+ $lastuserinfo=Database::get_user_info_from_id($row['user_id']);
+
+ //select page to discuss
+ $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC';
+ $result=api_sql_query($sql,__LINE__,__FILE__);
+ $row=Database::fetch_array($result);
+ $id=$row['id'];
+ $firstuserid=$row['user_id'];
+
+ //mode assignment: previous to show page type
+ if(stripslashes($row['assignment'])==1)
+ {
+ $icon_assignment='

';
+ }
+ elseif(stripslashes($row['assignment'])==2)
+ {
+ $icon_assignment='

';
+ }
+
+
+ //Show title and form to discuss if page exist
+ if ($id!='')
+ {
+ //Show discussion 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($row['visibility_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id'])))
+ {
+ echo '
';
+
+ // discussion action: protecting (locking) the discussion
+ if (check_addlock_discuss())
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $addlock_disc= '

';
+ }
+ else
+ {
+ $addlock_disc= '

';
+ }
+
+ }
+ else
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $addlock_disc= '

';
+ }
+ }
+ echo '
';
+ echo ''.$addlock_disc.'';
+ echo '';
+
+
+ // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
+ if (check_visibility_discuss())
+ {
+ //Mode assignments: If is hidden, show pages to student only if student is the author
+ if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
+ {
+ $visibility_disc= '

';
+ }
+ }
+ else
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $visibility_disc= '

';
+ }
+ }
+ echo '
';
+ echo ''.$visibility_disc.'';
+ echo '';
+
+
+ //discussion action: check add rating lock. Show/Hide list to rating for all student
+ if (check_ratinglock_discuss())
+ {
+ //Mode assignment: only the teacher can assign scoring
+ if(($row['assignment']==2 && $row['ratinglock_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
+ {
+ $ratinglock_disc= '

';
+ }
+ }
+ else
+ {
+ if(api_is_allowed_to_edit() || api_is_platform_admin())
+ {
+ $ratinglock_disc= '

';
+ }
+ }
+ echo '
';
+ echo ''.$ratinglock_disc.'';
+ echo '';
+
+ //discussion action: email notification
+ if (check_notify_discuss($page))
+ {
+ $notify_disc= '

';
+ }
+ else
+ {
+ $notify_disc= '

';
+ }
+ echo '
';
+ echo ''.$notify_disc.'';
+ echo '';
+
+ echo $icon_assignment.' '.$row['title'];
+
+ echo ' ('.get_lang('MostRecentVersionBy').'
'.$lastuserinfo['firstname'].' '.$lastuserinfo['lastname'].' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read avg score
+
+ echo '
';
+
+ if($row['addlock_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin()) //show comments but students can't add theirs
+ {
+ ?>
+
+
+ ';
+ $user_table = Database :: get_main_table(TABLE_MAIN_USER);
+
+ $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' ORDER BY id DESC";
+ $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
+
+ $countWPost = Database::num_rows($result);
+ echo get_lang('NumComments').": ".$countWPost; //comment's numbers
+
+ $sql="SELECT SUM(p_score) as sumWPost FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-' ORDER BY id DESC";
+ $result2=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
+ $row2=Database::fetch_array($result2);
+
+ $sql="SELECT * FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-'";
+ $result3=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error());
+ $countWPost_score= Database::num_rows($result3);
+
+ echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;//
+
+ if ($countWPost_score!=0)
+ {
+ $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10';
+ }
+ else
+ {
+ $avg_WPost_score = $countWPost_score;
+ }
+
+ echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
+
+ $sql='UPDATE '.$tbl_wiki.' SET score="'.Database::escape_string($avg_WPost_score).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; // check if work ok. TODO
+ api_sql_query($sql,__FILE__,__LINE__);
+
+ echo '
';
+ //echo '
';
+
+ while ($row=Database::fetch_array($result))
+ {
+ $userinfo=Database::get_user_info_from_id($row['userc_id']);
+ if (($userinfo['status'])=="5")
+ {
+ $author_status=get_lang('Student');
+ }
+ else
+ {
+ $author_status=get_lang('Teacher');
+ }
+
+ require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php');
+ $user_id=$row['userc_id'];
+ $name=$userinfo['lastname']." ".$userinfo['firstname'];
+ $attrb=array();
+ if ($user_id<>0)
+ {
+ $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
+ $image_repository = $image_path['dir'];
+ $existing_image = $image_path['file'];
+ $author_photo= '

';
+
+ }
+ else
+ {
+ $author_photo= '
.)
';
+ }
+
+ //stars
+ $p_score=$row['p_score'];
+ switch($p_score){
+ case 0:
+ $imagerating='

';
+ break;
+ case 1:
+ $imagerating='

';
+ break;
+ case 2:
+ $imagerating='

';
+ break;
+ case 3:
+ $imagerating='

';
+ break;
+ case 4:
+ $imagerating='

';
+ break;
+ case 5:
+ $imagerating='

';
+ break;
+ case 6:
+ $imagerating='

';
+ break;
+ case 7:
+ $imagerating='

';
+ break;
+ case 8:
+ $imagerating='

';
+ break;
+ case 9:
+ $imagerating='

';
+ break;
+ case 10:
+ $imagerating='

';
+ break;
+ }
+
+ echo '
';
+ echo '';
+ echo '| '.$author_photo.' | ';
+ echo ''.$userinfo['lastname'].', '.$userinfo['firstname'].' ('.$author_status.') '.$row['dtime'].' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' | ';
+ echo '
';
+ echo '';
+ echo '| '.$row['comment'].' | ';
+ echo '
';
+ echo "
";
+ echo '
';
+
+ }
+ // echo"
";
+ }
+ else
+ {
+
+ Display::display_warning_message(get_lang('LockByTeacher'),false);
+
+ }
+ }
+ else
+ {
+
+ Display::display_normal_message(get_lang('DiscussNotAvailable'));
+
+ }
+}
+
+echo "