* @author Patrick Cool , Ghent University, Belgium * @author Julio Montoya using the pdf.lib.php library * @package chamilo.wiki */ /* 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 * reflink suggestion has to be checked also * @author Patrick Cool , Ghent University * @param */ function createreflink($testvalue) { $counter = ''; while (!checktitle($testvalue.$counter)) { $counter++; echo $counter."-".$testvalue.$counter."
"; } // the reflink has not been found yet, so it is OK return $testvalue.$counter; } /** * Check whether this title is already used * @param string title * @return bool False if title is already taken * @author Patrick Cool , Ghent University **/ 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); if ($numberofresults == 0) // the value has not been found and is this available { return true; } else // the value has been found { return false; } } /** * check wikilinks that has a page * @author Juan Carlos Raña **/ function links_to($input) { $input_array = preg_split("/(\[\[|\]\])/", $input, -1, PREG_SPLIT_DELIM_CAPTURE); $all_links = array(); foreach ($input_array as $key => $value) { if ($input_array[$key - 1] == '[[' AND $input_array[$key + 1] == ']]') { if (api_strpos($value, "|") !== false) { $full_link_array = explode("|", $value); $link = trim($full_link_array[0]); $title = trim($full_link_array[1]); } else { $link = trim($value); $title = trim($value); } unset($input_array[$key - 1]); unset($input_array[$key + 1]); $all_links[] = Database::escape_string( str_replace(' ', '_', $link) ).' '; //replace blank spaces by _ within the links. But to remove links at the end add a blank space } } $output = implode($all_links); return $output; } /** * detect and add style to external links * @author Juan Carlos Raña Trabado **/ function detect_external_link($input) { $exlink = 'href='; $exlinkStyle = 'class="wiki_link_ext" href='; $output = str_replace($exlink, $exlinkStyle, $input); return $output; } /** * detect and add style to anchor links * @author Juan Carlos Raña Trabado **/ function detect_anchor_link($input) { $anchorlink = 'href="#'; $anchorlinkStyle = 'class="wiki_anchor_link" href="#'; $output = str_replace($anchorlink, $anchorlinkStyle, $input); return $output; } /** * detect and add style to mail links * author Juan Carlos Raña Trabado **/ function detect_mail_link($input) { $maillink = 'href="mailto'; $maillinkStyle = 'class="wiki_mail_link" href="mailto'; $output = str_replace($maillink, $maillinkStyle, $input); return $output; } /** * detect and add style to ftp links * @author Juan Carlos Raña Trabado **/ function detect_ftp_link($input) { $ftplink = 'href="ftp'; $ftplinkStyle = 'class="wiki_ftp_link" href="ftp'; $output = str_replace($ftplink, $ftplinkStyle, $input); return $output; } /** * detect and add style to news links * @author Juan Carlos Raña Trabado **/ function detect_news_link($input) { $newslink = 'href="news'; $newslinkStyle = 'class="wiki_news_link" href="news'; $output = str_replace($newslink, $newslinkStyle, $input); return $output; } /** * detect and add style to irc links * @author Juan Carlos Raña Trabado **/ function detect_irc_link($input) { $irclink = 'href="irc'; $irclinkStyle = 'class="wiki_irc_link" href="irc'; $output = str_replace($irclink, $irclinkStyle, $input); return $output; } /** * This function allows users to have [link to a title]-style links like in most regular wikis. * It is true that the adding of links is probably the most anoying part of Wiki for the people * who know something about the wiki syntax. * @author Patrick Cool , Ghent University * Improvements [[]] and [[ | ]]by Juan Carlos Raña * Improvements internal wiki style and mark group by Juan Carlos Raña **/ function make_wiki_link_clickable($input) { $_course = api_get_course_info(); 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 $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 { /////////// TODO: metawiki /* if ($session_id==0) { if ($_clean['group_id']==0) { $titleg_ex=''; } else { $group_properties = GroupManager :: get_group_properties($_clean['group_id']); $group_name= $group_properties['name']; $titleg_ex='('.$group_name.')'; } } else { TODO:logic for sessions } */ ///////// //now full wikilink if (api_strpos($value, "|") !== false) { $full_link_array = explode("|", $value); $link = trim(strip_tags($full_link_array[0])); $title = trim($full_link_array[1]); } else { $link = trim(strip_tags($value)); $title = trim($value); } //if wikilink is homepage if ($link == 'index') { $title = get_lang('DefaultTitle'); } if ($link == get_lang('DefaultTitle')) { $link = 'index'; } // note: checkreflink checks if the link is still free. If it is not used then it returns true, if it is used, then it returns false. Now the title may be different if (checktitle(strtolower(str_replace(' ', '_', $link)))) { $link = api_html_entity_decode($link); $input_array[$key] = ''.$title.''; } else { $input_array[$key] = ''.$title.''; } unset($input_array[$key - 1]); unset($input_array[$key + 1]); } } $output = implode('', $input_array); return $output; } /** * This function saves a change in a wiki page * @author Patrick Cool , Ghent University * @return language string saying that the changes are stored **/ function save_wiki() { global $charset, $tbl_wiki, $_course, $tbl_wiki_conf; // NOTE: visibility, visibility_disc and ratinglock_disc changes are not made here, but through the interce buttons // cleaning the variables $_clean['page_id'] = Database::escape_string($_POST['page_id']); $_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') { $purifier = new HTMLPurifier(); $_clean['content'] = $purifier->purify($_clean['content']); } $_clean['user_id'] = api_get_user_id(); $_clean['assignment'] = Database::escape_string($_POST['assignment']); $_clean['comment'] = Database::escape_string($_POST['comment']); $_clean['progress'] = Database::escape_string($_POST['progress']); $_clean['version'] = intval($_POST['version']) + 1; $_clean['linksto'] = links_to($_clean['content']); //and check links content $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']); } //cleaning config variables if (!empty($_POST['task'])) { $_clean['task'] = Database::escape_string($_POST['task']); } if (!empty($_POST['feedback1']) || !empty($_POST['feedback2']) || !empty($_POST['feedback3'])) { $_clean['feedback1'] = Database::escape_string($_POST['feedback1']); $_clean['feedback2'] = Database::escape_string($_POST['feedback2']); $_clean['feedback3'] = Database::escape_string($_POST['feedback3']); $_clean['fprogress1'] = Database::escape_string($_POST['fprogress1']); $_clean['fprogress2'] = Database::escape_string($_POST['fprogress2']); $_clean['fprogress3'] = Database::escape_string($_POST['fprogress3']); } if (Security::remove_XSS($_POST['initstartdate'] == 1)) { $_clean['startdate_assig'] = Database::escape_string(get_date_from_select('startdate_assig')); } else { $_clean['startdate_assig'] = Database::escape_string($_POST['startdate_assig']); } if (Security::remove_XSS($_POST['initenddate'] == 1)) { $_clean['enddate_assig'] = Database::escape_string(get_date_from_select('enddate_assig')); } else { $_clean['enddate_assig'] = Database::escape_string($_POST['enddate_assig']); } $_clean['delayedsubmit'] = Database::escape_string($_POST['delayedsubmit']); if (!empty($_POST['max_text']) || !empty($_POST['max_version'])) { $_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)."')"; $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'] ); } if ($_clean['page_id'] == 0) { $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$Id.'" WHERE c_id = '.$course_id.' AND id="'.$Id.'"'; Database::query($sql); } //update wiki config if ($_clean['reflink'] == 'index' && $_clean['version'] == 1) { $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'].'" 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']); check_emailcue($_clean['reflink'], 'P', $dtime, $_clean['user_id']); return get_lang('ChangesStored'); } /** * This function restore a wikipage * @author Juan Carlos Raña * @return string Message of success (to be printed on screen) **/ function restore_wikipage( $r_page_id, $r_reflink, $r_title, $r_content, $r_group_id, $r_assignment, $r_progress, $c_version, $r_version, $r_linksto ) { global $tbl_wiki, $_course; $r_user_id = api_get_user_id(); $r_dtime = date("Y-m-d H:i:s"); $r_version = $r_version + 1; $r_comment = get_lang('RestoredFromVersion').': '.$c_version; $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 ($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); $Id = Database::insert_id(); api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id(), $r_group_id); check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id); return get_lang('PageRestored'); } /** * This function delete a wiki * @author Juan Carlos Raña * @return string Message of success (to be printed) **/ 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']; $group_id = $row['group_id']; $session_id = $row['session_id']; $page_id = $row['page_id']; Database::query('DELETE FROM '.$tbl_wiki_conf.' WHERE page_id="'.$id.'" AND c_id = '.$course_id); Database::query('DELETE FROM '.$tbl_wiki_discuss.' WHERE publication_id="'.$id.'" AND c_id = '.$course_id); } Database::query( 'DELETE FROM '.$tbl_wiki_mailcue.' WHERE session_id="'.$session_id.'" AND group_id="'.$group_id.'" AND c_id = '.$course_id ); Database::query( 'DELETE FROM '.$tbl_wiki.' WHERE session_id="'.$session_id.'" AND group_id="'.$group_id.'" AND c_id = '.$course_id ); return get_lang('WikiDeleted'); } /** * This function saves a new wiki page. * @author Patrick Cool , Ghent University * @todo consider merging this with the function save_wiki into one single function. * @return string Message of success **/ function save_new_wiki() { global $charset; global $tbl_wiki; global $assig_user_id; //need for assignments mode global $tbl_wiki_conf; global $page; // cleaning the variables $_clean['assignment'] = Database::escape_string($_POST['assignment']); // session_id $session_id = api_get_session_id(); if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) { // Unlike ordinary pages of pages of assignments. Allow create a ordinary page although there is a assignment with the same name $page = str_replace(' ', '_', $_POST['title']."_uass".$assig_user_id); } else { $page = str_replace(' ', '_', $_POST['title']); } $_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 $_clean['visibility'] = 0; $_clean['visibility_disc'] = 0; $_clean['ratinglock_disc'] = 0; } else { $_clean['user_id'] = api_get_user_id(); $_clean['visibility'] = 1; $_clean['visibility_disc'] = 1; $_clean['ratinglock_disc'] = 1; } $_clean['comment'] = Database::escape_string($_POST['comment']); $_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']); } $_clean['linksto'] = links_to($_clean['content']); //check wikilinks //cleaning config variables $_clean['task'] = Database::escape_string($_POST['task']); $_clean['feedback1'] = Database::escape_string($_POST['feedback1']); $_clean['feedback2'] = Database::escape_string($_POST['feedback2']); $_clean['feedback3'] = Database::escape_string($_POST['feedback3']); $_clean['fprogress1'] = Database::escape_string($_POST['fprogress1']); $_clean['fprogress2'] = Database::escape_string($_POST['fprogress2']); $_clean['fprogress3'] = Database::escape_string($_POST['fprogress3']); if ($_POST['initstartdate'] == 1) { $_clean['startdate_assig'] = Database::escape_string(get_date_from_select('startdate_assig')); } else { $_clean['startdate_assig'] = Database::escape_string($_POST['startdate_assig']); } if ($_POST['initenddate'] == 1) { $_clean['enddate_assig'] = Database::escape_string(get_date_from_select('enddate_assig')); } else { $_clean['enddate_assig'] = Database::escape_string($_POST['enddate_assig']); } $_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'); Display::display_warning_message($message, false); } else { $var = $_clean['reflink']; $group_id = Security::remove_XSS($_GET['group_id']); if (!checktitle($var)) { 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)."')"; $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'] ); } $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 ($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); check_emailcue(0, 'A'); return get_lang('NewWikiSaved'); } } //end filter no _uass } /** * This function displays the form for adding a new wiki page. * @author Patrick Cool , Ghent University * @return html code **/ function display_new_wiki_form() { $_course = api_get_course_info(); global $page; ?> '; 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 ? echo' '.Display::return_icon( 'div_show.gif', get_lang('Show'), array('style' => 'vertical-align:middle') ).' '.get_lang('AdvancedParameters').''; echo ''; } echo '
'; echo '
'; api_disp_html_area( 'content', '', '', '', null, api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student') ); echo '
'; echo '
'; echo get_lang('Comments').':  

