From 992da76bacaef8a607fe8efb5c1f2b89badf6d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Ra=C3=B1a?= Date: Mon, 12 Oct 2009 20:32:12 +0200 Subject: [PATCH] fix some buttons for lock/unlock: add new pages, edit pages, visibility pages, rating discuss, new messages to discuss, visibility discuss --- main/wiki/index.php | 130 ++++++++++++------------ main/wiki/wiki.inc.php | 222 +++++++++++++++++------------------------ 2 files changed, 157 insertions(+), 195 deletions(-) diff --git a/main/wiki/index.php b/main/wiki/index.php index 1095e49132..65f4d8ac90 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -426,24 +426,25 @@ echo ''; //menu add page echo '
  • '.get_lang('AddNew').' '; } - + + if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) + { // page action: enable or disable the adding of new pages - if (check_addnewpagelock()) + if (check_addnewpagelock()==1) { - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) - { - $protect_addnewpage= ''.get_lang('AddOptionProtected').''; - } + + $protect_addnewpage= ''.get_lang('AddOptionProtected').''; + $lock_unlock_addnew='unlockaddnew'; + } else { - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) - { - $protect_addnewpage= ''.get_lang('AddOptionUnprotected').''; - } + $protect_addnewpage= ''.get_lang('AddOptionUnprotected').''; + $lock_unlock_addnew='lockaddnew'; } + } - echo ''.$protect_addnewpage.'
  • '; + echo ''.$protect_addnewpage.''; ///menu find echo '
  • '.get_lang('SearchPages').'
  • '; @@ -1197,7 +1198,7 @@ if ($_GET['action']=='addnew') } } - elseif (check_addnewpagelock() && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) + elseif (check_addnewpagelock()==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) { Display::display_error_message(get_lang('AddPagesLocked')); } @@ -2130,80 +2131,79 @@ if ($_GET['action']=='discuss') echo '
    '; // discussion action: protecting (locking) the discussion - if (check_addlock_discuss()) - { - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) - { - $addlock_disc= ''.get_lang('LockDiscussExtra').''; - } - else - { - $addlock_disc= ''.get_lang('LockDiscussExtra').''; - } - - } - else - { - 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 (check_addlock_discuss()==1) + { $addlock_disc= ''.get_lang('UnlockDiscussExtra').''; - } - } + $lock_unlock_disc='unlockdisc'; + } + + else + { + $addlock_disc= ''.get_lang('LockDiscussExtra').''; + $lock_unlock_disc='lockdisc'; + } + } echo ''; - echo ''.$addlock_disc.''; - echo ''; - + echo ''.$addlock_disc.''; + echo ''; // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden. - if (check_visibility_discuss()) - { - //Mode assignments: If is hidden, show pages to student only if student is the author - if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false) - { - $visibility_disc= ''.get_lang('HideDiscussExtra').''; - } - } - else - { - 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 (check_visibility_discuss()==1) + { + /// TODO: Fix Mode assignments: If is hidden, show discussion to student only if student is the author + //if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false) + //{ + //$visibility_disc= ''.get_lang('HideDiscussExtra').''; + + //} $visibility_disc= ''.get_lang('ShowDiscussExtra').''; - } - } + $hide_show_disc='hidedisc'; + } + else + { + $visibility_disc= ''.get_lang('HideDiscussExtra').''; + $hide_show_disc='showdisc'; + } + } echo ''; - echo ''.$visibility_disc.''; + echo ''.$visibility_disc.''; echo ''; - //discussion action: check add rating lock. Show/Hide list to rating for all student - if (check_ratinglock_discuss()) - { - //Mode assignment: only the teacher can assign scoring - if(($row['assignment']==2 && $row['ratinglock_disc']==0 && (api_get_user_id()==$row['user_id']))==false) + + if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) + { + if (check_ratinglock_discuss()==1) { - $ratinglock_disc= ''.get_lang('LockRatingDiscussExtra').''; + $ratinglock_disc= ''.get_lang('UnlockRatingDiscussExtra').''; + $lock_unlock_rating_disc='unlockrating'; } - } - else - { - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) + else { - $ratinglock_disc= ''.get_lang('UnlockRatingDiscussExtra').''; + $ratinglock_disc= ''.get_lang('LockRatingDiscussExtra').''; + $lock_unlock_rating_disc='lockrating'; } - } + } + echo ''; - echo ''.$ratinglock_disc.''; + echo ''.$ratinglock_disc.''; echo ''; //discussion action: email notification if (check_notify_discuss($page)) - { + { $notify_disc= ''.get_lang('NotifyDiscussByEmail').''; - } + } else - { + { $notify_disc= ''.get_lang('CancelNotifyDiscussByEmail').''; - } + } echo ''; echo ''.$notify_disc.''; echo ''; diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index 9e1060d4b5..4117a57103 100644 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -838,47 +838,46 @@ function display_wiki_entry() { echo '
    '; - // page action: protecting (locking) the page - if (check_protect_page()) - { + // page action: protecting (locking) the page if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { + if (check_protect_page()==1) + { $protect_page= ''.get_lang('PageLockedExtra').''; - } - else - { - $protect_page= ''.get_lang('PageLockedExtra').''; - } - } - else - { - if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) - { + $lock_unlock_protect='unlock'; + } + else + { $protect_page= ''.get_lang('PageUnlockedExtra').''; - } - } + $lock_unlock_protect='lock'; + } + } echo ''; - echo ''.$protect_page.''; + echo ''.$protect_page.''; echo ''; //page action: visibility - if (check_visibility_page()) - { - //This hides the icon eye closed to users of work they can see yours - if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false) - { - $visibility_page= ''.get_lang('HidePageExtra').''; - } - } - else - { if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { + if (check_visibility_page()==1) + { + // TODO: FIX This hides the icon eye closed to users of work they can see yours + //if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false) + //{ + // + // } $visibility_page= ''.get_lang('ShowPageExtra').''; + $lock_unlock_visibility='invisible'; + + } + else + { + $visibility_page= ''.get_lang('HidePageExtra').''; + $lock_unlock_visibility='visible'; + } } - } echo ''; - echo ''.$visibility_page.''; + echo ''.$visibility_page.''; echo ''; //page action: notification @@ -1049,6 +1048,7 @@ function is_active_navigation_tab($paramwk) /** * Lock add pages * @author Juan Carlos Raña + * return current database status of protect page and change it if get action */ function check_addnewpagelock() @@ -1066,15 +1066,16 @@ function check_addnewpagelock() $status_addlock=$row['addlock']; //change status - if ($_GET['actionpage']=='addlock' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) + if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { - if ($row['addlock']==1) + + if ($_GET['actionpage']=='lockaddnew' && $status_addlock==0) { - $status_addlock=0; - } - else + $status_addlock=1; + } + if ($_GET['actionpage']=='unlockaddnew' && $status_addlock==1) { - $status_addlock=1; + $status_addlock=0; } Database::query('UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string($status_addlock).'" WHERE '.$groupfilter.'',__LINE__,__FILE__); @@ -1086,20 +1087,14 @@ function check_addnewpagelock() //show status - if ($row['addlock']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - } - else - { - return true; - } + return $row['addlock']; } /** * Protect page * @author Juan Carlos Raña + * return current database status of protect page and change it if get action */ function check_protect_page() { @@ -1118,16 +1113,17 @@ function check_protect_page() $id=$row['id']; ///change status - if ($_GET['actionpage']=='lock' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) - { - if ($row['editlock']==0) - { - $status_editlock=1; - } - else + if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) + { + if($_GET['actionpage']=='lock' && $status_editlock==0) { - $status_editlock=0; - } + $status_editlock=1; + } + if($_GET['actionpage']=='unlock' && $status_editlock==1) + { + $status_editlock=0; + } + $sql='UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string($status_editlock).'" WHERE id="'.$id.'"'; Database::query($sql,__FILE__,__LINE__); @@ -1140,21 +1136,15 @@ function check_protect_page() } //show status - if ($row['editlock']==0 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - } - else - { - return true; - } + return $row['editlock']; } /** * Visibility page * @author Juan Carlos Raña + * return current database status of visibility and change it if get action */ function check_visibility_page() { @@ -1170,18 +1160,20 @@ function check_visibility_page() $row=Database::fetch_array($result); $status_visibility=$row['visibility']; - $id=$row['id']; //need ? check. TODO - //change status - if ($_GET['actionpage']=='visibility' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) + + //change status + + if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { - if ($row['visibility']==1) - { - $status_visibility=0; - } - else + if($_GET['actionpage']=='visible' && $status_visibility==0) + { + $status_visibility=1; + + } + if($_GET['actionpage']=='invisible' && $status_visibility==1) { - $status_visibility=1; + $status_visibility=0; } $sql='UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string($status_visibility).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; @@ -1195,21 +1187,14 @@ function check_visibility_page() } //show status - if ($row['visibility']=="1" || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - } - else - { - return true; - } - + return $row['visibility']; } /** * Visibility discussion * @author Juan Carlos Raña + * return current database status of discuss visibility and change it if get action page */ function check_visibility_discuss() { @@ -1225,18 +1210,17 @@ function check_visibility_discuss() $row=Database::fetch_array($result); $status_visibility_disc=$row['visibility_disc']; - $id=$row['id']; //need ? check. TODO - + //change status - if ($_GET['actionpage']=='visibility_disc' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) + if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { - if ($row['visibility_disc']==1) - { - $status_visibility_disc=0; - } - else + if ($_GET['actionpage']=='showdisc' && $status_visibility_disc==0) { - $status_visibility_disc=1; + $status_visibility_disc=1; + } + if ($_GET['actionpage']=='hidedisc' && $status_visibility_disc==1) + { + $status_visibility_disc=0; } $sql='UPDATE '.$tbl_wiki.' SET visibility_disc="'.Database::escape_string($status_visibility_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; @@ -1250,22 +1234,14 @@ function check_visibility_discuss() } //show status - - if ($row['visibility_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - - } - else - { - return true; - } + return $row['visibility_disc']; } /** * Lock add discussion * @author Juan Carlos Raña + * return current database status of lock dicuss and change if get action */ function check_addlock_discuss() { @@ -1280,18 +1256,18 @@ function check_addlock_discuss() $row=Database::fetch_array($result); $status_addlock_disc=$row['addlock_disc']; - $id=$row['id']; //need ? check. TODO //change status - if ($_GET['actionpage']=='addlock_disc' && (api_is_allowed_to_edit(null,true) || api_is_platform_admin())) + if (api_is_allowed_to_edit() || api_is_platform_admin()) { - if ($row['addlock_disc']==1) - { - $status_addlock_disc=0; - } - else + + if ($_GET['actionpage']=='lockdisc' && $status_addlock_disc==0) + { + $status_addlock_disc=1; + } + if ($_GET['actionpage']=='unlockdisc' && $status_addlock_disc==1) { - $status_addlock_disc=1; + $status_addlock_disc=0; } $sql='UPDATE '.$tbl_wiki.' SET addlock_disc="'.Database::escape_string($status_addlock_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; @@ -1305,22 +1281,14 @@ function check_addlock_discuss() } //show status - - if ($row['addlock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - } - else - { - return true; - } + return $row['addlock_disc']; } - /** * Lock rating discussion * @author Juan Carlos Raña + * Return current database status of rating discuss and change it if get action */ function check_ratinglock_discuss() { @@ -1336,19 +1304,19 @@ function check_ratinglock_discuss() $row=Database::fetch_array($result); $status_ratinglock_disc=$row['ratinglock_disc']; - $id=$row['id']; //need ? check. TODO + //change status - if ($_GET['actionpage']=='ratinglock_disc' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) + if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { - if ($row['ratinglock_disc']==1) - { - $status_ratinglock_disc=0; - } - else + if ($_GET['actionpage']=='lockrating' && $status_ratinglock_disc==0) { - $status_ratinglock_disc=1; + $status_ratinglock_disc=1; } + if ($_GET['actionpage']=='unlockrating' && $status_ratinglock_disc==1) + { + $status_ratinglock_disc=0; + } $sql='UPDATE '.$tbl_wiki.' SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; //Visibility. Value to all,not only for the first Database::query($sql,__FILE__,__LINE__); @@ -1361,21 +1329,15 @@ function check_ratinglock_discuss() } //show status - if ($row['ratinglock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) - { - return false; - } - else - { - return true; - } + return $row['ratinglock_disc']; } /** * Notify page changes * @author Juan Carlos Raña + * return the current */ function check_notify_page($reflink)