, Ghent University, Belgium * @author Juan Carlos Raña * * @package chamilo.wiki */ /** * Code */ // name of the language file that needs to be included $language_file = 'wiki'; // including the global initialization file require_once '../inc/global.inc.php'; // section (for the tabs) $this_section = SECTION_COURSES; // including additional library scripts require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once 'wiki.inc.php'; $course_id = api_get_course_int_id(); // additional style information $htmlHeadXtra[] =''; // javascript for advanced parameters menu $htmlHeadXtra[] = ''; // Database table definition $tbl_wiki = Database::get_course_table(TABLE_WIKI); $tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS); $tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE); $tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF); /* Constants and variables */ $tool_name = get_lang('ToolWiki'); $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong")); //condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); /* ACCESS */ api_protect_course_script(); api_block_anonymous_users(); /* TRACKING */ event_access_tool(TOOL_WIKI); /* HEADER & TITLE */ // If it is a group wiki then the breadcrumbs will be different. //Setting variable $_clean['group_id'] = 0; if ($_SESSION['_gid'] OR $_GET['group_id']) { if (isset($_SESSION['_gid'])) { $_clean['group_id']=intval($_SESSION['_gid']); } if (isset($_GET['group_id'])) { $_clean['group_id']=intval($_GET['group_id']); } $group_properties = GroupManager :: get_group_properties($_clean['group_id']); $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups')); $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_clean['group_id'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']); $add_group_to_title = ' '.$group_properties['name']; $groupfilter='group_id="'.$_clean['group_id'].'"'; //ensure this tool in groups whe it's private or deactivated if ($group_properties['wiki_state']==0) { api_not_allowed(); } elseif ($group_properties['wiki_state']==2) { if (!api_is_allowed_to_edit(false,true) and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) { api_not_allowed(); } } } else { $groupfilter='group_id=0'; } if ($_POST['action']=='export_to_pdf' && isset($_POST['wiki_id']) && api_get_setting('students_export2pdf') == 'true') { export_to_pdf($_POST['wiki_id'], api_get_course_id()); exit; } Display::display_header($tool_name, 'Wiki'); $is_allowed_to_edit = api_is_allowed_to_edit(false,true); //api_display_tool_title($tool_name.$add_group_to_title); /* INITIALISATION */ //the page we are dealing with if (!isset($_GET['title'])) { $page = 'index'; } else { $page = $_GET['title']; } // some titles are not allowed // $not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now /* MAIN CODE */ // Tool introduction Display::display_introduction_section(TOOL_WIKI); /* ACTIONS */ //release of blocked pages to prevent concurrent editions $sql = "SELECT * FROM $tbl_wiki WHERE c_id = $course_id AND is_editing != '0' ".$condition_session; $result=Database::query($sql); while ($is_editing_block=Database::fetch_array($result)) { $max_edit_time = 1200; // 20 minutes $timestamp_edit = strtotime($is_editing_block['time_edit']); $time_editing = time()-$timestamp_edit; //first prevent concurrent users and double version if ($is_editing_block['is_editing']==$_user['user_id']) { $_SESSION['_version']=$is_editing_block['version']; } else { unset ( $_SESSION['_version'] ); } //second checks if has exceeded the time that a page may be available or if a page was edited and saved by its author if ($time_editing>$max_edit_time || ($is_editing_block['is_editing']==$_user['user_id'] && $_GET['action']!='edit')) { $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" WHERE c_id = '.$course_id.' AND is_editing="'.$is_editing_block['is_editing'].'" '.$condition_session; Database::query($sql); } } // saving a change if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') { if(empty($_POST['title'])) { Display::display_error_message(get_lang("NoWikiPageTitle")); } elseif(!double_post($_POST['wpost_id'])) { //double post } elseif ($_POST['version']!='' && $_SESSION['_version']!=0 && $_POST['version']!=$_SESSION['_version']) { //prevent concurrent users and double version Display::display_error_message(get_lang("EditedByAnotherUser")); } else { $return_message=save_wiki(); Display::display_confirmation_message($return_message, false); } } //saving a new wiki entry if (isset($_POST['SaveWikiNew'])) { if (empty($_POST['title'])) { Display::display_error_message(get_lang("NoWikiPageTitle")); } elseif (strtotime(get_date_from_select('startdate_assig')) > strtotime(get_date_from_select('enddate_assig'))) { Display::display_error_message(get_lang("EndDateCannotBeBeforeTheStartDate")); } elseif(!double_post($_POST['wpost_id'])) { //double post } else { $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment if ($_clean['assignment']==1) { auto_add_page_users($_clean['assignment']); } else { $return_message=save_new_wiki(); if ($return_message==false) { Display::display_error_message(get_lang('NoWikiPageTitle'), false); } else { Display::display_confirmation_message($return_message, false); } } } } // check last version if ($_GET['view']) { $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND id="'.Database::escape_string($_GET['view']).'"'; //current view $result=Database::query($sql); $current_row=Database::fetch_array($result); $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; //last version $result=Database::query($sql); $last_row=Database::fetch_array($result); if ($_GET['view']<$last_row['id']) { $message= '
'.get_lang('NoAreSeeingTheLastVersion').'
'.get_lang("Version").' ('.$current_row['version'].' / '.$last_row['version'].')
'.get_lang("ConvertToLastVersion").': '.get_lang("Restore").'
'; Display::display_warning_message($message,false); } ///restore page if ($_GET['action']=='restorepage') { //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher if (($current_row['reflink']=='index' || $current_row['reflink']=='' || $current_row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && intval($_GET['group_id'])==0)) { Display::display_normal_message(get_lang('OnlyEditPagesCourseManager')); } else { $PassEdit=false; //check if is a wiki group if ($current_row['group_id']!=0) { //Only teacher, platform admin and group members can edit a wiki group if (api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],intval($_GET['group_id']))) { $PassEdit=true; } else { Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers')); } } else { $PassEdit=true; } // check if is an assignment if ($current_row['assignment']==1) { Display::display_normal_message(get_lang('EditAssignmentWarning')); $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL); } elseif($current_row['assignment']==2) { $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL); if ((api_get_user_id()==$current_row['user_id'])==false) { if (api_is_allowed_to_edit(false,true) || 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 ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) { Display::display_normal_message(get_lang('PageLockedExtra')); } else { if ($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id']) { //checking for concurrent users $timestamp_edit=strtotime($last_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($last_row['is_editing']); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '. Display::tag('span', api_get_person_name($userinfo['firstname'], $userinfo['lastname'], array('title'=>$username))). get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').''; Display::display_normal_message($is_being_edited, false); } else { Display::display_confirmation_message(restore_wikipage($current_row['page_id'], $current_row['reflink'], $current_row['title'], $current_row['content'], $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': '.api_htmlentities($last_row['title']).'',false); } } } } } } if ($_GET['action']=='deletewiki') { if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { if ($_GET['delete'] == 'yes') { $return_message=delete_wiki(); Display::display_confirmation_message($return_message); } } } if ($_GET['action']=='discuss' && $_POST['Submit']) { Display::display_confirmation_message(get_lang('CommentAdded')); } /* WIKI WRAPPER */ echo '
'; /** Actions bar (= action of the wiki tool, not of the page)**/ //dynamic wiki menu ?> '; echo ' '.Display::return_icon('wiki.png',get_lang('HomeWiki'),'','32').' '; echo ' '.Display::return_icon('menu.png',get_lang('Menu'),'',ICON_SIZE_SMALL).''; ///menu home echo ''; 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 '
'; //menu show page echo '  '.Display::return_icon('page.png',get_lang('ShowThisPage'),'','32').''; if (api_is_allowed_to_session_edit(false,true) ) { //menu edit page echo ''.Display::return_icon('edit.png',get_lang('EditThisPage'),'','32').''; //menu discuss page echo ''.Display::return_icon('discuss.png',get_lang('DiscussThisPage'),'','32').''; } //menu history echo ''.Display::return_icon('history.png',get_lang('ShowPageHistory'),'','32').''; //menu linkspages echo ''.Display::return_icon('what_link_here.png',get_lang('LinksPages'),'','32').''; //menu delete wikipage if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { echo ''.Display::return_icon('delete.png',get_lang('DeleteThisPage'),'','32').''; } echo '
'; } //In new pages go to new page if (isset($_POST['SaveWikiNew'])) { display_wiki_entry($_POST['reflink']); } //More for export to course document area. See display_wiki_entry if ($_POST['export2DOC']) { $doc_id = $_POST['doc_id']; $export2doc = export2doc($doc_id); if ($export2doc) { Display::display_confirmation_message(get_lang('ThePageHasBeenExportedToDocArea')); } } if ($_GET['action']=='more') { echo '
'.get_lang('More').'
'; echo ''; echo ' '; echo ' '; echo ' '; echo ''; echo ' '; echo '
'; echo ' '; echo ' '; echo ' '; echo ''; echo '
    '; //Submenu Statistics if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { echo '
  • '.get_lang('Statistics').'
  • '; } echo '