'; echo get_lang('Progress').':   %'; echo '

'; echo ''; //prevent double post echo ''; //for button icon. Don't change name (see fckeditor/editor/plugins/customizations/fckplugin_compressed.js and fckplugin.js echo '
'; echo ''; } /** * This function displays a wiki entry * @author Patrick Cool , Ghent University * @author Juan Carlos Raña Trabado * @return html code **/ function display_wiki_entry($newtitle) { global $charset, $tbl_wiki, $tbl_wiki_conf, $groupfilter, $condition_session, $page; $course_id = api_get_course_int_id(); if ($newtitle) { $pageMIX = $newtitle; //display the page after it is created } else { $pageMIX = $page; //display current page } $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); if ($_GET['view']) { $_clean['view'] = (int)Database::escape_string($_GET['view']); $filter = ' AND w.id="'.$_clean['view'].'"'; } //first, check page visibility in the first page version $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string( $pageMIX ).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); $KeyVisibility = $row['visibility']; // second, show the last version $sql = 'SELECT * FROM '.$tbl_wiki.' w , '.$tbl_wiki_conf.' wc WHERE wc.c_id = '.$course_id.' AND w.c_id = '.$course_id.' AND wc.page_id = w.page_id AND w.reflink = "'.Database::escape_string($pageMIX).'" AND w.session_id = '.$session_id.' AND w.'.$groupfilter.' '.$filter.' ORDER BY id DESC'; $result = Database::query($sql); $row = Database::fetch_array( $result ); // we do not need a while loop since we are always displaying the last version //update visits if ($row['id']) { $sql = 'UPDATE '.$tbl_wiki.' SET hits=(hits+1) WHERE c_id = '.$course_id.' AND id='.$row['id'].''; Database::query($sql); } // if both are empty and we are displaying the index page then we display the default text. if ($row['content'] == '' AND $row['title'] == '' AND $page == 'index') { if (api_is_allowed_to_edit(false, true) || api_is_platform_admin() || GroupManager :: is_user_in_group( api_get_user_id(), $_SESSION['_gid'] ) ) { //Table structure for better export to pdf $default_table_for_content_Start = '
'; $default_table_for_content_End = '
'; $content = $default_table_for_content_Start.sprintf( get_lang('DefaultContent'), api_get_path(WEB_IMG_PATH) ).$default_table_for_content_End; $title = get_lang('DefaultTitle'); } else { return Display::display_normal_message(get_lang('WikiStandBy')); } } else { $content = Security::remove_XSS($row['content'], COURSEMANAGERLOWSECURITY); $title = $row['title']; } //assignment mode: identify 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('AssignmentWork'), '', ICON_SIZE_SMALL); } //task mode if (!empty($row['task'])) { $icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL); } //Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view if ($KeyVisibility == "1" || api_is_allowed_to_edit(false, true) || api_is_platform_admin( ) || ($row['assignment'] == 2 && $KeyVisibility == "0" && (api_get_user_id() == $row['user_id'])) ) { echo '
'; // page action: protecting (locking) the page if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if (check_protect_page() == 1) { $protect_page = Display::return_icon('lock.png', get_lang('PageLockedExtra'), '', ICON_SIZE_SMALL); $lock_unlock_protect = 'unlock'; } else { $protect_page = Display::return_icon('unlock.png', get_lang('PageUnlockedExtra'), '', ICON_SIZE_SMALL); $lock_unlock_protect = 'lock'; } } if ($row['id']) { echo ''; echo ''.$protect_page.''; echo ''; } //page action: visibility if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if (check_visibility_page() == 1) { // TODO: FIX This hides the icon eye closed to users of work they can see yours //if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false) //{ // // } $visibility_page = Display::return_icon('visible.png', get_lang('ShowPageExtra'), '', ICON_SIZE_SMALL); $lock_unlock_visibility = 'invisible'; } else { $visibility_page = Display::return_icon( 'invisible.png', get_lang('HidePageExtra'), '', ICON_SIZE_SMALL ); $lock_unlock_visibility = 'visible'; } } if ($row['id']) { echo ''; echo ''.$visibility_page.''; echo ''; } //page action: notification if (api_is_allowed_to_session_edit()) { if (check_notify_page($page) == 1) { $notify_page = Display::return_icon( 'messagebox_info.png', get_lang('NotifyByEmail'), '', ICON_SIZE_SMALL ); $lock_unlock_notify_page = 'unlocknotify'; } else { $notify_page = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'), '', ICON_SIZE_SMALL); $lock_unlock_notify_page = 'locknotify'; } } echo ''; echo ''.$notify_page.''; echo ''; //ONly available if row['id'] is set if ($row['id']) { //page action: export to pdf echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '
'; //page action: copy last version to doc area if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { echo ''; echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '
'; } } //export to print ?> '; echo Display::return_icon( 'printer.png', get_lang('Print'), array('onclick' => "javascript: goprint();"), ICON_SIZE_SMALL ); echo ''; if (empty($title)) { $title = get_lang('DefaultTitle'); } if (wiki_exist($title)) { echo $icon_assignment.' '.$icon_task.' '.api_htmlentities($title); } else { echo api_htmlentities($title); } echo '
'; echo '
'.make_wiki_link_clickable( detect_external_link( detect_anchor_link(detect_mail_link(detect_ftp_link(detect_irc_link(detect_news_link($content))))) ) ).'
'; echo '
'.get_lang('Progress').': '.$row['progress'].'%   '.get_lang( 'Rating' ).': '.$row['score'].'   '.get_lang('Words').': '.word_count($content).'
'; } //end filter visibility } // end function display_wiki_entry /** * This function counted the words in a document. Thanks Adeel Khan * @param string Document's text * @return int Number of words */ function word_count($document) { $search = array( '@]*?>.*?@si', '@]*?>.*?@siU', '@
0) { return true; } else { return false; } } /** * This function a wiki warning * @author Patrick Cool , Ghent University * @return html code **/ function display_wiki_warning($variable) { echo '
'.$variable.'
'; } /** * Checks if this navigation tab has to be set to active * @author Patrick Cool , Ghent University * @return html code */ function is_active_navigation_tab($paramwk) { if ($_GET['action'] == $paramwk) { return ' class="active"'; } } /** * Lock add pages * @author Juan Carlos Raña * return current database status of protect page and change it if get action */ function check_addnewpagelock() { global $tbl_wiki; global $groupfilter; global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $course_id = api_get_course_int_id(); $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); $status_addlock = $row['addlock']; //change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['actionpage'] == 'lockaddnew' && $status_addlock == 1) { $status_addlock = 0; } if ($_GET['actionpage'] == 'unlockaddnew' && $status_addlock == 0) { $status_addlock = 1; } Database::query( 'UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string( $status_addlock ).'" WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.'' ); $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); } //show status return $row['addlock']; } /** * Protect page * @author Juan Carlos Raña * return current database status of protect page and change it if get action */ function check_protect_page() { global $tbl_wiki; global $page; global $groupfilter; global $condition_session; $course_id = api_get_course_int_id(); $_clean['group_id'] = (int)$_SESSION['_gid']; $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); $status_editlock = $row['editlock']; $id = $row['id']; ///change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['actionpage'] == 'lock' && $status_editlock == 0) { $status_editlock = 1; } if ($_GET['actionpage'] == 'unlock' && $status_editlock == 1) { $status_editlock = 0; } $sql = 'UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string( $status_editlock ).'" WHERE c_id = '.$course_id.' AND id="'.$id.'"'; Database::query($sql); $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); } //show status return $row['editlock']; } /** * Visibility page * @author Juan Carlos Raña * return current database status of visibility and change it if get action */ function check_visibility_page() { global $tbl_wiki; global $page; global $groupfilter; global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $course_id = api_get_course_int_id(); $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); $status_visibility = $row['visibility']; //change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['actionpage'] == 'visible' && $status_visibility == 0) { $status_visibility = 1; } if ($_GET['actionpage'] == 'invisible' && $status_visibility == 1) { $status_visibility = 0; } $sql = 'UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string( $status_visibility ).'" WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string( $page ).'" AND '.$groupfilter.$condition_session; Database::query($sql); //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page $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); } if (empty($row['id'])) { $row['visibility'] = 1; } //show status return $row['visibility']; } /** * Visibility discussion * @author Juan Carlos Raña * @return int current database status of discuss visibility and change it if get action page */ function check_visibility_discuss() { global $tbl_wiki; global $page; global $groupfilter; global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $course_id = api_get_course_int_id(); $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); $status_visibility_disc = $row['visibility_disc']; //change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['actionpage'] == 'showdisc' && $status_visibility_disc == 0) { $status_visibility_disc = 1; } if ($_GET['actionpage'] == 'hidedisc' && $status_visibility_disc == 1) { $status_visibility_disc = 0; } $sql = 'UPDATE '.$tbl_wiki.' SET visibility_disc="'.Database::escape_string( $status_visibility_disc ).'" WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string( $page ).'" AND '.$groupfilter.$condition_session; Database::query($sql); //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page $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); } //show status return $row['visibility_disc']; } /** * Lock add discussion * @author Juan Carlos Raña * @return int current database status of lock dicuss and change if get action */ function check_addlock_discuss() { global $tbl_wiki; global $page; global $groupfilter; global $condition_session; $course_id = api_get_course_int_id(); $_clean['group_id'] = (int)$_SESSION['_gid']; $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); $status_addlock_disc = $row['addlock_disc']; //change status if (api_is_allowed_to_edit() || api_is_platform_admin()) { if ($_GET['actionpage'] == 'lockdisc' && $status_addlock_disc == 0) { $status_addlock_disc = 1; } if ($_GET['actionpage'] == 'unlockdisc' && $status_addlock_disc == 1) { $status_addlock_disc = 0; } $sql = 'UPDATE '.$tbl_wiki.' SET addlock_disc="'.Database::escape_string($status_addlock_disc).'" WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string( $page ).'" AND '.$groupfilter.$condition_session; Database::query($sql); //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page $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); } //show status return $row['addlock_disc']; } /** * Lock rating discussion * @author Juan Carlos Raña * @return int current database status of rating discuss and change it if get action */ function check_ratinglock_discuss() { global $tbl_wiki; global $page; global $groupfilter; global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $course_id = api_get_course_int_id(); $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); $status_ratinglock_disc = $row['ratinglock_disc']; //change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($_GET['actionpage'] == 'lockrating' && $status_ratinglock_disc == 0) { $status_ratinglock_disc = 1; } if ($_GET['actionpage'] == 'unlockrating' && $status_ratinglock_disc == 1) { $status_ratinglock_disc = 0; } $sql = 'UPDATE '.$tbl_wiki.' SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'" WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string( $page ).'" AND '.$groupfilter.$condition_session; //Visibility. Value to all,not only for the first Database::query($sql); //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page $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); } //show status return $row['ratinglock_disc']; } /** * Notify page changes * @author Juan Carlos Raña * @return int the current notification status */ function check_notify_page($reflink) { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); $id = $row['id']; $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id( ).'" AND type="P"'; $result = Database::query($sql); $row = Database::fetch_array($result); $idm = $row['id']; if (empty($idm)) { $status_notify = 0; } else { $status_notify = 1; } //change status if ($_GET['actionpage'] == 'locknotify' && $status_notify == 0) { $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES ($course_id, '".$id."','".api_get_user_id()."','P','".$_clean['group_id']."','".$session_id."')"; Database::query($sql); $status_notify = 1; } if ($_GET['actionpage'] == 'unlocknotify' && $status_notify == 1) { $sql = 'DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id( ).'" AND type="P" AND c_id = '.$course_id; //$_clean['group_id'] not necessary. CHECK FOR SESSIONS Database::query($sql); $status_notify = 0; } //show status return $status_notify; } /** * Notify discussion changes * @author Juan Carlos Raña * @return int current database status of rating discuss and change it if get action */ function check_notify_discuss($reflink) { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; global $condition_session; $course_id = api_get_course_int_id(); $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); $sql = 'SELECT * FROM '.$tbl_wiki.'WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); $id = $row['id']; $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id( ).'" AND type="D"'; $result = Database::query($sql); $row = Database::fetch_array($result); $idm = $row['id']; if (empty($idm)) { $status_notify_disc = 0; } else { $status_notify_disc = 1; } //change status if ($_GET['actionpage'] == 'locknotifydisc' && $status_notify_disc == 0) { $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES ($course_id, '".$id."','".api_get_user_id()."','D','".$_clean['group_id']."','".$session_id."')"; Database::query($sql); $status_notify_disc = 1; } if ($_GET['actionpage'] == 'unlocknotifydisc' && $status_notify_disc == 1) { $sql = 'DELETE FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND id="'.$id.'" AND user_id="'.api_get_user_id( ).'" AND type="D" AND c_id = '.$course_id; //$_clean['group_id'] not necessary TODO:CHECK FOR SESSIONS Database::query($sql); $status_notify_disc = 0; } //show status return $status_notify_disc; } /** * Notify all changes * @author Juan Carlos Raña */ function check_notify_all() { global $tbl_wiki_mailcue; $course_id = api_get_course_int_id(); $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND user_id="'.api_get_user_id( ).'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; $result = Database::query($sql); $row = Database::fetch_array($result); $idm = $row['user_id']; if (empty($idm)) { $status_notify_all = 0; } else { $status_notify_all = 1; } //change status if ($_GET['actionpage'] == 'locknotifyall' && $status_notify_all == 0) { $sql = "INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES ($course_id, '".api_get_user_id()."','F','".$_clean['group_id']."','".$session_id."')"; Database::query($sql); $status_notify_all = 1; } if ($_GET['actionpage'] == 'unlocknotifyall' && $status_notify_all == 1) { $sql = 'DELETE FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND user_id="'.api_get_user_id( ).'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'" AND c_id = '.$course_id; Database::query($sql); $status_notify_all = 0; } //show status return $status_notify_all; } /** * Sends pending e-mails */ function check_emailcue($id_or_ref, $type, $lastime = '', $lastuser = '') { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; $_course = api_get_course_info(); global $condition_session; $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $group_properties = GroupManager :: get_group_properties($_clean['group_id']); $group_name = $group_properties['name']; $allow_send_mail = false; //define the variable to below if ($type == 'P') { //if modifying a wiki page //first, current author and time //Who is the author? $userinfo = api_get_user_info($lastuser); $email_user_author = get_lang('EditedBy').': '.$userinfo['complete_name']; //When ? $year = substr($lastime, 0, 4); $month = substr($lastime, 5, 2); $day = substr($lastime, 8, 2); $hours = substr($lastime, 11, 2); $minutes = substr($lastime, 14, 2); $seconds = substr($lastime, 17, 2); $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds; //second, extract data from first reg $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.$id_or_ref.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; //id_or_ref is reflink from tblwiki $result = Database::query($sql); $row = Database::fetch_array($result); $id = $row['id']; $email_page_name = $row['title']; if ($row['visibility'] == 1) { $allow_send_mail = true; //if visibility off - notify off $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full. $result = Database::query($sql); $emailtext = get_lang('EmailWikipageModified').' '.$email_page_name.' '.get_lang('Wiki'); } } elseif ($type == 'D') { //if added a post to discuss //first, current author and time //Who is the author of last message? $userinfo = api_get_user_info($lastuser); $email_user_author = get_lang('AddedBy').': '.$userinfo['complete_name']; //When ? $year = substr($lastime, 0, 4); $month = substr($lastime, 5, 2); $day = substr($lastime, 8, 2); $hours = substr($lastime, 11, 2); $minutes = substr($lastime, 14, 2); $seconds = substr($lastime, 17, 2); $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds; //second, extract data from first reg $id = $id_or_ref; //$id_or_ref is id from tblwiki $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND id="'.$id.'" ORDER BY id ASC'; $result = Database::query($sql); $row = Database::fetch_array($result); $email_page_name = $row['title']; if ($row['visibility_disc'] == 1) { $allow_send_mail = true; //if visibility off - notify off $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'WHERE c_id = '.$course_id.' AND id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full $result = Database::query($sql); $emailtext = get_lang('EmailWikiPageDiscAdded').' '.$email_page_name.' '.get_lang('Wiki'); } } elseif ($type == 'A') { //for added pages $id = 0; //for tbl_wiki_mailcue $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' ORDER BY id DESC'; //the added is always the last $result = Database::query($sql); $row = Database::fetch_array($result); $email_page_name = $row['title']; //Who is the author? $userinfo = api_get_person_name($row['user_id']); $email_user_author = get_lang('AddedBy').': '.$userinfo['complete_name']; //When ? $year = substr($row['dtime'], 0, 4); $month = substr($row['dtime'], 5, 2); $day = substr($row['dtime'], 8, 2); $hours = substr($row['dtime'], 11, 2); $minutes = substr($row['dtime'], 14, 2); $seconds = substr($row['dtime'], 17, 2); $email_date_changes = $day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds; if ($row['assignment'] == 0) { $allow_send_mail = true; } elseif ($row['assignment'] == 1) { $email_assignment = get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')'; $allow_send_mail = true; } elseif ($row['assignment'] == 2) { $allow_send_mail = false; //Mode tasks: avoids notifications to all users about all users } $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$course_id.' AND id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full $result = Database::query($sql); $emailtext = get_lang('EmailWikiPageAdded').' '.$email_page_name.' '.get_lang( 'In' ).' '.get_lang('Wiki'); } elseif ($type == 'E') { $id = 0; $allow_send_mail = true; //Who is the author? $userinfo = api_get_user_info(api_get_user_id()); //current user $email_user_author = get_lang('DeletedBy').': '.$userinfo['complete_name']; //When ? $today = date('r'); //current time $email_date_changes = $today; $sql = 'SELECT * FROM '.$tbl_wiki_mailcue.'WHERE c_id = '.$course_id.' AND id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=wiki $result = Database::query($sql); $emailtext = get_lang('EmailWikipageDedeleted'); } ///make and send email if ($allow_send_mail) { while ($row = Database::fetch_array($result)) { $userinfo = api_get_user_info($row['user_id']); //$row['user_id'] obtained from tbl_wiki_mailcue $name_to = api_get_person_name( $userinfo['firstname'], $userinfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS ); $email_to = $userinfo['email']; $sender_name = api_get_setting('emailAdministrator'); $sender_email = api_get_setting('emailAdministrator'); $email_subject = get_lang('EmailWikiChanges').' - '.$_course['official_code']; $email_body = get_lang('DearUser').' '.api_get_person_name( $userinfo['firstname'], $userinfo['lastname'] ).',

