Minor - format code, remove unused code.

pull/2487/head
jmontoyaa 7 years ago
parent 885ba7b65d
commit 80b8f59509
  1. 443
      main/wiki/wiki.inc.php

@ -62,9 +62,7 @@ class Wiki
$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();
$this->url = api_get_path(WEB_CODE_PATH).'wiki/index.php?'.api_get_cidreq();
}
/**
@ -88,9 +86,9 @@ class Wiki
reflink="'.Database::escape_string($link).'" AND
'.$groupfilter.$condition_session.'';
$result = Database::query($sql);
$numberofresults = Database::num_rows($result);
$num = Database::num_rows($result);
// the value has not been found and is this available
if ($numberofresults == 0) {
if ($num == 0) {
return true;
} else {
// the value has been found
@ -812,7 +810,7 @@ class Wiki
);
if ((api_is_allowed_to_edit(false, true) ||
api_is_platform_admin()) &&
api_is_platform_admin()) &&
isset($row['reflink']) && $row['reflink'] != 'index'
) {
$form->addElement(
@ -898,9 +896,9 @@ class Wiki
$row['initenddate'] = null;
}
$form->addElement('html', '<div id="end_date" style="'.$style.'">');
$form->addHtml('<div id="end_date" style="'.$style.'">');
$form->addDatePicker('enddate_assig', '');
$form->addElement('html', '</div>');
$form->addHtml('</div>');
$form->addElement(
'checkbox',
'delayedsubmit',
@ -987,8 +985,7 @@ class Wiki
}
$wikiData = self::getWikiData();
$redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq(
);
$redirectUrl = $this->url.'&action=showpage&title='.$wikiData['reflink'].'&'.api_get_cidreq();
header('Location: '.$redirectUrl);
exit;
}
@ -1129,16 +1126,12 @@ class Wiki
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'])) ||
($row['assignment'] == 2 && $KeyVisibility == "0" && (api_get_user_id() == $row['user_id'])) ||
api_is_allowed_in_course()
) {
$actionsLeft = '';
// menu edit page
$editLink = '<a href="index.php?'.api_get_cidreq(
).'&action=edit&title='.api_htmlentities(
urlencode($page)
).'"'.self::is_active_navigation_tab('edit').'>'.
$editLink = '<a href="index.php?'.api_get_cidreq().'&action=edit&title='.api_htmlentities(urlencode($page)).'"'.self::is_active_navigation_tab('edit').'>'.
Display::return_icon(
'edit.png',
get_lang('EditThisPage'),
@ -1166,8 +1159,9 @@ class Wiki
$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 (api_is_allowed_to_edit(false, true) ||
api_is_platform_admin()
) {
if (self::check_protect_page() == 1) {
$protect_page = Display::return_icon(
'lock.png',
@ -1188,18 +1182,16 @@ class Wiki
}
if ($row['id']) {
$actionsRight .= '<a href="index.php?'.api_get_cidreq(
).'&action=showpage&actionpage='.$lock_unlock_protect.'&title='.api_htmlentities(
urlencode($page)
).'">'.
$protect_page.'</a>';
$actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_protect.'&title='.api_htmlentities(urlencode($page)).'">'.
$protect_page.'</a>';
}
$visibility_page = null;
$lock_unlock_visibility = null;
//page action: visibility
if (api_is_allowed_to_edit(false, true) || api_is_platform_admin(
)) {
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',
@ -1221,10 +1213,7 @@ class Wiki
}
if ($row['id']) {
$actionsRight .= '<a href="index.php?'.api_get_cidreq(
).'&action=showpage&actionpage='.$lock_unlock_visibility.'&title='.api_htmlentities(
urlencode($page)
).'">'.
$actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=showpage&actionpage='.$lock_unlock_visibility.'&title='.api_htmlentities(urlencode($page)).'">'.
$visibility_page.'</a>';
}
@ -1251,10 +1240,8 @@ class Wiki
// Only available if row['id'] is set
if ($row['id']) {
if (api_is_allowed_to_session_edit(
false,
true
) && api_is_allowed_to_edit() ||
if (api_is_allowed_to_session_edit(false, true) &&
api_is_allowed_to_edit() ||
GroupManager::is_user_in_group(
api_get_user_id(),
$groupInfo
@ -1297,10 +1284,9 @@ class Wiki
).'</a>';
//menu delete wikipage
if (api_is_allowed_to_edit(
false,
true
) || api_is_platform_admin()) {
if (api_is_allowed_to_edit(false, true) ||
api_is_platform_admin()
) {
$actionsRight .= '<a href="index.php?action=delete&'.api_get_cidreq(
).'&title='.api_htmlentities(
urlencode($page)
@ -1320,10 +1306,9 @@ class Wiki
$notify_page.'</a>';
// Page action: copy last version to doc area
if (api_is_allowed_to_edit(
false,
true
) || api_is_platform_admin()) {
if (api_is_allowed_to_edit(false, true) ||
api_is_platform_admin()
) {
$actionsRight .= '<a href="index.php?'.api_get_cidreq(
).'&action=export2doc&wiki_id='.$row['id'].'">'.
Display::return_icon(
@ -1345,10 +1330,7 @@ class Wiki
$unoconv = api_get_configuration_value('unoconv.binaries');
if ($unoconv) {
$actionsRight .= '<a href="'.api_get_path(
WEB_CODE_PATH
).'wiki/index.php?action=export_to_doc_file&id='.$row['id'].'&'.api_get_cidreq(
).'">'.
$actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).'wiki/index.php?action=export_to_doc_file&id='.$row['id'].'&'.api_get_cidreq().'">'.
Display::return_icon(
'export_doc.png',
get_lang('ExportToDoc'),
@ -1391,9 +1373,8 @@ class Wiki
}
if (self::wiki_exist($title)) {
$pageTitle = $icon_assignment.'&nbsp;'.$icon_task.'&nbsp;'.api_htmlentities(
$title
);
$pageTitle = $icon_assignment.'&nbsp;'.
$icon_task.'&nbsp;'.api_htmlentities($title);
} else {
$pageTitle = api_htmlentities($title);
}
@ -1535,7 +1516,9 @@ class Wiki
$status_addlock = $row['addlock'];
// Change status
if (api_is_allowed_to_edit(false, true) || api_is_platform_admin()) {
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;
@ -1594,16 +1577,15 @@ class Wiki
$status_editlock = 0;
}
$sql = 'UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string(
$status_editlock
).'"
$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
WHERE
c_id = '.$course_id.' AND
reflink="'.Database::escape_string($page).'" AND
'.$groupfilter.$condition_session.'
ORDER BY id ASC';
$result = Database::query($sql);
@ -1637,12 +1619,20 @@ class Wiki
$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) {
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) {
if (isset($_GET['actionpage']) &&
$_GET['actionpage'] == 'invisible' &&
$status_visibility == 1
) {
$status_visibility = 0;
}
@ -1679,7 +1669,8 @@ class Wiki
/**
* Visibility discussion
* @author Juan Carlos Raña <herodoto@telefonica.net>
* @return int current database status of discuss visibility and change it if get action page
* @return int current database status of discuss visibility
* and change it if get action page
*/
public function check_visibility_discuss()
{
@ -1702,16 +1693,21 @@ class Wiki
//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) {
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) {
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
).'"
$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
@ -1761,10 +1757,16 @@ class Wiki
//change status
if (api_is_allowed_to_edit() || api_is_platform_admin()) {
if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'lockdisc' && $status_addlock_disc == 0) {
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) {
if (isset($_GET['actionpage']) &&
$_GET['actionpage'] == 'unlockdisc' &&
$status_addlock_disc == 1
) {
$status_addlock_disc = 0;
}
@ -1819,23 +1821,29 @@ class Wiki
$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) {
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) {
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
).'"
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
// Visibility. Value to all,not only for the first
Database::query($sql);
// Although the value now is assigned to all (not only the first),
@ -1843,9 +1851,9 @@ class Wiki
// 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
WHERE
c_id = '.$course_id.' AND
reflink="'.Database::escape_string($page).'" AND
'.$groupfilter.$condition_session.'
ORDER BY id ASC';
$result = Database::query($sql);
@ -1872,14 +1880,20 @@ class Wiki
$userId = api_get_user_id();
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.'
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"';
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'];
@ -1890,7 +1904,10 @@ class Wiki
}
// Change status
if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotify' && $status_notify == 0) {
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);
@ -1907,10 +1924,16 @@ class Wiki
$status_notify = 1;
}
if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'unlocknotify' && $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;
WHERE
id="'.$id.'" AND
user_id="'.api_get_user_id().'" AND
type="P" AND
c_id = '.$course_id;
Database::query($sql);
$status_notify = 0;
}
@ -1936,13 +1959,17 @@ class Wiki
$session_id = api_get_session_id();
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE c_id = '.$course_id.' AND reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.'
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(
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);
@ -1954,18 +1981,27 @@ class Wiki
$status_notify_disc = 1;
}
//change status
if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotifydisc' && $status_notify_disc == 0) {
// 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."')";
($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) {
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;
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;
}
@ -2003,7 +2039,10 @@ class Wiki
}
//change status
if (isset($_GET['actionpage']) && $_GET['actionpage'] == 'locknotifyall' && $status_notify_all == 0) {
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."')";
@ -2073,7 +2112,10 @@ class Wiki
//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.'
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);
@ -2091,11 +2133,9 @@ class Wiki
session_id="'.$session_id.'"';
//type: P=page, D=discuss, F=full.
$result = Database::query($sql);
$emailtext = get_lang(
'EmailWikipageModified'
).' <strong>'.$email_page_name.'</strong> '.get_lang(
'Wiki'
);
$emailtext = get_lang('EmailWikipageModified').
'<strong>'.$email_page_name.'</strong> '.
get_lang('Wiki');
}
} elseif ($type == 'D') {
//if added a post to discuss
@ -2180,7 +2220,13 @@ class Wiki
}
$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.'"';
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);
@ -2194,9 +2240,7 @@ class Wiki
$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'];
$email_user_author = get_lang('DeletedBy').': '.$userinfo['complete_name'];
//When ?
$today = date('r'); //current time
$email_date_changes = $today;
@ -2363,10 +2407,9 @@ class Wiki
)
);
//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
// 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)
@ -2538,9 +2581,7 @@ class Wiki
);
//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();
@ -2628,8 +2669,9 @@ class Wiki
</div>[['.$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
//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[] = '<li>'.
Display::tag(
@ -2642,7 +2684,9 @@ class Wiki
' [['.Security::remove_XSS(
$_POST['title']
)."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>';
//don't change this line without guaranteeing that users will be ordered by last names in the following format (surname, name)
// 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;
@ -3007,118 +3051,6 @@ class Wiki
}
}
/**
* 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
).'&nbsp;&nbsp;&nbsp;&nbsp;';
$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 = '<select name="'.$name.'" id="'.$name.'">';
foreach ($values as $key => $value) {
$output .= '<option value="'.$key.'" '.(($checked == $key) ? 'selected="selected"' : '').'>'.$value.'</option>';
}
$output .= '</select>';
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
@ -3299,8 +3231,12 @@ class Wiki
} 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')) {
// 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']);
}
}
@ -3570,7 +3506,10 @@ class Wiki
//Total protect pages
$total_protected = 0;
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE c_id = '.$course_id.' AND editlock=1 AND '.$groupfilter.$condition_session.'
WHERE
c_id = '.$course_id.' AND
editlock = 1 AND
'.$groupfilter.$condition_session.'
GROUP BY reflink';
// or group by page_id. As the mark of protected page is the first version of the page, I can use group by
$allpages = Database::query($sql);
@ -3671,7 +3610,11 @@ class Wiki
WHERE s1.c_id = '.$course_id.' AND assignment=1 AND id=(
SELECT MAX(s2.id)
FROM '.$tbl_wiki.' s2
WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.'
WHERE
s2.c_id = '.$course_id.' AND
s1.reflink = s2.reflink AND
'.$groupfilter.' AND
session_id='.$session_id.'
)';
//mark all versions, but do not use group by reflink because y want the pages not versions
$allpages = Database::query($sql);
@ -3683,8 +3626,13 @@ class Wiki
$total_student_assignment = 0;
$sql = 'SELECT * FROM '.$tbl_wiki.' s1
WHERE s1.c_id = '.$course_id.' AND assignment=2 AND
id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
id = (SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
WHERE
s2.c_id = '.$course_id.' AND
s1.reflink = s2.reflink AND
'.$groupfilter.' AND
session_id='.$session_id.'
)';
//mark all versions, but do not use group by reflink because y want the pages not versions
$allpages = Database::query($sql);
while ($row = Database::fetch_array($allpages)) {
@ -3760,7 +3708,8 @@ class Wiki
s2.c_id = '.$course_id.' AND
s1.reflink = s2.reflink AND
'.$groupfilter.' AND
session_id='.$session_id.')';
session_id='.$session_id.'
)';
// As the value is only the latest version I can not use group by
$allpages = Database::query($sql);
while ($row = Database::fetch_array($allpages)) {
@ -4165,8 +4114,7 @@ class Wiki
if ($row['visibility_disc'] == 1 ||
api_is_allowed_to_edit(false, true) ||
api_is_platform_admin() ||
($row['assignment'] == 2 && $row['visibility_disc'] == 0 && (api_get_user_id(
) == $row['user_id']))
($row['assignment'] == 2 && $row['visibility_disc'] == 0 && (api_get_user_id() == $row['user_id']))
) {
echo '<div id="wikititle">';
// discussion action: protecting (locking) the discussion
@ -4582,14 +4530,22 @@ class Wiki
FROM '.$tbl_wiki.' s1
WHERE s1.c_id = '.$course_id.' AND id=(
SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
WHERE
s2.c_id = '.$course_id.' AND
s1.reflink = s2.reflink AND
'.$groupfilter.' AND
session_id='.$session_id.')';
// warning don't use group by reflink because does not return the last version
} else {
$sql = 'SELECT * FROM '.$tbl_wiki.' s1
WHERE visibility=1 AND s1.c_id = '.$course_id.' AND id=(
SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
WHERE
s2.c_id = '.$course_id.' AND
s1.reflink = s2.reflink AND
'.$groupfilter.' AND
session_id='.$session_id.')';
// warning don't use group by reflink because does not return the last version
}
@ -5463,8 +5419,11 @@ class Wiki
/* Only teachers and platform admin can edit the index page.
Only teachers and platform admin can edit an assignment teacher*/
if (($current_row['reflink'] == 'index' || $current_row['reflink'] == '' || $current_row['assignment'] == 1) &&
(!api_is_allowed_to_edit(false, true) && $this->group_id == 0)
if (($current_row['reflink'] == 'index' ||
$current_row['reflink'] == '' ||
$current_row['assignment'] == 1) &&
(!api_is_allowed_to_edit(false, true) &&
$this->group_id == 0)
) {
Display::addFlash(
Display::return_message(
@ -6348,12 +6307,13 @@ class Wiki
) && $groupId == 0) && !api_is_allowed_in_course()
) {
Display::addFlash(
Display::return_message(get_lang('OnlyEditPagesCourseManager')),
'error'
Display::return_message(
get_lang('OnlyEditPagesCourseManager'),
'error'
)
);
} else {
$PassEdit = false;
// Check if is a wiki group
if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId);
@ -6762,7 +6722,6 @@ class Wiki
}
// Second, show
//if the page is hidden and is a job only sees its author and professor
if ($KeyVisibility == 1 ||
api_is_allowed_to_edit(false, true) ||
@ -6773,7 +6732,9 @@ class Wiki
)
) {
// We show the complete history
if (!isset($_POST['HistoryDifferences']) && !isset($_POST['HistoryDifferences2'])) {
if (!isset($_POST['HistoryDifferences']) &&
!isset($_POST['HistoryDifferences2'])
) {
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE
c_id = '.$course_id.' AND

Loading…
Cancel
Save