'; echo'
'; //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 Random page //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO: //Submenu Task //echo '
  • '.get_lang('Task').'
  • ';//TODO:task list order by start date or end date //Submenu Who and Where //echo '
  • '.get_lang('WhoAndWhere').'
  • ';//TODO:Who and where everyone is working now? } // Statistics Juan Carlos Raña Trabado if ($_GET['action']=='statistics' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) { echo '
    '.get_lang('Statistics').'
    '; //check all versions of all pages $total_words = 0; $total_links = 0; $total_links_anchors = 0; $total_links_mail = 0; $total_links_ftp = 0; $total_links_irc = 0; $total_links_news = 0; $total_wlinks = 0; $total_images = 0; $clean_total_flash = 0; $total_flash = 0; $total_mp3 = 0; $total_flv_p = 0; $total_flv = 0; $total_youtube = 0; $total_multimedia = 0; $total_tables = 0; $sql="SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; $allpages=Database::query($sql); while ($row=Database::fetch_array($allpages)) { $total_versions = $row['TOTAL_VERS']; $total_visits = intval($row['TOTAL_VISITS']); } $sql="SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; $allpages=Database::query($sql); while ($row=Database::fetch_array($allpages)) { $total_words = $total_words+word_count($row['content']); $total_links = $total_links+substr_count($row['content'], "href="); $total_links_anchors = $total_links_anchors+substr_count($row['content'], 'href="#'); $total_links_mail = $total_links_mail+substr_count($row['content'], 'href="mailto'); $total_links_ftp = $total_links_ftp+substr_count($row['content'], 'href="ftp'); $total_links_irc = $total_links_irc+substr_count($row['content'], 'href="irc'); $total_links_news = $total_links_news+substr_count($row['content'], 'href="news'); $total_wlinks = $total_wlinks+substr_count($row['content'], "[["); $total_images = $total_images+substr_count($row['content'], "
    '; } // Recent changes // @todo rss feed if ($_GET['action']=='recentchanges') { $_clean['group_id']=(int)$_SESSION['_gid']; if ( api_is_allowed_to_session_edit(false,true) ) { if (check_notify_all()==1) { $notify_all= Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotNotifyChanges'); $lock_unlock_notify_all='unlocknotifyall'; } else { $notify_all=Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotifyChanges'); $lock_unlock_notify_all='locknotifyall'; } } echo '
    '; echo ''.$notify_all.''; echo ''.get_lang('RecentChanges').'
    '; if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.c_id= '.$course_id.' AND '.$tbl_wiki.'.c_id= '.$course_id.' AND '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session.' ORDER BY dtime DESC'; // new version } else { $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1 ORDER BY dtime DESC'; // old version TODO: Replace by the bottom line } $allpages=Database::query($sql); //show table if (Database::num_rows($allpages) > 0) { $row = array (); while ($obj = Database::fetch_object($allpages)) { //get author $userinfo=Database::get_user_info_from_id($obj->user_id); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); //get type assignment icon if ($obj->assignment==1) { $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL); } elseif ($obj->assignment==2) { $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL); } elseif ($obj->assignment==0) { $ShowAssignment=''; } //get icon task if (!empty($obj->task)) { $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL); } else { $icon_task=''; } $row = array (); $row[] = api_get_local_time($obj->dtime, null, date_default_timezone_get()); $row[] = $ShowAssignment.$icon_task; $row[] = ''.api_htmlentities($obj->title).''; $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy'); if ($obj->user_id <> 0 ) { $row[] = ''. Display::tag('span', api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])), array('title'=>$username)). ''; } else { $row[] = get_lang('Anonymous').' ('.api_htmlentities($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']),'session_id'=>Security::remove_XSS($_GET['session_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); $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(false,true) || api_is_platform_admin()) { //only by professors if page is hidden $sql = 'SELECT * FROM '.$tbl_wiki.' s1 WHERE s1.c_id = '.$course_id.' AND id=( SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')'; // warning don't use group by reflink because does not return the last version } else { $sql = 'SELECT * FROM '.$tbl_wiki.' s1 WHERE visibility=1 AND s1.c_id = '.$course_id.' AND id=( SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')'; // warning don't use group by reflink because does not return the last version } $allpages=Database::query($sql); //show table if (Database::num_rows($allpages) > 0) { $row = array (); while ($obj = Database::fetch_object($allpages)) { //get author $userinfo=Database::get_user_info_from_id($obj->user_id); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); //get type assignment icon if ($obj->assignment==1) { $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL); } elseif ($obj->assignment==2) { $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL); } elseif ($obj->assignment==0) { $ShowAssignment=''; } //get icon task if (!empty($obj->task)) { $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL); } else { $icon_task=''; } $row = array (); $row[] =$ShowAssignment.$icon_task; $row[] = ''.api_htmlentities($obj->title).''; if ($obj->user_id <>0) { $row[] = ''. Display::tag('span', api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])), array('title'=>$username)). ''; } else { $row[] = get_lang('Anonymous').' ('.api_htmlentities($obj->user_ip).')'; } $row[] = api_get_local_time($obj->dtime, null, date_default_timezone_get()); if (api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) { $showdelete=' '.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL); } if (api_is_allowed_to_session_edit(false,true) ) { $row[] = ''.Display::return_icon('edit.png', get_lang('EditPage'),'',ICON_SIZE_SMALL).' '.Display::return_icon('discuss.png', get_lang('Discuss'),'',ICON_SIZE_SMALL).' '.Display::return_icon('history.png', get_lang('History'),'',ICON_SIZE_SMALL).' '.Display::return_icon('what_link_here.png', get_lang('LinksPages'),'',ICON_SIZE_SMALL).''.$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); if (api_is_allowed_to_session_edit(false,true) ) { $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:130px;')); } $table->display(); } } // Discuss pages if ($_GET['action']=='discuss') { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } if (!$_GET['title']) { Display::display_error_message(get_lang("MustSelectPage")); exit; } //first extract the date of last version $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; $result=Database::query($sql); $row=Database::fetch_array($result); $lastversiondate=api_get_local_time($row['dtime'], null, date_default_timezone_get()); $lastuserinfo=Database::get_user_info_from_id($row['user_id']); $username = api_htmlentities(sprintf(get_lang('LoginX'), $lastuserinfo['username']), ENT_QUOTES); //select page to discuss $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result=Database::query($sql); $row=Database::fetch_array($result); $id=$row['id']; $firstuserid=$row['user_id']; //mode assignment: previous to show page type if ($row['assignment']==1) { $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL); } elseif($row['assignment']==2) { $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL); } //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(false,true) || 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 (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { if (check_addlock_discuss()==1) { $addlock_disc= Display::return_icon('unlock.png', get_lang('UnlockDiscussExtra'),'',ICON_SIZE_SMALL); $lock_unlock_disc='unlockdisc'; } else { $addlock_disc= Display::return_icon('lock.png', get_lang('LockDiscussExtra'),'',ICON_SIZE_SMALL); $lock_unlock_disc='lockdisc'; } } 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 (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { if (check_visibility_discuss()==1) { /// TODO: Fix Mode assignments: If is hidden, show discussion 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= ''.get_lang('HideDiscussExtra').''; //} $visibility_disc= Display::return_icon('visible.png', get_lang('ShowDiscussExtra'),'',ICON_SIZE_SMALL); $hide_show_disc='hidedisc'; } else { $visibility_disc= Display::return_icon('invisible.png', get_lang('HideDiscussExtra'),'',ICON_SIZE_SMALL); $hide_show_disc='showdisc'; } } echo ''; echo ''.$visibility_disc.''; echo ''; //discussion action: check add rating lock. Show/Hide list to rating for all student if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { if (check_ratinglock_discuss()==1) { $ratinglock_disc= Display::return_icon('star.png', get_lang('UnlockRatingDiscussExtra'),'',ICON_SIZE_SMALL); $lock_unlock_rating_disc='unlockrating'; } else { $ratinglock_disc= Display::return_icon('star_na.png', get_lang('LockRatingDiscussExtra'),'',ICON_SIZE_SMALL); $lock_unlock_rating_disc='lockrating'; } } echo ''; echo ''.$ratinglock_disc.''; echo ''; //discussion action: email notification if (check_notify_discuss($page)==1) { $notify_disc= Display::return_icon('messagebox_info.png', get_lang('NotifyDiscussByEmail'),'',ICON_SIZE_SMALL); $lock_unlock_notify_disc='unlocknotifydisc'; } else { $notify_disc= Display::return_icon('mail.png', get_lang('CancelNotifyDiscussByEmail'),'',ICON_SIZE_SMALL); $lock_unlock_notify_disc='locknotifydisc'; } echo ''; echo ''.$notify_disc.''; echo ''; echo $icon_assignment.'   '.api_htmlentities($row['title']); echo ' ('.get_lang('MostRecentVersionBy').' '. Display::tag('span', api_htmlentities(api_get_person_name($lastuserinfo['firstname'], $lastuserinfo['lastname'])), array('title'=>$username)). ' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read average score echo '
    '; if ($row['addlock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //show comments but students can't add theirs ?>
    ';//prevent double post ?> ';// must pass a default value to avoid rate automatically } ?>
    :
    :
      '.get_lang('Send').''; ?>
    '; $user_table = Database :: get_main_table(TABLE_MAIN_USER); $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.c_id = $course_id AND reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' ORDER BY id DESC"; $result=Database::query($sql) or die(Database::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 c_id = $course_id AND publication_id = '".$id."' AND NOT p_score='-' ORDER BY id DESC"; $result2=Database::query($sql) or die(Database::error()); $row2=Database::fetch_array($result2); $sql="SELECT * FROM $tbl_wiki_discuss WHERE c_id = $course_id AND publication_id='".$id."' AND NOT p_score='-'"; $result3=Database::query($sql) or die(Database::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 c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session; // check if work ok. TODO: Database::query($sql); echo '
    '; //echo '
    '; while ($row=Database::fetch_array($result)) { $userinfo=Database::get_user_info_from_id($row['userc_id']); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); if (($userinfo['status'])=="5") { $author_status=get_lang('Student'); } else { $author_status=get_lang('Teacher'); } $user_id=$row['userc_id']; $name = api_get_person_name($userinfo['firstname'], $userinfo['lastname']); $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= ''.api_htmlentities($name).''; } else { $author_photo= ''.api_htmlentities($name).''; } //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 ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo "
    '.$author_photo.''. Display::tag('span', api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])), array('title'=>$username)). ' ('.$author_status.') '.api_get_local_time($row['dtime'], null, date_default_timezone_get()).' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.'
    '.api_htmlentities($row['comment']).'
    "; echo '


    '; } } else { Display::display_warning_message(get_lang('LockByTeacher'),false); } } else { Display::display_normal_message(get_lang('DiscussNotAvailable')); } } echo "
    "; // echo "
    "; echo "
    "; // echo "
    "; /* FOOTER */ Display::display_footer();