'; if ($session_id == 0) { $email_body .= $emailtext.' '.$_course['name'].' - '.$group_name.'


'; } else { $email_body .= $emailtext.' '.$_course['name'].' ('.api_get_session_name( api_get_session_id() ).') - '.$group_name.'


'; } $email_body .= $email_user_author.' ('.$email_date_changes.')


'; $email_body .= $email_assignment.'


'; $email_body .= ''.get_lang('EmailWikiChangesExt_1').': '.get_lang( 'NotifyChanges' ).'
'; $email_body .= get_lang('EmailWikiChangesExt_2').': '.get_lang( 'NotNotifyChanges' ).'

'; @api_mail_html($name_to, $email_to, $email_subject, $email_body, $sender_name, $sender_email); } } } /** * Function export last wiki page version to document area * @author Juan Carlos Raña */ function export2doc($doc_id) { $_course = api_get_course_info(); $groupId = api_get_group_id(); $session_id = api_get_session_id(); $data = get_wiki_data($doc_id); if (empty($data)) { return false; } $wikiTitle = $data['title']; $wikiContents = $data['content']; $template = ' {TITLE} {ASCIIMATHML_SCRIPT} {CONTENT} '; $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/default.css'; if (file_exists($css_file)) { $css = @file_get_contents($css_file); } else { $css = ''; } // Fixing some bugs in css files. $root_rel = api_get_path(REL_PATH); $css_path = 'main/css/'; $theme = api_get_setting('stylesheets').'/'; $css = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css); $css = str_replace('main/', $root_rel.'main/', $css); $css = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css); $css = str_replace('../../img/', $root_rel.'main/img/', $css); $asciimathmal_script = (Text::api_contains_asciimathml($wikiContents) || Text::api_contains_asciisvg($wikiContents)) ? ''."\n" : ''; $template = str_replace( array( '{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}' ), array( api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script ), $template ); if (0 != $groupId) { $groupPart = '_group'.$groupId; // and add groupId to put the same document title in different groups $group_properties = GroupManager :: get_group_properties($groupId); $groupPath = $group_properties['directory']; } else { $groupPart = ''; $groupPath = ''; } $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/document'.$groupPath; $exportFile = api_replace_dangerous_char($wikiTitle, 'strict').$groupPart; //$clean_wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents)); //$array_clean_wikiContents= explode('|', $clean_wikiContents); $wikiContents = trim(preg_replace("/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/", "$1", $wikiContents)); //TODO: put link instead of title $wikiContents = str_replace('{CONTENT}', $wikiContents, $template); // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents if (api_strpos($wikiContents, '../../courses/') !== false) { $web_course_path = api_get_path(WEB_COURSE_PATH); $wikiContents = str_replace('../../courses/', $web_course_path, $wikiContents); } $doc_id = 0; $i = 1; while (file_exists( $exportDir.'/'.$exportFile.'_'.$i.'.html' )) { $i++; } //only export last version, but in new export new version in document area $wikiFileName = $exportFile.'_'.$i.'.html'; $exportPath = $exportDir.'/'.$wikiFileName; file_put_contents($exportPath, $wikiContents); $doc_id = FileManager::add_document( $_course, $groupPath.'/'.$wikiFileName, 'file', filesize($exportPath), $wikiTitle ); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId); return $doc_id; // TODO: link to go document area } /** * Exports the wiki page to PDF */ function export_to_pdf($id, $course_code) { $data = get_wiki_data($id); $content_pdf = api_html_entity_decode($data['content'], ENT_QUOTES, api_get_system_encoding()); //clean wiki links $content_pdf = trim(preg_replace("/\[[\[]?([^\]|]*)[|]?([^|\]]*)\][\]]?/", "$1", $content_pdf)); //TODO: It should be better to display the link insted of the tile but it is hard for [[title]] links $title_pdf = api_html_entity_decode($data['title'], ENT_QUOTES, api_get_system_encoding()); $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding()); $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding()); $html = ' '.$content_pdf; $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css'; if (file_exists($css_file)) { $css = @file_get_contents($css_file); } else { $css = ''; } $pdf = new PDF(); $pdf->content_to_pdf($html, $css, $title_pdf, $course_code); exit; } /** * Function prevent double post (reload or F5) * */ function double_post($wpost_id) { if (isset($_SESSION['wpost_id'])) { if ($wpost_id == $_SESSION['wpost_id']) { return false; } else { $_SESSION['wpost_id'] = $wpost_id; return true; } } else { $_SESSION['wpost_id'] = $wpost_id; return true; } } /** * Function wizard individual assignment * @author Juan Carlos Raña */ function auto_add_page_users($assignment_type) { global $assig_user_id, $session_id; //$assig_user_id is need to identify end reflinks $_clean['group_id'] = (int)$_SESSION['_gid']; if ($_clean['group_id'] == 0) { //extract course members if (!empty($session_id)) { $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], $session_id); } else { $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0); } } else { //extract group members $subscribed_users = GroupManager :: get_subscribed_users($_clean['group_id']); $subscribed_tutors = GroupManager :: get_subscribed_tutors($_clean['group_id']); $a_users_to_add_with_duplicates = array_merge($subscribed_users, $subscribed_tutors); //remove duplicates $a_users_to_add = $a_users_to_add_with_duplicates; //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_encode($value);')); $a_users_to_add = array_unique($a_users_to_add); //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_decode($value, true);')); } //echo print_r($a_users_to_add); $all_students_pages = array(); //data about teacher $userinfo = api_get_user_info(api_get_user_id()); $name = $userinfo['complete_name_login_as']; if (api_get_user_id() <> 0) { $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $photo = ''.$name.''; } else { $photo = ''.$name.''; } //teacher assignment title $title_orig = $_POST['title']; //teacher assignment reflink $link2teacher = $_POST['title'] = $title_orig."_uass".api_get_user_id(); //first: teacher name, photo, and assignment description (original content) // $content_orig_A='
'.$photo.'
'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'
('.get_lang('Teacher').')

