diff --git a/main/wiki/index.php b/main/wiki/index.php index 13dcb29d6f..11e3108e11 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -138,34 +138,14 @@ $wiki->page = $page; Display::display_introduction_section(TOOL_WIKI); /* ACTIONS */ +$wiki->blockConcurrentEditions(api_get_user_id(), $action); -// Release of blocked pages to prevent concurrent editions -echo '
'; - -$result = $wiki->getAllWiki(); -foreach ($result as $is_editing_block) { - $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'] && $action!='edit')) { - $wiki->updateWikiIsEditing($is_editing_block['is_editing']); - } -} -echo '
'; // Saving a change if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') { - if(empty($_POST['title'])) { + if (empty($_POST['title'])) { Display::display_error_message(get_lang("NoWikiPageTitle")); - } elseif(!$wiki->double_post($_POST['wpost_id'])) { + } elseif (!$wiki->double_post($_POST['wpost_id'])) { //double post } elseif ($_POST['version']!='' && $_SESSION['_version']!=0 && $_POST['version']!=$_SESSION['_version']) { //prevent concurrent users and double version @@ -176,8 +156,7 @@ if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') { } } -//saving a new wiki entry -echo '
'; +// Saving a new wiki entry if (isset($_POST['SaveWikiNew'])) { if (empty($_POST['title'])) { Display::display_error_message(get_lang("NoWikiPageTitle")); @@ -195,7 +174,6 @@ if (isset($_POST['SaveWikiNew'])) { if ($_clean['assignment'] == 1) { $wiki->auto_add_page_users($_clean['assignment']); } - $return_message = $wiki->save_new_wiki(); if ($return_message == false) { Display::display_error_message(get_lang('NoWikiPageTitle'), false); @@ -204,12 +182,13 @@ if (isset($_POST['SaveWikiNew'])) { } } } -echo '
'; // check last version if (isset($_GET['view']) && $_GET['view']) { $sql = 'SELECT * FROM '.$tbl_wiki.' - WHERE c_id = '.$course_id.' AND id="'.Database::escape_string($_GET['view']).'"'; //current view + WHERE + c_id = '.$course_id.' AND + id="'.Database::escape_string($_GET['view']).'"'; //current view $result=Database::query($sql); $current_row=Database::fetch_array($result); @@ -219,24 +198,30 @@ if (isset($_GET['view']) && $_GET['view']) { $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").'
'; + $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 + // Restore page. - if ($action=='restorepage') { + if ($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)) { + 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) { + 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; + $PassEdit = true; } else { Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers')); } @@ -263,21 +248,20 @@ if (isset($_GET['view']) && $_GET['view']) { } } - if ($PassEdit) { //show editor if edit is allowed + //show editor if edit is allowed + if ($PassEdit) { if ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) { - Display::display_normal_message(get_lang('PageLockedExtra')); + Display::display_normal_message(get_lang('PageLockedExtra')); } else { - if ($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id']) { + 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; - + $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']); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); - - $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '. + $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); @@ -304,7 +288,6 @@ if (isset($_GET['view']) && $_GET['view']) { } } -echo '
'; if ($action == 'deletewiki') { if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['delete'] == 'yes') { @@ -316,7 +299,6 @@ if ($action == 'deletewiki') { if ($action =='discuss' && isset($_POST['Submit']) && $_POST['Submit']) { Display::display_confirmation_message(get_lang('CommentAdded')); } -echo '
'; /* MAIN WIKI AREA */ @@ -386,7 +368,7 @@ if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { echo '
is_active_navigation_tab('delete').'>'.Display::return_icon('delete.png',get_lang('DeleteThisPage'),'',ICON_SIZE_MEDIUM).''; } echo ''; -echo ''; +echo ''; // End actions //In new pages go to new page @@ -406,7 +388,6 @@ if (isset($_POST['export2DOC']) && $_POST['export2DOC']) { } if (isset($action) && $action =='more') { - echo '
'.get_lang('More').'
'; echo ''; echo ' '; @@ -422,17 +403,17 @@ if (isset($action) && $action =='more') { echo ' '; echo ' '; echo ''; echo ' '; echo '
'; echo ' '; echo ''; echo '
    '; - //Submenu Statistics + // Submenu Statistics if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { echo '
  • '.get_lang('Statistics').'
  • '; } @@ -440,584 +421,18 @@ if (isset($action) && $action =='more') { 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 ($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 + $wiki->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'], "word_count($row['content']); - $total_links_lv = $total_links_lv+substr_count($row['content'], "href="); - $total_links_anchors_lv = $total_links_anchors_lv+substr_count($row['content'], 'href="#'); - $total_links_mail_lv = $total_links_mail_lv+substr_count($row['content'], 'href="mailto'); - $total_links_ftp_lv = $total_links_ftp_lv+substr_count($row['content'], 'href="ftp'); - $total_links_irc_lv = $total_links_irc_lv+substr_count($row['content'], 'href="irc'); - $total_links_news_lv = $total_links_news_lv+substr_count($row['content'], 'href="news'); - $total_wlinks_lv = $total_wlinks_lv+substr_count($row['content'], "[["); - $total_images_lv = $total_images_lv+substr_count($row['content'], "