* @author Patrick Cool , Ghent University, Belgium * @author Julio Montoya using the pdf.lib.php library * * @package chamilo.wiki */ class Wiki { public $tbl_wiki; public $tbl_wiki_discuss; public $tbl_wiki_mailcue; public $tbl_wiki_conf; public $session_id = null; public $course_id = null; public $condition_session = null; public $group_id; public $assig_user_id; public $groupfilter = 'group_id=0'; public $courseInfo; public $charset; public $page; public $action; public $wikiData = array(); public $url; /** * Constructor */ public function __construct() { // Database table definition $this->tbl_wiki = Database::get_course_table(TABLE_WIKI); $this->tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS); $this->tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE); $this->tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF); $this->session_id = api_get_session_id(); $this->condition_session = api_get_session_condition($this->session_id); $this->course_id = api_get_course_int_id(); $this->group_id = api_get_group_id(); if (!empty($this->group_id)) { $this->groupfilter = ' group_id="'.$this->group_id.'"'; } $this->courseInfo = api_get_course_info(); $this->url = api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq(); } /** * Check whether this title is already used * @param string $link * * * @return bool False if title is already taken * @author Patrick Cool , Ghent University **/ public function checktitle($link) { $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $course_id = $this->course_id; $groupfilter = $this->groupfilter; $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($link).'" AND '.$groupfilter.$condition_session.''; $result = Database::query($sql); $numberofresults = Database::num_rows($result); // the value has not been found and is this available if ($numberofresults == 0) { return true; } else { // the value has been found return false; } } /** * check wikilinks that has a page * @author Juan Carlos Raña * @param string $input * * @return string **/ public function links_to($input) { $input_array = preg_split("/(\[\[|\]\])/", $input, -1, PREG_SPLIT_DELIM_CAPTURE); $all_links = array(); foreach ($input_array as $key => $value) { if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' && isset($input_array[$key + 1]) && $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]); //replace blank spaces by _ within the links. But to remove links at the end add a blank space $all_links[] = Database::escape_string(str_replace(' ', '_', $link)).' '; } } $output = implode($all_links); return $output; } /** * detect and add style to external links * @author Juan Carlos Raña Trabado **/ public 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 **/ public 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 **/ public 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 **/ public 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 **/ public 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 **/ public 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 **/ public function make_wiki_link_clickable($input) { $groupId = api_get_group_id(); //now doubles brackets $input_array = preg_split("/(\[\[|\]\])/", $input, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($input_array as $key => $value) { //now doubles brackets if (isset($input_array[$key - 1]) && $input_array[$key - 1] == '[[' && $input_array[$key + 1] == ']]' ) { // 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 (self::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 * @param array $values * @return language string saying that the changes are stored **/ public function save_wiki($values) { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_conf = $this->tbl_wiki_conf; $_course = $this->courseInfo; $time = api_get_utc_datetime(); $session_id = api_get_session_id(); $groupId = api_get_group_id(); $userId = api_get_user_id(); $groupInfo = GroupManager::get_group_properties($groupId); $course_id = api_get_course_int_id(); $_clean = array( 'task' => '', 'feedback1' => '', 'feedback2' => '', 'feedback3' => '', 'fprogress1' => '', 'fprogress2' => '', 'fprogress3' => '', 'max_text' => 0, 'max_version' => 0, 'delayedsubmit' => '', 'assignment' => 0 ); $pageId = intval($values['page_id']); // NOTE: visibility, visibility_disc and ratinglock_disc changes // are not made here, but through the interce buttons // cleaning the variables if (api_get_setting('htmlpurifier_wiki') == 'true') { //$purifier = new HTMLPurifier(); $values['content'] = Security::remove_XSS($values['content']); } $version = intval($values['version']) + 1; $linkTo = self::links_to($values['content']); //and check links content //cleaning config variables if (!empty($values['task'])) { $_clean['task'] = $values['task']; } if (!empty($values['feedback1']) || !empty($values['feedback2']) || !empty($values['feedback3'])) { $_clean['feedback1'] = $values['feedback1']; $_clean['feedback2'] = $values['feedback2']; $_clean['feedback3'] = $values['feedback3']; $_clean['fprogress1'] = $values['fprogress1']; $_clean['fprogress2'] = $values['fprogress2']; $_clean['fprogress3'] = $values['fprogress3']; } if (isset($values['initstartdate']) && $values['initstartdate'] == 1) { $_clean['startdate_assig'] = $values['startdate_assig']; } else { $_clean['startdate_assig'] = null; } if (isset($values['initenddate']) && $values['initenddate'] == 1) { $_clean['enddate_assig'] = $values['enddate_assig']; } else { $_clean['enddate_assig'] = null; } if (isset($values['delayedsubmit'])) { $_clean['delayedsubmit'] = $values['delayedsubmit']; } if (!empty($values['max_text']) || !empty($values['max_version'])) { $_clean['max_text'] = $values['max_text']; $_clean['max_version'] = $values['max_version']; } $values['assignment'] = isset($values['assignment']) ? $values['assignment'] : 0; $values['page_id'] = isset($values['page_id']) ? $values['page_id'] : 0; $params = [ 'c_id' => $course_id, 'addlock' => 1, 'visibility' => 1, 'visibility_disc' => 1, 'addlock_disc' => 1, 'ratinglock_disc' => 1, 'page_id' => $pageId, 'reflink' => trim($values['reflink']), 'title' => trim($values['title']), 'content' => $values['content'], 'user_id' => $userId, 'group_id' => $groupId, 'dtime' => $time, 'assignment' => $values['assignment'], 'comment' => $values['comment'], 'progress' => $values['progress'], 'version' => $version, 'linksto' => $linkTo, 'user_ip' => $_SERVER['REMOTE_ADDR'], 'session_id' => $session_id, 'page_id' => $values['page_id'], 'editlock' => 0, 'is_editing' => 0, 'time_edit' => $time, 'tag' => '' ]; $id = Database::insert($tbl_wiki, $params); if ($id > 0) { $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id"; Database::query($sql); // insert into item_property api_item_property_update( $_course, TOOL_WIKI, $id, 'WikiAdded', $userId, $groupInfo ); if ($values['page_id'] == 0) { $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'" WHERE c_id = '.$course_id.' AND iid ="'.$id.'"'; Database::query($sql); } } // Update wiki config if ($values['reflink'] == 'index' && $version == 1) { $params = [ 'c_id' => $course_id, 'page_id' => $id, 'task' => $_clean['task'], 'feedback1' => $_clean['feedback1'], 'feedback2' => $_clean['feedback2'], 'feedback3' => $_clean['feedback3'], 'fprogress1' => $_clean['fprogress1'], 'fprogress2' => $_clean['fprogress2'], 'fprogress3' => $_clean['fprogress3'], 'max_text' => intval($_clean['max_text']), 'max_version' => intval($_clean['max_version']), 'startdate_assig' => $_clean['startdate_assig'], 'enddate_assig' => $_clean['enddate_assig'], 'delayedsubmit' => $_clean['delayedsubmit'] ]; Database::insert($tbl_wiki_conf, $params); } else { $params = [ 'task' => $_clean['task'], 'feedback1' => $_clean['feedback1'], 'feedback2' => $_clean['feedback2'], 'feedback3' => $_clean['feedback3'], 'fprogress1' => $_clean['fprogress1'], 'fprogress2' => $_clean['fprogress2'], 'fprogress3' => $_clean['fprogress3'], 'max_text' => intval($_clean['max_text']), 'max_version' => intval($_clean['max_version']), 'startdate_assig' => $_clean['startdate_assig'], 'enddate_assig' => $_clean['enddate_assig'], 'delayedsubmit' => $_clean['delayedsubmit'] ]; Database::update( $tbl_wiki_conf, $params, ['page_id = ? AND c_id = ?' => [$pageId, $course_id]] ); } api_item_property_update( $_course, 'wiki', $id, 'WikiAdded', $userId, $groupInfo ); self::check_emailcue($_clean['reflink'], 'P', $time, $userId); $this->setWikiData($id); return get_lang('Saved'); } /** * This function restore a wikipage * @author Juan Carlos Raña * @return string Message of success (to be printed on screen) **/ public 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 ) { $tbl_wiki = $this->tbl_wiki; $_course = $this->courseInfo; $r_user_id = api_get_user_id(); $r_dtime = api_get_utc_datetime(); $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(); $groupInfo = GroupManager::get_group_properties($r_group_id); $params = [ 'c_id' => $course_id, 'page_id' => $r_page_id, 'reflink' => $r_reflink, 'title' => $r_title, 'content' => $r_content, 'user_id' => $r_user_id, 'group_id' => $r_group_id, 'dtime' => $r_dtime, 'assignment' => $r_assignment, 'comment' => $r_comment, 'progress' => $r_progress, 'version' => $r_version, 'linksto' => $r_linksto, 'user_ip' => $_SERVER['REMOTE_ADDR'], 'session_id' => $session_id, ]; $id = Database::insert($tbl_wiki, $params); if ($id) { $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id"; Database::query($sql); api_item_property_update( $_course, 'wiki', $id, 'WikiAdded', api_get_user_id(), $groupInfo ); self::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) **/ public function delete_wiki() { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_discuss = $this->tbl_wiki_discuss; $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $tbl_wiki_conf = $this->tbl_wiki_conf; $conditionSession = $this->condition_session; $groupFilter = $this->groupfilter; $course_id = $this->course_id; $sql = "SELECT page_id FROM $tbl_wiki WHERE c_id = $course_id AND $groupFilter $conditionSession ORDER BY id DESC"; $result = Database::query($sql); $pageList = Database::store_result($result); if ($pageList) { foreach ($pageList as $pageData) { $pageId = $pageData['page_id']; $sql = "DELETE FROM $tbl_wiki_conf WHERE c_id = $course_id AND page_id = $pageId"; Database::query($sql); $sql = "DELETE FROM $tbl_wiki_discuss WHERE c_id = $course_id AND publication_id = $pageId"; Database::query($sql); } } $sql = "DELETE FROM $tbl_wiki_mailcue WHERE c_id = $course_id AND $groupFilter $conditionSession "; Database::query($sql); $sql = "DELETE FROM $tbl_wiki WHERE c_id = $course_id AND $groupFilter $conditionSession "; Database::query($sql); 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 **/ public function save_new_wiki($values) { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_conf = $this->tbl_wiki_conf; $assig_user_id = $this->assig_user_id; $_clean = array(); // cleaning the variables $_clean['assignment'] = ''; if (isset($values['assignment'])) { $_clean['assignment'] = $values['assignment']; } // session_id $session_id = api_get_session_id(); // Unlike ordinary pages of pages of assignments. // Allow create a ordinary page although there is a assignment with the same name if ($_clean['assignment'] == 2 || $_clean['assignment'] == 1) { $page = str_replace(' ', '_', $values['title']."_uass".$assig_user_id); } else { $page = str_replace(' ', '_', $values['title']); } $_clean['reflink'] = $page; $_clean['title'] = trim($values['title']); $_clean['content'] = $values['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) //Identifies the user as a creator, not the teacher who created $_clean['user_id'] = intval($assig_user_id); $_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'] = $values['comment']; $_clean['progress'] = $values['progress']; $_clean['version'] = 1; $groupId = api_get_group_id(); $groupInfo = GroupManager::get_group_properties($groupId); //check wikilinks $_clean['linksto'] = self::links_to($_clean['content']); // cleaning config variables $_clean['task'] = isset($values['task']) ? $values['task'] : ''; $_clean['feedback1'] = isset($values['feedback1']) ? $values['feedback1'] : ''; $_clean['feedback2'] = isset($values['feedback2']) ? $values['feedback2'] : ''; $_clean['feedback3'] = isset($values['feedback3']) ? $values['feedback3'] : ''; $_clean['fprogress1'] = isset($values['fprogress1']) ? $values['fprogress1'] : ''; $_clean['fprogress2'] = isset($values['fprogress2']) ? $values['fprogress2'] : ''; $_clean['fprogress3'] = isset($values['fprogress3']) ? $values['fprogress3'] : ''; if (isset($values['initstartdate']) && $values['initstartdate'] == 1) { $_clean['startdate_assig'] = $values['startdate_assig']; } else { $_clean['startdate_assig'] = null; } if (isset($values['initenddate']) && $values['initenddate'] == 1) { $_clean['enddate_assig'] = $values['enddate_assig']; } else { $_clean['enddate_assig'] = null; } $_clean['delayedsubmit'] = isset($values['delayedsubmit']) ? $values['delayedsubmit'] : ''; $_clean['max_text'] = isset($values['max_text']) ? $values['max_text'] : ''; $_clean['max_version'] = isset($values['max_version']) ? $values['max_version'] : ''; $course_id = api_get_course_int_id(); // Filter no _uass if (api_strtoupper(trim($values['title'])) === 'INDEX') { Display::addFlash(Display::return_message(get_lang('GoAndEditMainPage'), 'warning', false)); } else { $var = $_clean['reflink']; $group_id = intval($_GET['group_id']); if (!self::checktitle($var)) { return get_lang('WikiPageTitleExist'). ''. $values['title'].''; } else { $dtime = api_get_utc_datetime(); $params = [ 'c_id' => $course_id, 'reflink' => $_clean['reflink'], 'title' => $_clean['title'], 'content' => $_clean['content'], 'user_id' => $_clean['user_id'], 'group_id' => $groupId, 'dtime' => $dtime, 'visibility' => $_clean['visibility'], 'visibility_disc' => $_clean['visibility_disc'], 'ratinglock_disc' => $_clean['ratinglock_disc'], 'assignment' => $_clean['assignment'], 'comment' => $_clean['comment'], 'progress' => $_clean['progress'], 'version' => $_clean['version'], 'linksto' => $_clean['linksto'], 'user_ip' => $_SERVER['REMOTE_ADDR'], 'session_id' => $session_id, 'addlock_disc' => 1 ]; $id = Database::insert($tbl_wiki, $params); if ($id > 0) { $sql = "UPDATE $tbl_wiki SET id = iid WHERE iid = $id"; Database::query($sql); //insert into item_property api_item_property_update( api_get_course_info(), TOOL_WIKI, $id, 'WikiAdded', api_get_user_id(), $groupInfo ); $sql = 'UPDATE '.$tbl_wiki.' SET page_id="'.$id.'" WHERE c_id = '.$course_id.' AND id = "'.$id.'"'; Database::query($sql); // insert wiki config $params = [ 'c_id' => $course_id, 'page_id' => $id, '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'] ]; Database::insert($tbl_wiki_conf, $params); $this->setWikiData($id); self::check_emailcue(0, 'A'); return get_lang('NewWikiSaved'); } } } } /** * @param FormValidator $form * @param array $row */ public function setForm($form, $row = array()) { $toolBar = api_is_allowed_to_edit(null, true) ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400') : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student'); $form->addHtmlEditor('content', get_lang('Content'), false, false, $toolBar); //$content $form->addElement('text', 'comment', get_lang('Comments')); $progress = array('', 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); $form->addElement('select', 'progress', get_lang('Progress'), $progress); if ((api_is_allowed_to_edit(false, true) || api_is_platform_admin()) && isset($row['reflink']) && $row['reflink'] != 'index' ) { $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters')); $form->addElement('html', ''); } $form->addElement('hidden', 'page_id'); $form->addElement('hidden', 'reflink'); // $form->addElement('hidden', 'assignment'); $form->addElement('hidden', 'version'); $form->addElement('hidden', 'wpost_id', api_get_unique_id()); } /** * This function displays the form for adding a new wiki page. * @author Patrick Cool , Ghent University * @return html code **/ public function display_new_wiki_form() { $url = api_get_self().'?'.api_get_cidreq().'&action=addnew&group_id='.api_get_group_id(); $form = new FormValidator('wiki_new', 'post', $url); $form->addElement('text', 'title', get_lang('Title')); $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); self::setForm($form); $title = isset($_GET['title']) ? Security::remove_XSS($_GET['title']) : ''; $form->setDefaults(['title' => $title]); $form->addElement('button', 'SaveWikiNew', get_lang('Save')); $form->display(); if ($form->validate()) { $values = $form->exportValues(); if (isset($values['startdate_assig']) && isset($values['enddate_assig']) && strtotime($values['startdate_assig']) > strtotime($values['enddate_assig']) ) { Display::addFlash( Display::return_message( get_lang("EndDateCannotBeBeforeTheStartDate"), 'error', false ) ); } elseif (!self::double_post($_POST['wpost_id'])) { //double post } else { if (isset($values['assignment']) && $values['assignment'] == 1) { self::auto_add_page_users($values); } $return_message = self::save_new_wiki($values); if ($return_message == false) { Display::addFlash(Display::return_message(get_lang('NoWikiPageTitle'), 'error', false)); } else { Display::addFlash(Display::return_message($return_message, 'confirmation', false)); } $wikiData = self::getWikiData(); $redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq(); header('Location: '.$redirectUrl); exit; } } } /** * This function displays a wiki entry * @author Patrick Cool , Ghent University * @author Juan Carlos Raña Trabado * @param string $newtitle * @return string html code **/ public function display_wiki_entry($newtitle) { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_conf = $this->tbl_wiki_conf; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $page = $this->page; $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); if ($newtitle) { $pageMIX = $newtitle; //display the page after it is created } else { $pageMIX = $page; //display current page } $filter = null; if (isset($_GET['view']) && $_GET['view']) { $_clean['view'] = 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, 'ASSOC'); $KeyVisibility = $row['visibility']; // second, show the last version $sql = 'SELECT * FROM '.$tbl_wiki.' w INNER JOIN '.$tbl_wiki_conf.' wc ON (wc.page_id = w.page_id AND wc.c_id = w.c_id) WHERE w.c_id = '.$course_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); // we do not need a while loop since we are always displaying the last version $row = Database::fetch_array($result, 'ASSOC'); //log users access to wiki (page_id) if (!empty($row['page_id'])) { Event::addEvent(LOG_WIKI_ACCESS, LOG_WIKI_PAGE_ID, $row['page_id']); } //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); } $groupInfo = GroupManager::get_group_properties(api_get_group_id()); // if both are empty and we are displaying the index page then we display the default text. if ($row['content'] == '' && $row['title'] == '' && $page == 'index') { if (api_is_allowed_to_edit(false, true) || api_is_platform_admin() || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo) || api_is_allowed_in_course() ) { //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::addFlash(Display::return_message(get_lang('WikiStandBy'), 'normal', false)); } } else { $content = Security::remove_XSS($row['content']); $title = Security::remove_XSS($row['title']); } //assignment mode: identify page type $icon_assignment = null; 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 $icon_task = null; 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'])) || api_is_allowed_in_course() ) { $actionsLeft = ''; // menu edit page $editLink = ''. Display::return_icon('edit.png', get_lang('EditThisPage'), '', ICON_SIZE_MEDIUM).''; if (api_is_allowed_to_edit(false, true)) { $actionsLeft .= $editLink; } else { if ((api_is_allowed_in_course() || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo)) ) { $actionsLeft .= $editLink; } else { $actionsLeft .= ''; } } $actionsRight = ''; $protect_page = null; $lock_unlock_protect = null; // page action: protecting (locking) the page if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if (self::check_protect_page() == 1) { $protect_page = Display::return_icon('lock.png', get_lang('PageLockedExtra'), '', ICON_SIZE_MEDIUM); $lock_unlock_protect = 'unlock'; } else { $protect_page = Display::return_icon('unlock.png', get_lang('PageUnlockedExtra'), '', ICON_SIZE_MEDIUM); $lock_unlock_protect = 'lock'; } } if ($row['id']) { $actionsRight .= ''. $protect_page.''; } $visibility_page = null; $lock_unlock_visibility = null; //page action: visibility if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if (self::check_visibility_page() == 1) { $visibility_page = Display::return_icon('visible.png', get_lang('ShowPageExtra'), '', ICON_SIZE_MEDIUM); $lock_unlock_visibility = 'invisible'; } else { $visibility_page = Display::return_icon('invisible.png', get_lang('HidePageExtra'), '', ICON_SIZE_MEDIUM); $lock_unlock_visibility = 'visible'; } } if ($row['id']) { $actionsRight .= ''. $visibility_page.''; } //page action: notification if (api_is_allowed_to_session_edit()) { if (self::check_notify_page($page) == 1) { $notify_page = Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'), '', ICON_SIZE_MEDIUM); $lock_unlock_notify_page = 'unlocknotify'; } else { $notify_page = Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'), '', ICON_SIZE_MEDIUM); $lock_unlock_notify_page = 'locknotify'; } } // Only available if row['id'] is set if ($row['id']) { if (api_is_allowed_to_session_edit(false, true) && api_is_allowed_to_edit() || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo) ) { // menu discuss page $actionsRight .= ''. Display::return_icon('discuss.png', get_lang('DiscussThisPage'), '', ICON_SIZE_MEDIUM).''; } //menu history $actionsRight .= ''. Display::return_icon('history.png', get_lang('ShowPageHistory'), '', ICON_SIZE_MEDIUM).''; //menu linkspages $actionsRight .= ''. 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()) { $actionsRight .= ''. Display::return_icon('delete.png', get_lang('DeleteThisPage'), '', ICON_SIZE_MEDIUM).''; } $actionsRight .= ''. $notify_page.''; // Page action: copy last version to doc area if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { $actionsRight .= ''. Display::return_icon('export_to_documents.png', get_lang('ExportToDocArea'), '', ICON_SIZE_MEDIUM).''; } $actionsRight .= ''. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).''; $unoconv = api_get_configuration_value('unoconv.binaries'); if ($unoconv) { $actionsRight .= ''. Display::return_icon('export_doc.png', get_lang('ExportToDoc'), array(), ICON_SIZE_MEDIUM).''; } //export to print ?> "javascript: goprint();") ); } echo Display::toolbarAction('toolbar-wikistudent', [$actionsLeft, $actionsRight]); if (empty($title)) { $pageTitle = get_lang('DefaultTitle'); } if (self::wiki_exist($title)) { $pageTitle = $icon_assignment.' '.$icon_task.' '.api_htmlentities($title); } else { $pageTitle = api_htmlentities($title); } $pageWiki = self::make_wiki_link_clickable( self::detect_external_link( self::detect_anchor_link( self::detect_mail_link( self::detect_ftp_link( self::detect_irc_link( self::detect_news_link($content) ) ) ) ) ) ); $footerWiki = get_lang('Progress').': '.($row['progress'] * 10).'%   '.get_lang('Rating').': '.$row['score'].'   '.get_lang('Words').': '.self::word_count($content); echo Display::panel($pageWiki, $pageTitle, $footerWiki); } //end filter visibility } /** * This function counted the words in a document. Thanks Adeel Khan * @param string Document's text * @return int Number of words */ public function word_count($document) { $search = array( '@]*?>.*?@si', '@]*?>.*?@siU', '@
tbl_wiki; $groupfilter = $this->groupfilter; $condition_session = $this->condition_session; $course_id = api_get_course_int_id(); $sql = 'SELECT id FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND title="'.Database::escape_string($title).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; $result = Database::query($sql); $cant = Database::num_rows($result); if ($cant > 0) { return true; } else { return false; } } /** * Checks if this navigation tab has to be set to active * @author Patrick Cool , Ghent University * * @return string html code */ public function is_active_navigation_tab($paramwk) { if (isset($_GET['action']) && $_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 */ public function check_addnewpagelock() { $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $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 (isset($_GET['actionpage'])) { if ($_GET['actionpage'] == 'lockaddnew' && $status_addlock == 1) { $status_addlock = 0; } if ($_GET['actionpage'] == 'unlockaddnew' && $status_addlock == 0) { $status_addlock = 1; } $sql = 'UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string($status_addlock).'" WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session; Database::query($sql); } $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); } return $row['addlock']; } /** * Protect page * @author Juan Carlos Raña * return current database status of protect page and change it if get action */ public function check_protect_page() { $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $page = $this->page; $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_editlock = $row['editlock']; $id = $row['page_id']; // Change status if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) { if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lock' && $status_editlock == 0) { $status_editlock = 1; } if (isset($_GET['actionpage']) && $_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 page_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 */ public function check_visibility_page() { $tbl_wiki = $this->tbl_wiki; $page = $this->page; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $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 (isset($_GET['actionpage']) && $_GET['actionpage'] == 'visible' && $status_visibility == 0) { $status_visibility = 1; } if (isset($_GET['actionpage']) && $_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 */ public function check_visibility_discuss() { $tbl_wiki = $this->tbl_wiki; $page = $this->page; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $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 (isset($_GET['actionpage']) && $_GET['actionpage'] == 'showdisc' && $status_visibility_disc == 0) { $status_visibility_disc = 1; } if (isset($_GET['actionpage']) && $_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); } 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 */ public function check_addlock_discuss() { $tbl_wiki = $this->tbl_wiki; $page = $this->page; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $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_addlock_disc = $row['addlock_disc']; //change status if (api_is_allowed_to_edit() || api_is_platform_admin()) { if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lockdisc' && $status_addlock_disc == 0) { $status_addlock_disc = 1; } if (isset($_GET['actionpage']) && $_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); } 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 */ public function check_ratinglock_discuss() { $tbl_wiki = $this->tbl_wiki; $page = $this->page; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $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 (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lockrating' && $status_ratinglock_disc == 0) { $status_ratinglock_disc = 1; } if (isset($_GET['actionpage']) && $_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); } return $row['ratinglock_disc']; } /** * Notify page changes * @author Juan Carlos Raña * @return int the current notification status */ public function check_notify_page($reflink) { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $groupId = api_get_group_id(); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $userId = api_get_user_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 (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotify' && $status_notify == 0) { $sql = "SELECT id FROM $tbl_wiki_mailcue WHERE c_id = $course_id AND id = $id AND user_id = $userId"; $result = Database::query($sql); $exist = false; if (Database::num_rows($result)) { $exist = true; } if ($exist == false) { $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','".$groupId."','".$session_id."')"; Database::query($sql); } $status_notify = 1; } if (isset($_GET['actionpage']) && $_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; Database::query($sql); $status_notify = 0; } return $status_notify; } /** * Notify discussion changes * @author Juan Carlos Raña * @param string $reflink * @return int current database status of rating discuss and change it if get action */ public function check_notify_discuss($reflink) { $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $course_id = api_get_course_int_id(); $groupId = api_get_group_id(); $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 (isset($_GET['actionpage']) && $_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','".$groupId."','".$session_id."')"; Database::query($sql); $status_notify_disc = 1; } if (isset($_GET['actionpage']) && $_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; Database::query($sql); $status_notify_disc = 0; } return $status_notify_disc; } /** * Notify all changes * @author Juan Carlos Raña */ public function check_notify_all() { $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $course_id = api_get_course_int_id(); $groupId = api_get_group_id(); $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="'.$groupId.'" 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 (isset($_GET['actionpage']) && $_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','".$groupId."','".$session_id."')"; Database::query($sql); $status_notify_all = 1; } if (isset($_GET['actionpage']) && isset($_GET['actionpage']) && $_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="'.$groupId.'" 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 */ public function check_emailcue($id_or_ref, $type, $lastime = '', $lastuser = '') { $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $_course = $this->courseInfo; $groupId = api_get_group_id(); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $group_properties = GroupManager::get_group_properties($groupId); $group_name = $group_properties['name']; $allow_send_mail = false; //define the variable to below $email_assignment = null; 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'; $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="'.$groupId.'" 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="'.$groupId.'" 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_user_info($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="'.$groupId.'" 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="'.$groupId.'" 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 = $userinfo['complete_name']; $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 * @param int $doc_id wiki page id * @return mixed * @author Juan Carlos Raña */ public function export2doc($doc_id) { $_course = $this->courseInfo; $groupId = api_get_group_id(); $groupInfo = GroupManager::get_group_properties($groupId); $data = self::getWikiDataFromDb($doc_id); if (empty($data)) { return false; } $wikiTitle = $data['title']; $wikiContents = $data['content']; $template = ' {TITLE} {ASCIIMATHML_SCRIPT} {CONTENT} '; $css_file = api_get_path(SYS_CSS_PATH).'themes/'.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 = (api_contains_asciimathml($wikiContents) || 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).$groupPart; $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, '../..'.api_get_path(REL_COURSE_PATH)) !== false) { $web_course_path = api_get_path(WEB_COURSE_PATH); $wikiContents = str_replace('../..'.api_get_path(REL_COURSE_PATH), $web_course_path, $wikiContents); } $i = 1; //only export last version, but in new export new version in document area while (file_exists($exportDir.'/'.$exportFile.'_'.$i.'.html')) { $i++; } $wikiFileName = $exportFile.'_'.$i.'.html'; $exportPath = $exportDir.'/'.$wikiFileName; file_put_contents($exportPath, $wikiContents); $doc_id = add_document( $_course, $groupPath.'/'.$wikiFileName, 'file', filesize($exportPath), $wikiTitle ); api_item_property_update( $_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupInfo ); return $doc_id; } /** * Exports the wiki page to PDF */ public function export_to_pdf($id, $course_code) { if (!api_is_platform_admin()) { if (api_get_setting('students_export2pdf') !== 'true') { Display::addFlash( Display::return_message( get_lang('PDFDownloadNotAllowedForStudents'), 'error', false ) ); return false; } } $data = self::getWikiDataFromDb($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(SYS_CSS_PATH).'themes/'.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) * */ public function double_post($wpost_id) { $postId = Session::read('wpost_id'); if (!empty($postId)) { if ($wpost_id == $postId) { return false; } else { Session::write('wpost_id', $wpost_id); return true; } } else { Session::write('wpost_id', $wpost_id); return true; } } /** * Function wizard individual assignment * @author Juan Carlos Raña */ public function auto_add_page_users($values) { $assignment_type = $values['assignment']; $session_id = $this->session_id; $groupId = api_get_group_id(); $groupInfo = GroupManager::get_group_properties($groupId); if ($groupId == 0) { //extract course members if (!empty($session_id)) { $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id); } else { $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), 0); } } else { //extract group members $subscribed_users = GroupManager::get_subscribed_users($groupInfo); $subscribed_tutors = GroupManager::get_subscribed_tutors($groupInfo); $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);')); } $all_students_pages = array(); // Data about teacher $userId = api_get_user_id(); $userinfo = api_get_user_info($userId); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES)); $name = $userinfo['complete_name']." - ".$username; $photo = ''.$name.''; // teacher assignment title $title_orig = $values['title']; // teacher assignment reflink $link2teacher = $values['title'] = $title_orig."_uass".$userId; // first: teacher name, photo, and assignment description (original content) $content_orig_A = '
'.get_lang('AssignmentDesc').'
'.$photo.'
'.Display::tag('span', api_get_person_name($userinfo['firstname'], $userinfo['lastname']), array('title'=>$username)).'
'; $content_orig_B = '
'. get_lang('AssignmentDescription').': '. $title_orig.'

'.Security::remove_XSS($_POST['content']); //Second: student list (names, photo and links to their works). //Third: Create Students work pages. foreach ($a_users_to_add as $o_user_to_add) { if ($o_user_to_add['user_id'] != $userId) { // 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 $userPicture = UserManager::getUserPicture($assig_user_id); $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, $groupInfo); //student is tutor $is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $groupInfo) && GroupManager::is_subscribed($assig_user_id, $groupInfo); // 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) { $values['title'] = $title_orig; $values['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) ). ' [['.Security::remove_XSS($_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) $values['assignment'] = 2; } $this->assig_user_id = $assig_user_id; self::save_new_wiki($values); } } foreach ($a_users_to_add as $o_user_to_add) { if ($o_user_to_add['user_id'] == $userId) { $assig_user_id = $o_user_to_add['user_id']; if ($assignment_type == 1) { $values['title'] = $title_orig; $values['comment'] = get_lang('AssignmentDesc'); sort($all_students_pages); $values['content'] = $content_orig_A.$content_orig_B.'
    '.get_lang('AssignmentLinkstoStudentsPage').'

      '.implode($all_students_pages).'

    '; $values['assignment'] = 1; } $this->assig_user_id = $assig_user_id; self::save_new_wiki($values); } } } /** * Displays the results of a wiki search * @param string Search term * @param int Whether to search the contents (1) or just the titles (0) * @param int */ public function display_wiki_search_results($search_term, $search_content = 0, $all_vers = 0) { $tbl_wiki = $this->tbl_wiki; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $_course = $this->courseInfo; $course_id = api_get_course_int_id(); echo ''.get_lang('WikiSearchResults').': '.Security::remove_XSS($search_term); echo ''; //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 $rows = array(); if (Database::num_rows($result) > 0) { 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 = Display::return_icon('px_transparent.gif'); } $row = array(); $row[] = $ShowAssignment; if ($all_vers == '1') { $row[] = ''. api_htmlentities($obj->title).''; } else { $row[] = ''. $obj->title.''; } $row[] = ($obj->user_id != 0 && $userinfo !== false) ? UserManager::getUserProfileLink($userinfo) : get_lang('Anonymous').' ('.$obj->user_ip.')'; $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; if ($all_vers == '1') { $row[] = $obj->version; } else { $showdelete = ''; 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' => intval($_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 * */ public function draw_date_picker($prefix, $default = '') { if (empty($default)) { $default = date('Y-m-d H:i:s'); } $parts = explode(' ', $default); list($d_year, $d_month, $d_day) = explode('-', $parts[0]); list($d_hour, $d_minute) = explode(':', $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 = self::make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day); $date_form .= self::make_select($prefix.'_month', $month_list, $d_month); $date_form .= self::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 .= self::make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : '; $date_form .= self::make_select($prefix.'_minute', $minute, $d_minute); return $date_form; } /** * Draws an HTML form select with the given options * */ public function make_select($name, $values, $checked = '') { $output = ''; return $output; } /** * Translates a form date into a more usable format * */ public function get_date_from_select($prefix) { return $_POST[$prefix.'_year'].'-'. self::two_digits($_POST[$prefix.'_month']).'-'. self::two_digits($_POST[$prefix.'_day']).' '. self::two_digits($_POST[$prefix.'_hour']).':'. self::two_digits($_POST[$prefix.'_minute']).':00'; } /** * Converts 1-9 to 01-09 */ public function two_digits($number) { $number = (int) $number; return ($number < 10) ? '0'.$number : $number; } /** * Get wiki information * @param int|bool wiki id * @return array wiki data */ public function getWikiDataFromDb($id) { $tbl_wiki = $this->tbl_wiki; $course_id = api_get_course_int_id(); if ($id === false) { return array(); } $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; } /** * @param string $refLink * @return array */ public function getLastWikiData($refLink) { $tbl_wiki = $this->tbl_wiki; $groupfilter = $this->groupfilter; $condition_session = $this->condition_session; $course_id = api_get_course_int_id(); $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($refLink).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; $result = Database::query($sql); return Database::fetch_array($result); } /** * Get wiki information * @param string wiki id * @param int $courseId * @return array wiki data */ public function getPageByTitle($title, $courseId = null) { $tbl_wiki = $this->tbl_wiki; if (empty($courseId)) { $courseId = api_get_course_int_id(); } else { $courseId = intval($courseId); } if (empty($title) || empty($courseId)) { return array(); } $title = Database::escape_string($title); $sql = "SELECT * FROM $tbl_wiki WHERE c_id = $courseId AND reflink = '$title'"; $result = Database::query($sql); $data = array(); if (Database::num_rows($result)) { $data = Database::fetch_array($result, 'ASSOC'); } return $data; } /** * @param string $title * @param int $courseId * @param string * @param string * @return bool */ public function deletePage($title, $courseId, $groupfilter = null, $condition_session = null) { $tbl_wiki = $this->tbl_wiki; $tbl_wiki_discuss = $this->tbl_wiki_discuss; $tbl_wiki_mailcue = $this->tbl_wiki_mailcue; $tbl_wiki_conf = $this->tbl_wiki_conf; $pageInfo = self::getPageByTitle($title, $courseId); if (!empty($pageInfo)) { $pageId = $pageInfo['id']; $sql = "DELETE FROM $tbl_wiki_conf WHERE c_id = $courseId AND page_id = $pageId"; Database::query($sql); $sql = 'DELETE FROM '.$tbl_wiki_discuss.' WHERE c_id = '.$courseId.' AND publication_id = '.$pageId; Database::query($sql); $sql = 'DELETE FROM '.$tbl_wiki_mailcue.' WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.''; Database::query($sql); $sql = 'DELETE FROM '.$tbl_wiki.' WHERE c_id = '.$courseId.' AND id = '.$pageId.' AND '.$groupfilter.$condition_session.''; Database::query($sql); self::check_emailcue(0, 'E'); return true; } return false; } /** * @return array */ public function getAllWiki() { $tbl_wiki = $this->tbl_wiki; $course_id = $this->course_id; $condition_session = $this->condition_session; $sql = "SELECT * FROM $tbl_wiki WHERE c_id = $course_id AND is_editing != '0' ".$condition_session; $result = Database::query($sql); return Database::store_result($result, 'ASSOC'); } /** * @param int $isEditing */ public function updateWikiIsEditing($isEditing) { $tbl_wiki = $this->tbl_wiki; $course_id = $this->course_id; $condition_session = $this->condition_session; $isEditing = Database::escape_string($isEditing); $sql = 'UPDATE '.$tbl_wiki.' SET is_editing = "0", time_edit = NULL WHERE c_id = '.$course_id.' AND is_editing="'.$isEditing.'" '. $condition_session; Database::query($sql); } /** * Release of blocked pages to prevent concurrent editions * @param int $userId * @param string $action */ public function blockConcurrentEditions($userId, $action = null) { $result = self::getAllWiki(); if (!empty($result)) { foreach ($result as $is_editing_block) { $max_edit_time = 1200; // 20 minutes $timestamp_edit = strtotime($is_editing_block['time_edit']); $time_editing = time() - $timestamp_edit; // First prevent concurrent users and double version if ($is_editing_block['is_editing'] == $userId) { Session::write('_version', $is_editing_block['version']); } else { Session::erase('_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'] == $userId && $action != 'edit')) { self::updateWikiIsEditing($is_editing_block['is_editing']); } } } } /** * Showing wiki stats */ public function getStats() { if (!api_is_allowed_to_edit(false, true)) { return false; } $tbl_wiki = $this->tbl_wiki; $course_id = $this->course_id; $condition_session = $this->condition_session; $groupfilter = $this->groupfilter; $session_id = $this->session_id; $tbl_wiki_conf = $this->tbl_wiki_conf; echo '
    '.get_lang('Statistics').'
    '; // Check all versions of all pages $total_words = 0; $total_links = 0; $total_links_anchors = 0; $total_links_mail = 0; $total_links_ftp = 0; $total_links_irc = 0; $total_links_news = 0; $total_wlinks = 0; $total_images = 0; $clean_total_flash = 0; $total_flash = 0; $total_mp3 = 0; $total_flv_p = 0; $total_flv = 0; $total_youtube = 0; $total_multimedia = 0; $total_tables = 0; $sql = "SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; $allpages = Database::query($sql); while ($row = Database::fetch_array($allpages)) { $total_versions = $row['TOTAL_VERS']; $total_visits = intval($row['TOTAL_VISITS']); } $sql = "SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session.""; $allpages = Database::query($sql); while ($row = Database::fetch_array($allpages)) { $total_words = $total_words + self::word_count($row['content']); $total_links = $total_links + substr_count($row['content'], "href="); $total_links_anchors = $total_links_anchors + substr_count($row['content'], 'href="#'); $total_links_mail = $total_links_mail + substr_count($row['content'], 'href="mailto'); $total_links_ftp = $total_links_ftp + substr_count($row['content'], 'href="ftp'); $total_links_irc = $total_links_irc + substr_count($row['content'], 'href="irc'); $total_links_news = $total_links_news + substr_count($row['content'], 'href="news'); $total_wlinks = $total_wlinks + substr_count($row['content'], "[["); $total_images = $total_images + substr_count($row['content'], "