From 3e46c0270745faa45400850661efadddcf55e2b6 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 28 Nov 2013 15:02:36 +0100 Subject: [PATCH 1/4] Minor - adding message. --- main/cron/import_csv.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index 1b921f3132..ac0fb593a7 100644 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -160,7 +160,7 @@ class ImportCsv $method = $fileInfo['method']; $file = $fileInfo['file']; echo 'Static file: '.$file.PHP_EOL; - $this->logger->addInfo("Reading file: $file"); + $this->logger->addInfo("Reading static file: $file"); $this->$method($file, true); } } @@ -673,6 +673,7 @@ class ImportCsv $this->logger->addError($result['error_message']); } $this->logger->addInfo("Sessions - Sessions parsed: ".$result['session_counter']); + if ($moveFile) { $this->moveFile($file); } From a18e192ce48d857e048352a7567f4c2753ee52e4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 29 Nov 2013 14:46:01 +0100 Subject: [PATCH 2/4] Fixing empty title in work list see BT#6916 --- main/work/work.lib.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index e50074ed18..4b0316f1b5 100644 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -857,13 +857,15 @@ function build_work_move_to_selector($folders, $curdirpath, $move_file, $group_d $course_id = api_get_course_int_id(); $move_file = intval($move_file); $tbl_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $sql = "SELECT title FROM $tbl_work WHERE c_id = $course_id AND id ='".$move_file."'"; + $sql = "SELECT title, url FROM $tbl_work WHERE c_id = $course_id AND id ='".$move_file."'"; $result = Database::query($sql); - $title = Database::fetch_row($result); + $row = Database::fetch_array($result, 'ASSOC'); + $title = empty($row['title']) ? basename($row['url']) : $row['title']; + global $gradebook; //@todo use formvalidator please! $form = '
'; - $form .= ''.get_lang('MoveFile').' - '.Security::remove_XSS($title[0]).''; + $form .= ''.get_lang('MoveFile').' - '.Security::remove_XSS($title).''; $form .= ''; $form .= ''; $form .= '
@@ -1581,6 +1583,9 @@ function getWorkListStudent($start, $limit, $column, $direction, $where_conditio $work['type'] = Display::return_icon('work.png'); $work['expires_on'] = $work['expires_on'] == '0000-00-00 00:00:00' ? null : api_get_local_time($work['expires_on']); + if (empty($work['title'])) { + $work['title'] = basename($work['url']); + } $work['title'] = Display::url($work['title'], $url.'&id='.$work['id']); $work['others'] = Display::url(Display::return_icon('group.png', get_lang('Others')), $urlOthers.$work['id']); $works[] = $work; @@ -1595,6 +1600,7 @@ function getWorkListStudent($start, $limit, $column, $direction, $where_conditio * @param string $column * @param string $direction * @param string $where_condition + * @param bool $getCount * @return array */ function getWorkListTeacher($start, $limit, $column, $direction, $where_condition, $getCount = false) @@ -1643,6 +1649,9 @@ function getWorkListTeacher($start, $limit, $column, $direction, $where_conditio $work['type'] = Display::return_icon('work.png'); $work['expires_on'] = $work['expires_on'] == '0000-00-00 00:00:00' ? null : api_get_local_time($work['expires_on']); $work['ends_on'] = $work['ends_on'] == '0000-00-00 00:00:00' ? null : api_get_local_time($work['ends_on']); + if (empty($work['title'])) { + $work['title'] = basename($work['url']); + } $work['title'] = Display::url($work['title'], $url.'&id='.$work['id']); $works[] = $work; } @@ -3775,7 +3784,8 @@ function generateMoveForm($item_id, $path, $courseInfo, $groupId, $sessionId) $sessionCondition"; $res = Database::query($sql); while ($folder = Database::fetch_array($res)) { - $folders[$folder['id']] = $folder['title']; + $title = empty($folder['title']) ? basename($folder['url']) : $folder['title']; + $folders[$folder['id']] = $title; } return build_work_move_to_selector($folders, $path, $item_id); } From b6a83268b2a64a2485e451eb793bf56bb4dc9c71 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 29 Nov 2013 15:39:20 +0100 Subject: [PATCH 3/4] Cleaning code, format code, fixing php notices. --- main/wiki/index.php | 284 ++++++++++------------- main/wiki/wiki.inc.php | 495 +++++++++++++++++------------------------ 2 files changed, 320 insertions(+), 459 deletions(-) diff --git a/main/wiki/index.php b/main/wiki/index.php index 3fbd1a190f..6ecc13ef81 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -15,51 +15,45 @@ $language_file = 'wiki'; // including the global initialization file require_once '../inc/global.inc.php'; +//error_reporting(-1); + // section (for the tabs) $this_section = SECTION_COURSES; $current_course_tool = TOOL_WIKI; - -// including additional library scripts - 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[] = ''; +$(document).ready(function () { + setFocus(); +}); +'; // 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 -*/ +/* 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")); @@ -76,29 +70,19 @@ api_block_anonymous_users(); /* TRACKING */ event_access_tool(TOOL_WIKI); -/* -HEADER & TITLE -*/ +/* 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']); - } +// Setting variable +$groupId = api_get_group_id(); - $group_properties = GroupManager :: get_group_properties($_clean['group_id']); +if ($groupId) { + $group_properties = GroupManager::get_group_properties($groupId); $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']); + $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$groupId, "name"=> get_lang('GroupSpace').' '.$group_properties['name']); $add_group_to_title = ' '.$group_properties['name']; - $groupfilter='group_id="'.$_clean['group_id'].'"'; + $groupfilter='group_id="'.$groupId.'"'; //ensure this tool in groups whe it's private or deactivated if ($group_properties['wiki_state']==0) { @@ -112,22 +96,18 @@ if ($_SESSION['_gid'] OR $_GET['group_id']) { $groupfilter='group_id=0'; } - -if ($_POST['action']=='export_to_pdf' && isset($_POST['wiki_id']) && api_get_setting('students_export2pdf') == 'true') { +if (isset($_POST['action']) && $_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; } +$action = isset($_GET['action']) ? $_GET['action'] : null; Display::display_header($tool_name, 'Wiki'); $is_allowed_to_edit = api_is_allowed_to_edit(false,true); +/* INITIALISATION */ -//api_display_tool_title($tool_name.$add_group_to_title); - -/* -INITIALISATION -*/ //the page we are dealing with if (!isset($_GET['title'])) { $page = 'index'; @@ -135,25 +115,17 @@ if (!isset($_GET['title'])) { $page = $_GET['title']; } -// some titles are not allowed -// $not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now - -/* -MAIN CODE -*/ +/* MAIN CODE */ // Tool introduction Display::display_introduction_section(TOOL_WIKI); -/* - ACTIONS -*/ - +/* ACTIONS */ -//release of blocked pages to prevent concurrent editions +// 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); +$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']); @@ -166,7 +138,7 @@ while ($is_editing_block=Database::fetch_array($result)) { 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')) { + if ($time_editing>$max_edit_time || ($is_editing_block['is_editing']==$_user['user_id'] && $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); @@ -175,20 +147,19 @@ while ($is_editing_block=Database::fetch_array($result)) { 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); - } +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 '
'; @@ -215,9 +186,8 @@ echo '
'; } echo '
'; - // check last version -if ($_GET['view']) { +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 $result=Database::query($sql); $current_row=Database::fetch_array($result); @@ -226,14 +196,14 @@ if ($_GET['view']) { $result=Database::query($sql); $last_row=Database::fetch_array($result); - if ($_GET['view']<$last_row['id']) { + 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') { + 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)) { Display::display_normal_message(get_lang('OnlyEditPagesCourseManager')); @@ -300,7 +270,7 @@ if ($_GET['view']) { } echo '
'; - if ($_GET['action']=='deletewiki') { + if ($action=='deletewiki') { if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { if ($_GET['delete'] == 'yes') { $return_message=delete_wiki(); @@ -310,12 +280,11 @@ echo '
'; } - if ($_GET['action']=='discuss' && $_POST['Submit']) { + if ($action =='discuss' && $_POST['Submit']) { Display::display_confirmation_message(get_lang('CommentAdded')); } echo '
'; - /* WIKI WRAPPER */ echo '
'; @@ -348,14 +317,14 @@ document.getElementById("menuwiki").style.border=b+"px solid #cccccc"; echo ''; 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'))) { +if (!in_array($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'),'',ICON_SIZE_MEDIUM).''; + echo '  '.Display::return_icon('page.png',get_lang('ShowThisPage'),'',ICON_SIZE_MEDIUM).''; if (api_is_allowed_to_session_edit(false,true) ) { //menu edit page - echo ''.Display::return_icon('edit.png',get_lang('EditThisPage'),'',ICON_SIZE_MEDIUM).''; + echo ''.Display::return_icon('edit.png',get_lang('EditThisPage'),'',ICON_SIZE_MEDIUM).''; //menu discuss page echo ''.Display::return_icon('discuss.png',get_lang('DiscussThisPage'),'',ICON_SIZE_MEDIUM).''; } //menu history - echo ''.Display::return_icon('history.png',get_lang('ShowPageHistory'),'',ICON_SIZE_MEDIUM).''; + echo ''.Display::return_icon('history.png',get_lang('ShowPageHistory'),'',ICON_SIZE_MEDIUM).''; //menu linkspages - echo ''.Display::return_icon('what_link_here.png',get_lang('LinksPages'),'',ICON_SIZE_MEDIUM).''; + echo ''.Display::return_icon('what_link_here.png',get_lang('LinksPages'),'',ICON_SIZE_MEDIUM).''; //menu delete wikipage if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { @@ -425,16 +394,15 @@ if (isset($_POST['SaveWikiNew'])) { } //More for export to course document area. See display_wiki_entry -if ($_POST['export2DOC']) { +if (isset($_POST['export2DOC']) && $_POST['export2DOC']) { $doc_id = $_POST['doc_id']; $export2doc = export2doc($doc_id); if ($export2doc) { Display::display_confirmation_message(get_lang('ThePageHasBeenExportedToDocArea')); } - } -if ($_GET['action']=='more') { +if (isset($action ) =='more') { echo '
'.get_lang('More').'
'; @@ -443,28 +411,28 @@ if ($_GET['action']=='more') { echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ''; echo ''; echo ''; echo' '; @@ -472,45 +440,45 @@ if ($_GET['action']=='more') { echo ''; //Submenu Dead end pages - //echo '
  • '.get_lang('DeadEndPages').'
  • ';//TODO: + //echo '
  • '.get_lang('DeadEndPages').'
  • ';//TODO: //Submenu Most new pages (not versions) - //echo '
  • '.get_lang('MostNewPages').'
  • ';//TODO: + //echo '
  • '.get_lang('MostNewPages').'
  • ';//TODO: //Submenu Most long pages - //echo '
  • '.get_lang('MostLongPages').'
  • ';//TODO: + //echo '
  • '.get_lang('MostLongPages').'
  • ';//TODO: //Submenu Protected pages - //echo '
  • '.get_lang('ProtectedPages').'
  • ';//TODO: + //echo '
  • '.get_lang('ProtectedPages').'
  • ';//TODO: //Submenu Hidden pages - //echo '
  • '.get_lang('HiddenPages').'
  • ';//TODO: + //echo '
  • '.get_lang('HiddenPages').'
  • ';//TODO: //Submenu Most discuss pages - //echo '
  • '.get_lang('MostDiscussPages').'
  • ';//TODO: + //echo '
  • '.get_lang('MostDiscussPages').'
  • ';//TODO: //Submenu Best scored pages - //echo '
  • '.get_lang('BestScoredPages').'
  • ';//TODO: + //echo '
  • '.get_lang('BestScoredPages').'
  • ';//TODO: //Submenu Pages with more progress - //echo '
  • '.get_lang('MProgressPages').'
  • ';//TODO: + //echo '
  • '.get_lang('MProgressPages').'
  • ';//TODO: //Submenu Most active users in discuss - //echo '
  • '.get_lang('MostDiscussUsers').'
  • ';//TODO: + //echo '
  • '.get_lang('MostDiscussUsers').'
  • ';//TODO: //Submenu Random page - //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO: + //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO: //Submenu Task - //echo '
  • '.get_lang('Task').'
  • ';//TODO:task list order by start date or end date + //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? + //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())) { +if ($action =='statistics' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) { echo '
    '.get_lang('Statistics').'
    '; @@ -998,7 +966,7 @@ echo '
    '; // Most active users Juan Carlos Raña Trabado -if ($_GET['action']=='mactiveusers') { +if ($action =='mactiveusers') { echo '
    '.get_lang('MostActiveUsers').'
    '; $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY user_id'; @@ -1026,7 +994,7 @@ if ($_GET['action']=='mactiveusers') { } $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']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); $table->set_header(0,get_lang('Author'), true); $table->set_header(1,get_lang('Contributions'), true,array ('style' => 'width:30px;')); $table->display(); @@ -1035,7 +1003,7 @@ if ($_GET['action']=='mactiveusers') { // User contributions Juan Carlos Raña Trabado -if ($_GET['action']=='usercontrib') { +if ($action =='usercontrib') { $userinfo=Database::get_user_info_from_id($_GET['user_id']); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES); @@ -1050,7 +1018,7 @@ if ($_GET['action']=='usercontrib') { $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND user_id="'.Database::escape_string($_GET['user_id']).'" AND visibility=1'; } - $allpages=Database::query($sql); + $allpages = Database::query($sql); //show table if (Database::num_rows($allpages) > 0) { @@ -1083,19 +1051,14 @@ if ($_GET['action']=='usercontrib') { $row[] = ''.api_htmlentities($obj->title).''; $row[] =Security::remove_XSS($obj->version); $row[] =Security::remove_XSS($obj->comment); - //$row[] = api_strlen($obj->comment)>30 ? Security::remove_XSS(api_substr($obj->comment,0,30)).'...' : Security::remove_XSS($obj->comment); $row[] =Security::remove_XSS($obj->progress).' %'; $row[] =Security::remove_XSS($obj->score); - //if(api_is_allowed_to_edit() || api_is_platform_admin()) - //{ - //$row[] =Security::remove_XSS($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']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'user_id'=>Security::remove_XSS($_GET['user_id']),'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;')); @@ -1104,18 +1067,13 @@ if ($_GET['action']=='usercontrib') { $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 +/* Most changed pages */ -if ($_GET['action']=='mostchanged') { +if ($action =='mostchanged') { echo '
    '.get_lang('MostChangedPages').'
    '; @@ -1148,7 +1106,7 @@ if ($_GET['action']=='mostchanged') { } $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']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'session_id'=>Security::remove_XSS($_GET['session_id']),'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); @@ -1156,9 +1114,9 @@ if ($_GET['action']=='mostchanged') { } } -/////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado +/* Most visited pages */ -if ($_GET['action']=='mvisited') { +if ($action =='mvisited') { echo '
    '.get_lang('MostVisitedPages').'
    '; if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden @@ -1190,7 +1148,7 @@ if ($_GET['action']=='mvisited') { } $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']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'session_id'=>Security::remove_XSS($_GET['session_id']),'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); @@ -1198,9 +1156,9 @@ if ($_GET['action']=='mvisited') { } } -/////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado +/* Wanted pages */ -if ($_GET['action']=='wanted') { +if ($action =='wanted') { echo '
    '.get_lang('WantedPages').'
    '; $pages = array(); @@ -1222,7 +1180,7 @@ if ($_GET['action']=='wanted') { $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.$condition_session.')'; - $allpages=Database::query($sql); + $allpages = Database::query($sql); while ($row=Database::fetch_array($allpages)) { @@ -1251,14 +1209,14 @@ if ($_GET['action']=='wanted') { } $table = new SortableTableFromArrayConfig($rows,0,10,'WantedPages_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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); $table->set_header(0,get_lang('Title'), true); $table->display(); } -/////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado +/* Orphaned pages */ -if ($_GET['action']=='orphaned') { +if ($action =='orphaned') { echo '
    '.get_lang('OrphanedPages').'
    '; $pages = array(); @@ -1326,7 +1284,7 @@ if ($_GET['action']=='orphaned') { } $table = new SortableTableFromArrayConfig($rows,1,10,'OrphanedPages_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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'session_id'=>Security::remove_XSS($_GET['session_id']),'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->display(); @@ -1334,7 +1292,7 @@ if ($_GET['action']=='orphaned') { /////////////////////// Most linked pages /////////////////////// Juan Carlos Raña Trabado -if ($_GET['action']=='mostlinked') { +if ($action =='mostlinked') { echo '
    '.get_lang('MostLinkedPages').'
    '; $pages = array(); $refs = array(); @@ -1382,7 +1340,7 @@ if ($_GET['action']=='mostlinked') { } $table = new SortableTableFromArrayConfig($rows,0,10,'LinkedPages_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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($action ),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); $table->set_header(0,get_lang('Title'), true); $table->display(); @@ -1390,7 +1348,7 @@ if ($_GET['action']=='mostlinked') { /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado -if ($_GET['action']=='delete') { +if ($action =='delete') { if (!$_GET['title']) { Display::display_error_message(get_lang('MustSelectPage')); @@ -1436,7 +1394,7 @@ if ($_GET['action']=='delete') { /////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado -if ($_GET['action']=='deletewiki') { +if ($action =='deletewiki') { echo '
    '.get_lang('DeleteWiki').'
    '; echo '
    '; @@ -1459,7 +1417,7 @@ if ($_GET['action']=='deletewiki') { /////////////////////// search wiki pages /////////////////////// -if ($_GET['action']=='searchpages') { +if ($action =='searchpages') { echo '
    '.get_lang('SearchPages').'
    '; echo '
    '; @@ -1474,7 +1432,7 @@ if ($_GET['action']=='searchpages') { } else { // initiate the object - $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.api_htmlentities($_GET['cidReq']).'&action='.api_htmlentities($_GET['action']).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'&mode_table=yes1&search_term='.api_htmlentities($_GET['search_term']).'&search_content='.api_htmlentities($_GET['search_content']).'&all_vers='.api_htmlentities($_GET['all_vers'])); + $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.api_htmlentities($_GET['cidReq']).'&action='.api_htmlentities($action ).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'&mode_table=yes1&search_term='.api_htmlentities($_GET['search_term']).'&search_content='.api_htmlentities($_GET['search_content']).'&all_vers='.api_htmlentities($_GET['all_vers'])); // settting the form elements @@ -1501,7 +1459,7 @@ if ($_GET['action']=='searchpages') { /////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado -if ($_GET['action']=='links') { +if ($action =='links') { if (!$_GET['title']) { Display::display_error_message(get_lang("MustSelectPage")); @@ -1586,7 +1544,7 @@ if ($_GET['action']=='links') { } $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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($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); @@ -1602,7 +1560,7 @@ if ($_GET['action']=='links') { // Display the form for adding a new wiki page echo '
    '; -if ($_GET['action']=='addnew') { +if ($action =='addnew') { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } @@ -1631,14 +1589,14 @@ if ($_GET['action']=='addnew') { // Show home page -if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew'])) { +if (!$action OR $action =='show' AND !isset($_POST['SaveWikiNew'])) { display_wiki_entry($newtitle); } // Show current page -if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew'])) { +if ($action =='showpage' AND !isset($_POST['SaveWikiNew'])) { if ($_GET['title']) { display_wiki_entry($newtitle); } else { @@ -1648,14 +1606,12 @@ if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew'])) { // Edit current page -if ($_GET['action']=='edit') { +if (isset($action ) && $action =='edit') { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } - $_clean['group_id']=(int)$_SESSION['_gid']; - $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki.'.c_id = '.$course_id.' AND @@ -1692,7 +1648,7 @@ if ($_GET['action']=='edit') { $PassEdit=false; //check if is a wiki group - if ($_clean['group_id']!=0) { + if ($groupId!=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; @@ -2029,14 +1985,12 @@ if ($_GET['action']=='edit') { // Page history -if ($_GET['action']=='history' or $_POST['HistoryDifferences']) { +if ($action =='history' or $_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 @@ -2203,8 +2157,8 @@ if ($_GET['action']=='history' or $_POST['HistoryDifferences']) { // @todo rss feed -if ($_GET['action']=='recentchanges') { - $_clean['group_id']=(int)$_SESSION['_gid']; +if ($action =='recentchanges') { + $groupId=(int)$_SESSION['_gid']; if ( api_is_allowed_to_session_edit(false,true) ) { if (check_notify_all()==1) { @@ -2278,7 +2232,7 @@ if ($_GET['action']=='recentchanges') { } $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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($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); @@ -2292,12 +2246,9 @@ if ($_GET['action']=='recentchanges') { // All pages - -if ($_GET['action']=='allpages') { +if ($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=( @@ -2359,7 +2310,7 @@ if ($_GET['action']=='allpages') { } $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_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($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); @@ -2373,7 +2324,7 @@ if ($_GET['action']=='allpages') { // Discuss pages -if ($_GET['action']=='discuss') { +if ($action == 'discuss') { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { api_not_allowed(); } @@ -2661,7 +2612,4 @@ echo '
    '; // echo "
    "; echo "
    "; // echo "
    "; echo "
    "; // echo "
    "; -/* -FOOTER -*/ -Display::display_footer(); \ No newline at end of file +Display::display_footer(); diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index 6372e600a8..bb2a181690 100644 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -10,11 +10,11 @@ /* FUNCTIONS FOR WIKI */ /** - * Create a reference link for a given new page title (adds incremental number - * to the title). It is a recursive function because every newly created + * Create a reference link for a given new page title (adds incremental number + * to the title). It is a recursive function because every newly created * reflink suggestion has to be checked also * @author Patrick Cool , Ghent University - * @param + * @param */ function createreflink($testvalue) { $counter=''; @@ -30,7 +30,7 @@ function createreflink($testvalue) { /** - * Check whether this title is already used + * Check whether this title is already used * @param string title * @return bool False if title is already taken * @author Patrick Cool , Ghent University @@ -39,9 +39,9 @@ function checktitle($paramwk) { global $tbl_wiki; global $groupfilter; global $condition_session; - + $course_id = api_get_course_int_id(); - + $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($paramwk).'" AND '.$groupfilter.$condition_session.''; $result=Database::query($sql); $numberofresults=Database::num_rows($result); @@ -129,7 +129,7 @@ function detect_mail_link($input) { return $output; } -/** +/** * detect and add style to ftp links * @author Juan Carlos Raña Trabado **/ @@ -171,35 +171,25 @@ function detect_irc_link($input) { **/ function make_wiki_link_clickable($input) { global $_course; - - if (isset($_SESSION['_gid'])) { - $_clean['group_id']=intval($_SESSION['_gid']); - } - if (isset($_GET['group_id'])) { - $_clean['group_id']=intval($_GET['group_id']); - } - $session_id=api_get_session_id(); // TODO: check - + $groupId = api_get_group_id(); + $session_id = api_get_session_id(); // TODO: check $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE); //now doubles brackets - foreach ($input_array as $key=>$value) - { - - if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') //now doubles brackets - { - + foreach ($input_array as $key=>$value) { + //now doubles brackets + if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') { /////////// TODO: metawiki /* if ($session_id==0) { - if ($_clean['group_id']==0) + if ($groupId==0) { $titleg_ex=''; } else { - $group_properties = GroupManager :: get_group_properties($_clean['group_id']); + $group_properties = GroupManager :: get_group_properties($groupId); $group_name= $group_properties['name']; $titleg_ex='('.$group_name.')'; } @@ -211,7 +201,7 @@ function make_wiki_link_clickable($input) { */ ///////// - + //now full wikilink if (api_strpos($value, "|") !== false){ $full_link_array=explode("|", $value); @@ -235,11 +225,11 @@ function make_wiki_link_clickable($input) { if (checktitle(strtolower(str_replace(' ','_',$link)))) { $link = api_html_entity_decode($link); - $input_array[$key]=''.$title.''; + $input_array[$key]=''.$title.''; } else { - $input_array[$key]=''.$title.''; + $input_array[$key]=''.$title.''; } unset($input_array[$key-1]); unset($input_array[$key+1]); @@ -261,7 +251,7 @@ function save_wiki() { // cleaning the variables $_clean['page_id'] = Database::escape_string($_POST['page_id']); - $_clean['reflink'] = Database::escape_string(trim($_POST['reflink'])); + $_clean['reflink'] = Database::escape_string(trim($_POST['reflink'])); $_clean['title'] = Database::escape_string(trim($_POST['title'])); $_clean['content'] = Database::escape_string($_POST['content']); if (api_get_setting('htmlpurifier_wiki') == 'true'){ @@ -277,20 +267,11 @@ function save_wiki() { $dtime = date( "Y-m-d H:i:s" ); $session_id = api_get_session_id(); - - if (isset($_SESSION['_gid'])) - { - $_clean['group_id']=Database::escape_string($_SESSION['_gid']); - } - if (isset($_GET['group_id'])) - { - $_clean['group_id']=Database::escape_string($_GET['group_id']); - } + $groupId = api_get_group_id(); //cleaning config variables - if(!empty($_POST['task'])) - { + if(!empty($_POST['task'])) { $_clean['task']= Database::escape_string($_POST['task']); } if(!empty($_POST['feedback1']) || !empty($_POST['feedback2']) || !empty($_POST['feedback3'])) { @@ -327,11 +308,11 @@ function save_wiki() { $_clean['max_text'] =Database::escape_string($_POST['max_text']); $_clean['max_version']=Database::escape_string($_POST['max_version']); } - + $course_id = api_get_course_int_id(); - + $sql = "INSERT INTO ".$tbl_wiki." (c_id, page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip, session_id) - VALUES ($course_id, '".$_clean['page_id']."','".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$dtime."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')"; + VALUES ($course_id, '".$_clean['page_id']."','".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$groupId."','".$dtime."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')"; $result = Database::query($sql); @@ -339,7 +320,7 @@ function save_wiki() { if ($Id > 0) { //insert into item_property - api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']); + api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $groupId); } if ($_clean['page_id'] ==0) { @@ -352,11 +333,11 @@ function save_wiki() { $sql="INSERT INTO ".$tbl_wiki_conf." (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) VALUES ($course_id, '".$Id."','".$_clean['task']."','".$_clean['feedback1']."','".$_clean['feedback2']."','".$_clean['feedback3']."','".$_clean['fprogress1']."','".$_clean['fprogress2']."','".$_clean['fprogress3']."','".$_clean['max_text']."','".$_clean['max_version']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['delayedsubmit']."')"; } else { - $sql='UPDATE'.$tbl_wiki_conf.' SET task="'.$_clean['task'].'", feedback1="'.$_clean['feedback1'].'", feedback2="'.$_clean['feedback2'].'", feedback3="'.$_clean['feedback3'].'", fprogress1="'.$_clean['fprogress1'].'", fprogress2="'.$_clean['fprogress2'].'", fprogress3="'.$_clean['fprogress3'].'", max_text="'.$_clean['max_text'].'", max_version="'.$_clean['max_version'].'", startdate_assig="'.$_clean['startdate_assig'].'", enddate_assig="'.$_clean['enddate_assig'].'", delayedsubmit="'.$_clean['delayedsubmit'].'" + $sql='UPDATE'.$tbl_wiki_conf.' SET task="'.$_clean['task'].'", feedback1="'.$_clean['feedback1'].'", feedback2="'.$_clean['feedback2'].'", feedback3="'.$_clean['feedback3'].'", fprogress1="'.$_clean['fprogress1'].'", fprogress2="'.$_clean['fprogress2'].'", fprogress3="'.$_clean['fprogress3'].'", max_text="'.$_clean['max_text'].'", max_version="'.$_clean['max_version'].'", startdate_assig="'.$_clean['startdate_assig'].'", enddate_assig="'.$_clean['enddate_assig'].'", delayedsubmit="'.$_clean['delayedsubmit'].'" WHERE page_id="'.$_clean['page_id'].'" AND c_id = '.$course_id; } Database::query($sql); - api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']); + api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id(), $groupId); check_emailcue($_clean['reflink'], 'P', $dtime, $_clean['user_id']); return get_lang('ChangesStored'); } @@ -375,7 +356,7 @@ function restore_wikipage($r_page_id, $r_reflink, $r_title, $r_content, $r_group $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); - $sql="INSERT INTO ".$tbl_wiki." (c_id, page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES + $sql="INSERT INTO ".$tbl_wiki." (c_id, page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES ($course_id, '".$r_page_id."','".$r_reflink."','".$r_title."','".$r_content."','".$r_user_id."','".$r_group_id."','".$r_dtime."','".$r_assignment."','".$r_comment."','".$r_progress."','".$r_version."','".$r_linksto."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."','".Database::escape_string($session_id)."')"; $result=Database::query($sql); @@ -394,13 +375,13 @@ function restore_wikipage($r_page_id, $r_reflink, $r_title, $r_content, $r_group **/ function delete_wiki() { global $tbl_wiki, $tbl_wiki_conf, $tbl_wiki_discuss, $tbl_wiki_mailcue, $groupfilter, $condition_session; - + $course_id = api_get_course_int_id(); - + //identify the first id by group = identify wiki $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; $allpages = Database::query($sql); - + while ($row=Database::fetch_array($allpages)) { $id = $row['id']; @@ -444,18 +425,18 @@ function save_new_wiki() { $_clean['reflink'] = Database::escape_string(strip_tags(api_htmlentities($page))); $_clean['title'] = Database::escape_string(strip_tags(trim($_POST['title']))); $_clean['content'] = Database::escape_string($_POST['content']); - + if (api_get_setting('htmlpurifier_wiki') == 'true'){ $purifier = new HTMLPurifier(); $_clean['content'] = $purifier->purify($_clean['content']); } - + //re-check after strip_tags if the title is empty if(empty($_clean['title']) || empty($_clean['reflink'])){ - + return false; } - + if($_clean['assignment']==2) {//config by default for individual assignment (students) $_clean['user_id']=(int)Database::escape_string($assig_user_id);//Identifies the user as a creator, not the teacher who created @@ -477,14 +458,7 @@ function save_new_wiki() { $_clean['progress']=Database::escape_string($_POST['progress']); $_clean['version']=1; - if (isset($_SESSION['_gid'])) - { - $_clean['group_id']=(int)$_SESSION['_gid']; - } - if (isset($_GET['group_id'])) - { - $_clean['group_id']=(int)Database::escape_string($_GET['group_id']); - } + $groupId = api_get_group_id(); $_clean['linksto'] = links_to($_clean['content']); //check wikilinks @@ -512,9 +486,9 @@ function save_new_wiki() { $_clean['delayedsubmit']=Database::escape_string($_POST['delayedsubmit']); $_clean['max_text']=Database::escape_string($_POST['max_text']); $_clean['max_version']=Database::escape_string($_POST['max_version']); - + $course_id = api_get_course_int_id(); - + //filter no _uass if (api_eregi('_uass', $_POST['title']) || (api_strtoupper(trim($_POST['title'])) == 'INDEX' || api_strtoupper(trim(api_htmlentities($_POST['title'], ENT_QUOTES, $charset))) == api_strtoupper(api_htmlentities(get_lang('DefaultTitle'), ENT_QUOTES, $charset)))) { $message= get_lang('GoAndEditMainPage'); @@ -526,21 +500,21 @@ function save_new_wiki() { return get_lang('WikiPageTitleExist').''.$_POST['title'].''; } else { $dtime = date( "Y-m-d H:i:s" ); - $sql = "INSERT INTO ".$tbl_wiki." (c_id, reflink, title, content, user_id, group_id, dtime, visibility, visibility_disc, ratinglock_disc, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES - ($course_id, '".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$dtime."','".$_clean['visibility']."','".$_clean['visibility_disc']."','".$_clean['ratinglock_disc']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')"; + $sql = "INSERT INTO ".$tbl_wiki." (c_id, reflink, title, content, user_id, group_id, dtime, visibility, visibility_disc, ratinglock_disc, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES + ($course_id, '".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$groupId."','".$dtime."','".$_clean['visibility']."','".$_clean['visibility_disc']."','".$_clean['ratinglock_disc']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')"; $result = Database::query($sql); $Id = Database::insert_id(); if ($Id > 0) { //insert into item_property - api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']); + api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $groupId); } $sql='UPDATE '.$tbl_wiki.' SET page_id="'.$Id.'" WHERE c_id = '.$course_id.' AND id="'.$Id.'"'; Database::query($sql); //insert wiki config - $sql="INSERT INTO ".$tbl_wiki_conf." (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) VALUES + $sql="INSERT INTO ".$tbl_wiki_conf." (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) VALUES ($course_id, '".$Id."','".$_clean['task']."','".$_clean['feedback1']."','".$_clean['feedback2']."','".$_clean['feedback3']."','".$_clean['fprogress1']."','".$_clean['fprogress2']."','".$_clean['fprogress3']."','".$_clean['max_text']."','".$_clean['max_version']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['delayedsubmit']."')"; Database::query($sql); @@ -584,10 +558,8 @@ return true; echo '
    '; echo '
    * '.get_lang(Title).':
    '; - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) - { - - $_clean['group_id']=(int)$_SESSION['_gid']; // TODO: check if delete ? + if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { + $groupId = api_get_group_id(); echo' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').''; echo '