'; $content_orig_A = '
'.get_lang( 'AssignmentDesc' ).'
'.$photo.'
'.Display::tag('span', $name).'
'; $content_orig_B = '
'.get_lang( 'AssignmentDescription' ).': '.$title_orig.'

'.$_POST['content']; //Second: student list (names, photo and links to their works). //Third: Create Students work pages. foreach ($a_users_to_add as $user_id => $o_user_to_add) { if ($o_user_to_add['user_id'] != api_get_user_id()) //except that puts the task { $assig_user_id = $o_user_to_add['user_id']; //identifies each page as created by the student, not by teacher $image_path = UserManager::get_user_picture_path_by_id($assig_user_id, 'web', false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $username = api_htmlentities(sprintf(get_lang('LoginX'), $o_user_to_add['username'], ENT_QUOTES)); $name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname'])." . ".$username; $photo = ''.$name.''; $is_tutor_of_group = GroupManager :: is_tutor_of_group( $assig_user_id, $_clean['group_id'] ); //student is tutor $is_tutor_and_member = (GroupManager :: is_tutor_of_group( $assig_user_id, $_clean['group_id'] ) && GroupManager :: is_subscribed($assig_user_id, $_clean['group_id'])); //student is tutor and member if ($is_tutor_and_member) { $status_in_group = get_lang('GroupTutorAndMember'); } else { if ($is_tutor_of_group) { $status_in_group = get_lang('GroupTutor'); } else { $status_in_group = " "; //get_lang('GroupStandardMember') } } if ($assignment_type == 1) { $_POST['title'] = $title_orig; $_POST['comment'] = get_lang('AssignmentFirstComToStudent'); $_POST['content'] = '
'.get_lang( 'AssignmentWork' ).'
'.$photo.'
'.$name.'
[['.$link2teacher.' | '.get_lang( 'AssignmentLinktoTeacherPage' ).']] '; //If $content_orig_B is added here, the task written by the professor was copied to the page of each student. TODO: config options //AssignmentLinktoTeacherPage $all_students_pages[] = '
  • '. Display::tag( 'span', strtoupper($o_user_to_add['lastname']).', '.$o_user_to_add['firstname'], array('title' => $username) ). ' [['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'
  • '; //don't change this line without guaranteeing that users will be ordered by last names in the following format (surname, name) //$all_students_pages[] = '
  • '.api_get_person_name($o_user_to_add['lastname'], $o_user_to_add['firstname']).'[['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'
  • '; $_POST['assignment'] = 2; } save_new_wiki(); } } //end foreach for each user foreach ($a_users_to_add as $user_id => $o_user_to_add) { if ($o_user_to_add['user_id'] == api_get_user_id()) { $assig_user_id = $o_user_to_add['user_id']; if ($assignment_type == 1) { $_POST['title'] = $title_orig; $_POST['comment'] = get_lang('AssignmentDesc'); sort($all_students_pages); $_POST['content'] = $content_orig_A.$content_orig_B.'
    '.get_lang( 'AssignmentLinkstoStudentsPage' ).'

      '.implode( $all_students_pages ).'

    '; $_POST['assignment'] = 1; } save_new_wiki(); } } //end foreach to teacher } /** * Displays the results of a wiki search * @param string Search term * @param int Whether to search the contents (1) or just the titles (0) */ function display_wiki_search_results($search_term, $search_content = 0, $all_vers = 0) { global $tbl_wiki, $groupfilter, $MonthsLong, $condition_session; echo ''.get_lang('WikiSearchResults').''; $_clean['group_id'] = (int)$_SESSION['_gid']; $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); //only by professors when page is hidden if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if ($all_vers == '1') { if ($search_content == '1') { $sql = "SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND title LIKE '%".Database::escape_string( $search_term )."%' OR content LIKE '%".Database::escape_string( $search_term )."%' AND ".$groupfilter.$condition_session.""; //search all pages and all versions } else { $sql = "SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND title LIKE '%".Database::escape_string( $search_term )."%' AND ".$groupfilter.$condition_session.""; //search all pages and all versions } } else { if ($search_content == '1') { $sql = "SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND title LIKE '%".Database::escape_string( $search_term )."%' OR content LIKE '%".Database::escape_string($search_term)."%' 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.")"; // warning don't use group by reflink because don't return the last version } else { $sql = " SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND title LIKE '%".Database::escape_string($search_term)."%' 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.")"; // warning don't use group by reflink because don't return the last version } } } else { if ($all_vers == '1') { if ($search_content == '1') { $sql = "SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string( $search_term )."%' OR content LIKE '%".Database::escape_string( $search_term )."%' AND ".$groupfilter.$condition_session.""; //search all pages and all versions } else { $sql = "SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string( $search_term )."%' AND ".$groupfilter.$condition_session.""; //search all pages and all versions } } else { if ($search_content == '1') { $sql = " SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string( $search_term )."%' OR content LIKE '%".Database::escape_string($search_term)."%' 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.")"; // warning don't use group by reflink because don't return the last version } else { $sql = " SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string( $search_term )."%' 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.")"; // warning don't use group by reflink because don't return the last version } } } $result = Database::query($sql); //show table if (Database::num_rows($result) > 0) { $row = array(); while ($obj = Database::fetch_object($result)) { //get author $userinfo = api_get_user_info($obj->user_id); //get time $year = substr($obj->dtime, 0, 4); $month = substr($obj->dtime, 5, 2); $day = substr($obj->dtime, 8, 2); $hours = substr($obj->dtime, 11, 2); $minutes = substr($obj->dtime, 14, 2); $seconds = substr($obj->dtime, 17, 2); //get type assignment icon if ($obj->assignment == 1) { $ShowAssignment = 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 = ''; } $row = array(); $row[] = $ShowAssignment; if ($all_vers == '1') { $row[] = ''.api_htmlentities($obj->title).''; } else { $row[] = ''.$obj->title.''; } $row[] = $obj->user_id <> 0 ? ''.api_htmlentities($userinfo['complete_name']).'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; if ($all_vers == '1') { $row[] = $obj->version; } else { if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { $showdelete = ' '.Display::return_icon( 'delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL ); } $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, 'SearchPages_table', '', '', 'ASC'); $table->set_additional_parameters( array( 'cidReq' => $_GET['cidReq'], 'action' => $_GET['action'], 'group_id' => Security::remove_XSS($_GET['group_id']), 'mode_table' => 'yes2', 'search_term' => $search_term, 'search_content' => $search_content, 'all_vers' => $all_vers ) ); $table->set_header(0, get_lang('Type'), true, array('style' => 'width:30px;')); $table->set_header(1, get_lang('Title'), true); if ($all_vers == '1') { $table->set_header(2, get_lang('Author'), true); $table->set_header(3, get_lang('Date'), true); $table->set_header(4, get_lang('Version'), true); } else { $table->set_header(2, get_lang('Author').' ('.get_lang('LastVersion').')', true); $table->set_header(3, get_lang('Date').' ('.get_lang('LastVersion').')', true); $table->set_header(4, get_lang('Actions'), false, array('style' => 'width:130px;')); } $table->display(); } else { echo get_lang('NoSearchResults'); } } /** * Returns a date picker * @todo replace this function with the formvalidator datepicker * */ function draw_date_picker($prefix, $default = '') { if (empty($default)) { $default = date('Y-m-d H:i:s'); } $parts = split(' ', $default); list($d_year, $d_month, $d_day) = split('-', $parts[0]); list($d_hour, $d_minute) = split(':', $parts[1]); $month_list = array( 1 => get_lang('JanuaryLong'), 2 => get_lang('FebruaryLong'), 3 => get_lang('MarchLong'), 4 => get_lang('AprilLong'), 5 => get_lang('MayLong'), 6 => get_lang('JuneLong'), 7 => get_lang('JulyLong'), 8 => get_lang('AugustLong'), 9 => get_lang('SeptemberLong'), 10 => get_lang('OctoberLong'), 11 => get_lang('NovemberLong'), 12 => get_lang('DecemberLong') ); $minute = range(10, 59); array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09'); $date_form = make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day); $date_form .= make_select($prefix.'_month', $month_list, $d_month); $date_form .= make_select( $prefix.'_year', array( $d_year - 2 => $d_year - 2, $d_year - 1 => $d_year - 1, $d_year => $d_year, $d_year + 1 => $d_year + 1, $d_year + 2 => $d_year + 2 ), $d_year ).'    '; $date_form .= make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : '; $date_form .= make_select($prefix.'_minute', $minute, $d_minute); return $date_form; } /** * Draws an HTML form select with the given options * */ function make_select($name, $values, $checked = '') { $output = ''; return $output; } /** * Translates a form date into a more usable format * */ function get_date_from_select($prefix) { return $_POST[$prefix.'_year'].'-'.two_digits($_POST[$prefix.'_month']).'-'.two_digits( $_POST[$prefix.'_day'] ).' '.two_digits($_POST[$prefix.'_hour']).':'.two_digits($_POST[$prefix.'_minute']).':00'; } /** * Converts 1-9 to 01-09 */ function two_digits($number) { $number = (int)$number; return ($number < 10) ? '0'.$number : $number; } /** * Get wiki information * @param int wiki id * @return array wiki data */ function get_wiki_data($id) { global $tbl_wiki; $course_id = api_get_course_int_id(); $id = intval($id); $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND id = '.$id.' '; $result = Database::query($sql); $data = array(); while ($row = Database::fetch_array($result, 'ASSOC')) { $data = $row; } return $data; }