, 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; $current_course_tool = TOOL_WIKI; 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 echo '
'; $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); } } echo '
'; // 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 echo '
'; 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); } } } } echo '
'; // 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 = api_get_user_info($last_row['is_editing']); $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '. Display::tag('span', $userinfo['complete_name_login_as']). 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'], api_htmlentities($current_row['title']), api_htmlentities($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); } } } } } } echo '
'; 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')); } echo '
'; /* 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'),'',ICON_SIZE_MEDIUM).' '; 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 ''; } //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'], "
    '; // echo "
    "; echo "
    "; // echo "
    "; echo "
    "; // echo "
    "; /* FOOTER */ Display::display_footer();