'; /* /* ----------------------------------------------------------- Table definitions ----------------------------------------------------------- */ $tbl_wiki = Database::get_course_table(TABLE_WIKI); $tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS); $tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE); /* ----------------------------------------------------------- Constants and variables ----------------------------------------------------------- */ $tool_name = get_lang('Wiki'); $MonthsLong = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong")); /* ---------------------------------------------------------- ACCESS ----------------------------------------------------------- */ api_protect_course_script(); api_block_anonymous_users(); /* ----------------------------------------------------------- TRACKING ----------------------------------------------------------- */ event_access_tool('TOOL_WIKI'); /* ----------------------------------------------------------- HEADER & TITLE ----------------------------------------------------------- */ // If it is a group wiki then the breadcrumbs will be different. if ($_SESSION['_gid'] OR $_GET['group_id']) { if (isset($_SESSION['_gid'])) { $_clean['group_id']=(int)$_SESSION['_gid']; } if (isset($_GET['group_id'])) { $_clean['group_id']=(int)Database::escape_string($_GET['group_id']); } $group_properties = GroupManager :: get_group_properties($_clean['group_id']); $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['_gid'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')'); $add_group_to_title = ' ('.$group_properties['name'].')'; $groupfilter='group_id="'.$_clean['group_id'].'"'; } else { $groupfilter='group_id IS NULL'; } Display::display_header($tool_name, 'Wiki'); $is_allowed_to_edit = api_is_allowed_to_edit(); api_display_tool_title($tool_name.$add_group_to_title); /* ----------------------------------------------------------- INITIALISATION ----------------------------------------------------------- */ //the page we are dealing with if (!isset($_GET['title'])){ $page='index'; } else { $page=Security::remove_XSS($_GET['title']); } // some titles are not allowed //$not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now /* ----------------------------------------------------------- Configuration settings ----------------------------------------------------------- */ $fck_attribute['Width'] = '100%'; $fck_attribute['ToolbarSet'] = 'Wiki'; if(!api_is_allowed_to_edit()) { $fck_attribute['Config']['UserStatus'] = 'student'; } /* ============================================================================== MAIN CODE ============================================================================== */ /* ----------------------------------------------------------- Introduction section ----------------------------------------------------------- */ Display::display_introduction_section(TOOL_WIKI); /* ----------------------------------------------------------- ACTIONS ----------------------------------------------------------- */ // saving a change if ($_POST['SaveWikiChange'] AND $_POST['title']<>'') { if(empty($_POST['title'])) { Display::display_normal_message(get_lang("NoWikiPageTitle")); } else { $return_message=save_wiki(); } } //saving a new wiki entry if ($_POST['SaveWikiNew']) { if(empty($_POST['title'])) { Display::display_normal_message(get_lang("NoWikiPageTitle")); } else { $_clean['assignment']=Database::escape_string($_POST['assignment']); //Juan Carlos Raña for mode assignment if ($_clean['assignment']==1) { auto_add_page_users($_clean['assignment']); } else { $return_message=save_new_wiki(); } } } // displaying the message if there is a message to be displayed if (!empty($return_message)) { Display::display_confirmation_message($return_message, false); } // check last version hack by Juan Carlos Raña if ($_GET['view']) { $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version if ($_GET['view']<$row['id']) { $message= get_lang('NoAreSeeingTheLastVersion'); Display::display_warning_message($message,false); } } if ($_GET['action']=='deletewiki'){ if(api_is_allowed_to_edit() || api_is_platform_admin()) { $message = get_lang('ConfirmDeleteWiki')."

"."

"."".get_lang("No").""."  |  "."".get_lang("Yes").""."

"; if (!isset($_GET['delete'])) { Display::display_warning_message($message,false); } if ($_GET['delete'] == 'yes') { $return_message=delete_wiki(); Display::display_confirmation_message($return_message); } } else { Display::display_normal_message(get_lang("OnlyAdminDeleteWiki")); } } if ($_GET['action']=='discuss' && $_POST['Submit']) { Display::display_confirmation_message(get_lang('CommentAdded')); } /* ----------------------------------------------------------- WIKI WRAPPER ----------------------------------------------------------- */ echo "
"; /* ----------------------------------------------------------- WIKI MENU ----------------------------------------------------------- */ echo "'; /* ----------------------------------------------------------- MAIN WIKI AREA ----------------------------------------------------------- */ echo "
"; /////////////////////// more options /////////////////////// Juan Carlos Raña Trabado if ($_GET['action']=='more') { //to do } /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado if ($_GET['action']=='delete') { if(api_is_allowed_to_edit() || api_is_platform_admin()) { echo '
'; echo ''.get_lang('DeletePageHistory').''; echo '
'; $message = get_lang('ConfirmDeletePage')."

"."

"."".get_lang("No").""."  |  "."".get_lang("Yes").""."

"; if (!isset ($_GET['delete'])) { Display::display_warning_message($message,false); } if ($_GET['delete'] == 'yes') { $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; api_sql_query($sql,__FILE__,__LINE__); //// //here to do: delete discussion and mailcue too /// check_emailcue(0, 'E'); Display::display_confirmation_message(get_lang('WikiPageDeleted')); } } else { Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki")); } } /////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado if ($_GET['action']=='deletewiki') { echo '
'; echo ''.get_lang('DeleteWiki').''; echo '
'; } /////////////////////// search pages /////////////////////// Juan Carlos Raña Trabado if ($_GET['action']=='searchpages') { echo '
'; echo ''.$SearchPages.''; echo '
'; if (!$_POST['Skeyword']) { echo '
'; echo ''; echo '

'; echo ' '.get_lang('AlsoSearchContent'); echo '
'; } else { if($_POST['Scontent']=="1") { $sql="SELECT * FROM ".$tbl_wiki." WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' OR content LIKE '%".$_POST['Skeyword']."%' GROUP BY reflink ORDER BY title ASC"; } else { $sql="SELECT * FROM ".$tbl_wiki." WHERE ".$groupfilter." AND title LIKE '%".$_POST['Skeyword']."%' GROUP BY reflink ORDER BY title ASC"; } //show result $_clean['group_id']=(int)$_SESSION['_gid']; $result=api_sql_query($sql,__LINE__,__FILE__); echo ''; } } /////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado if ($_GET['action']=='links') { echo '
'; echo ''.$LinksPages.''; echo '
'; if (!$_GET['title']) { Display::display_normal_message(get_lang("MustSelectPage")); } else { $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.''; $result=api_sql_query($sql,__FILE__,__LINE__); //necessary for pages with compound name $row=Database::fetch_array($result); echo $LinksPagesFrom.': '.$row['title'].''; if ($page==get_lang('DefaultTitle')) { $page='index'; } $sql="SELECT * FROM ".$tbl_wiki." WHERE ".$groupfilter." AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))."%' GROUP BY reflink ORDER BY title ASC"; $result=api_sql_query($sql,__LINE__,__FILE__); //show result echo ''; } } /////////////////////// adding a new page /////////////////////// // Display the form for adding a new wiki page if ($_GET['action']=='addnew') { //first, check if page index was created. chektitle=false if (checktitle('index')) { Display::display_normal_message(get_lang('GoAndEditMainPage')); } elseif (check_addnewpagelock() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false)) { Display::display_normal_message(get_lang('AddPagesLocked')); } else { if(GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) { if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) { echo '
'; echo ''.get_lang('AddNew').''; echo '
'; display_new_wiki_form(); } else { Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers')); } } else { echo '
'; echo ''.get_lang('AddNew').''; echo '
'; display_new_wiki_form(); } } } /////////////////////// show home page /////////////////////// if (!$_GET['action'] OR $_GET['action']=='show' AND !$_POST['SaveWikiNew']) { display_wiki_entry(); } /////////////////////// show current page /////////////////////// if ($_GET['action']=='showpage' AND !$_POST['SaveWikiNew']) { display_wiki_entry(); } /////////////////////// edit current page /////////////////////// if ($_GET['action']=='edit') { $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher if(($row['reflink']=='index' || $row['assignment']==1) && (!api_is_allowed_to_edit() || !api_is_platform_admin())) { Display::display_normal_message(get_lang('OnlyEditPagesCourseManager')); } else { $PassEdit=false; if(stripslashes($row['assignment'])==1) { Display::display_normal_message(get_lang('EditAssignmentWarning')); $icon_assignment=''.get_lang('AssignmentDescExtra').''; } elseif(stripslashes($row['assignment'])==2) { $icon_assignment=''.get_lang('AssignmentWorkExtra').''; } //check if is a wiki group if($_clean['group_id']!==0) { //Only teacher, platform admin and group members can edit a wiki group if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) { $PassEdit=true; } else { Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers')); } } else { $PassEdit=true; } if($PassEdit) //show editor if edit is allowed { if (check_protect_page() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false)) { Display::display_normal_message(get_lang('PageLockedExtra')); } else { if ($row['content']=='' AND $row['title']=='' AND $page='index') { $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)); $title=get_lang('DefaultTitle'); } else { $content=$row['content']; $title=$row['title']; } echo '
'; echo $icon_assignment.'   '.$title.'
'; echo '
'; echo '
'; echo ''; echo ''; api_disp_html_area('content',stripslashes($content),'300px'); echo '
'; echo '
'; //if(api_is_allowed_to_edit() || api_is_platform_admin()) //off for now //{ echo get_lang('Comments').':     '; //} echo ''; //echo ''; //off for now //echo ''; //off for now echo ''; //get current version echo get_lang('Progress').':   %'; echo '

'; echo ''; echo '
'; echo '
'; } } } } /////////////////////// page history /////////////////////// if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences'])) { $_clean['group_id']=(int)$_SESSION['_gid']; //First, see the property visibility that is at the last register and therefore we should select descending order. But to give ownership to each record, this is no longer necessary except for the title. TO DO: check this $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; $result=api_sql_query($sql,__LINE__,__FILE__); while ($row=Database::fetch_array($result)) { $KeyVisibility=$row['visibility']; $KeyAssignment=$row['assignment']; $KeyTitle=$row['title']; $KeyUserId=$row['user_id']; } if($KeyAssignment==1) { $icon_assignment=''.get_lang('AssignmentDescExtra').''; } elseif($KeyAssignment==2) { $icon_assignment=''.get_lang('AssignmentWorkExtra').''; } //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() || api_is_platform_admin() || ($KeyAssignment==2 && $KeyVisibility==0 && (api_get_user_id()==$KeyUserId))) { // We show the complete history if (!$_POST['HistoryDifferences'] && !$_POST['HistoryDifferences2'] ) { $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; $result=api_sql_query($sql,__LINE__,__FILE__); $title=Security::remove_XSS($_GET['title']); $group_id=Security::remove_XSS($_GET['group_id']); echo '
'; echo $icon_assignment.'   '.$KeyTitle; echo '
'; echo '
'; echo '
'; echo '
    '; echo '
    '; echo ''; echo ''; echo '

    '; $counter=0; $total_versions=Database::num_rows($result); while ($row=Database::fetch_array($result)) { $userinfo=Database::get_user_info_from_id($row['user_id']); $year = substr($row['timestamp'], 0, 4); $month = substr($row['timestamp'], 5, 2); $day = substr($row['timestamp'], 8, 2); $hours=substr($row['timestamp'], 11,2); $minutes=substr($row['timestamp'], 14,2); $seconds=substr($row['timestamp'], 17,2); echo '
  • '; ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle=''; ($counter==0) ? $newchecked=' checked':$newchecked=''; ($counter==$total_versions-1) ? $newstyle='style="visibility: hidden;"':$newstyle=''; ($counter==1) ? $oldchecked=' checked':$oldchecked=''; echo ' '; echo ' '; echo ''; echo ''; echo $day.' '.$MonthsLong[$month-1].' '.$year.' '.$hours.":".$minutes.":".$seconds; echo ''; echo ' ('.get_lang('Version').' '.$row['version'].')'; echo ' ... '; if ($row['user_id']<>0) { echo ''.$userinfo['lastname'].', '.$userinfo['firstname'].''; } else { echo get_lang('Anonymous').' ('.$row[user_ip].')'; } echo ' ... '.get_lang('Progress').': '.$row['progress'].'%'; $comment=$row['comment']; if (!empty($comment)) { echo ' ... '.get_lang('Comments').': '; } else { echo ' ... '. get_lang('Comments').': '; } echo '

  • '; $counter++; } //end while echo ''; echo ''; echo '
'; } // We show the differences between two versions else { $sql_old="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['old'])."'"; $result_old=api_sql_query($sql_old,__LINE__,__FILE__); $version_old=Database::fetch_array($result_old); $sql_new="SELECT * FROM $tbl_wiki WHERE id='".Database::escape_string($_POST['new'])."'"; $result_new=api_sql_query($sql_new,__LINE__,__FILE__); $version_new=Database::fetch_array($result_new); if($_POST['HistoryDifferences']) { include('diff.inc.php'); //title echo '
'.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['timestamp']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['timestamp']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedLine).' '.get_lang(WikiDiffDeletedLine).' '.get_lang(WikiDiffMovedLine).'
'; } if($_POST['HistoryDifferences2']) { require_once 'Text/Diff.php'; require_once 'Text/Diff/Renderer/inline.php'; //title echo '
'.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['timestamp']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['timestamp']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedTex).' '.get_lang(WikiDiffDeletedTex).'
'; } echo '


'; if($_POST['HistoryDifferences']) { echo ''.diff( stripslashes($version_old['content']), stripslashes($version_new['content']), true, 'format_table_line' ).'
'; // format_line mode is better for words echo '
'; echo '
'; echo '
'; echo ''.get_lang('Legend').'
' . "\n"; echo ''; echo ''; echo '
'; echo ''; echo ''.get_lang('WikiDiffUnchangedLine').'
'; echo ''.get_lang('WikiDiffAddedLine').'
'; echo ''.get_lang('WikiDiffDeletedLine').'
'; echo ''.get_lang('WikiDiffMovedLine').'
'; echo '
'; } if($_POST['HistoryDifferences2']) { $lines1 = array(stripslashes($version_old['content'])); //it may not be necessary stripslashes. to do $lines2 = array(stripslashes($version_new['content'])); //it may not be necessary stripslashes. to do $diff = &new Text_Diff($lines1, $lines2); $renderer = &new Text_Diff_Renderer_inline(); echo ''.$renderer->render($diff); // Code inline //echo '
'.html_entity_decode($renderer->render($diff)).'
'; // Html inline. By now, turned off by problems in comparing pages separated by more than one version echo '
'; echo '
'; echo '
'; echo ''.get_lang('Legend').'
' . "\n"; echo ''; echo ''; echo '
'; echo ''; echo ''.get_lang('WikiDiffAddedTex').'
'; echo ''.get_lang('WikiDiffDeletedTex').'
'; echo '
'; } } } } /////////////////////// recent changes /////////////////////// // //rss feed. to do // if ($_GET['action']=='recentchanges') { $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY timestamp DESC LIMIT 0,10'; // last 10 $result=api_sql_query($sql,__LINE__,__FILE__); if (check_notify_all()) { $notify_all= ''.get_lang('FullNotifyByEmail').''.get_lang('NotNotifyChanges').''; } else { $notify_all= ''.get_lang('FullCancelNotifyByEmail').''.get_lang('NotifyChanges').''; } echo '
'; echo ''.get_lang('RecentChanges').' '.$notify_all.'
'; echo '
'; echo ''; } /////////////////////// all pages /////////////////////// if ($_GET['action']=='allpages') { $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY title ASC'; //tasks grouped by reflink instead of tilte, because there may be pages with the same name but with different reflink. This is true of the tasks $result=api_sql_query($sql,__LINE__,__FILE__); echo '
'; echo ''.get_lang('AllPages').''; echo '
'; echo ''; } /////////////////////// discuss pages /////////////////////// if ($_GET['action']=='discuss') { //select page to discuss $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version $id=$row['id']; $wuid=$row['user_id']; $userinfo=Database::get_user_info_from_id($row['user_id']); //check discuss 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').''.get_lang('ShowDiscuss').''; } } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $visibility_disc= ''.get_lang('ShowDiscussExtra').''.get_lang('HideDiscuss').''; } } //check add messages lock. if (check_addlock_discuss()) { $addlock_disc= ''.get_lang('LockDiscussExtra').''.get_lang('UnlockDiscuss').''; } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $addlock_disc= ''.get_lang('UnlockDiscussExtra').''.get_lang('LockDiscuss').''; } } //check add rating lock. Show/Hide list to rating for all student if (check_ratinglock_discuss()) { //Mode assignment: check. to do if(($row['assignment']==2 && $row['ratinglock_disc']==0 && (api_get_user_id()==$row['user_id']))==false) { $ratinglock_disc= ''.get_lang('LockRatingDiscussExtra').''.get_lang('UnlockRatingDiscuss').''; } } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $ratinglock_disc= ''.get_lang('UnlockRatingDiscussExtra').''.get_lang('LockRatingDiscuss').''; } } //check notify by email if (check_notify_discuss($page)) { $notify_disc= ''.get_lang('NotifyDiscussByEmail').''.get_lang('NotifyDiscussChanges').''; } else { $notify_disc= ''.get_lang('CancelNotifyDiscussByEmail').''.get_lang('NotNotifyDiscussChanges').''; } //mode assignment: previous to show page type if(stripslashes($row['assignment'])==1) { $icon_assignment=''.get_lang('AssignmentDescExtra').''; } elseif(stripslashes($row['assignment'])==2) { $icon_assignment=''.get_lang('AssignmentWorkExtra').''; } //Show title and form to discuss if page exist if ($id!='') { //Show discussion to students if isn't hidden. Show page to all teachers if is hidden. Mode assignments: If is hidden, show pages to student only if student is the author if($row['visibility_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))) { echo '
'; echo $icon_assignment.'   '.$row['title'].'
'.''.$addlock_disc.''.'   '.$visibility_disc.''.'   '.$ratinglock_disc.'   '.$notify_disc.'    ('.get_lang('MostRecentVersionBy').''.$userinfo['firstname'].' '.$userinfo['lastname'].' '.$row['timestamp'].$countWPost.')'.$avg_WPost_score.' '; //to do: read avg score echo '
'; if($row['addlock_disc']==1 || api_is_allowed_to_edit() || api_is_platform_admin()) //show comments but students can't add theirs { ?>
';// must pass a default value to avoid rate automatically } ?>
: :
  '; ?>
'; $user_table = Database :: get_main_table(TABLE_MAIN_USER); $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.publication_id='".$id."' AND user.user_id='".$wuid."' ORDER BY id DESC"; $result=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error()); $countWPost = Database::num_rows($result); echo get_lang('NumComments').": ".$countWPost; //comment's numbers $sql="SELECT SUM(p_score) as sumWPost FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-' ORDER BY id DESC"; $result2=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error()); $row2=Database::fetch_array($result2); $sql="SELECT * FROM $tbl_wiki_discuss WHERE publication_id='".$id."' AND NOT p_score='-'"; $result3=api_sql_query($sql,__FILE__,__LINE__) or die(mysql_error()); $countWPost_score= Database::num_rows($result3); echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;// $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10'; echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating $sql='UPDATE '.$tbl_wiki.' SET score="'.Database::escape_string($avg_WPost_score).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; // check if work ok. to do api_sql_query($sql,__FILE__,__LINE__); echo '
'; //echo '
'; while ($row=Database::fetch_array($result)) { $userinfo=Database::get_user_info_from_id($row['userc_id']); if (($userinfo['status'])=="5") { $author_status=get_lang('Student'); } else { $author_status=get_lang('Teacher'); } require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php'); $user_id=$row['userc_id']; $name=$userinfo['lastname']." ".$userinfo['firstname']; $attrb=array(); if ($user_id<>0) { $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $author_photo= ''.$name.''; } else { $author_photo= ''.$name.''; } //stars $p_score=$row['p_score']; switch($p_score){ case 0: $imagerating=''; break; case 1: $imagerating=''; break; case 2: $imagerating=''; break; case 3: $imagerating=''; break; case 4: $imagerating=''; break; case 5: $imagerating=''; break; case 6: $imagerating=''; break; case 7: $imagerating=''; break; case 8: $imagerating=''; break; case 9: $imagerating=''; break; case 10: $imagerating=''; break; } echo '

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo "
'.$author_photo.''.$userinfo['lastname'].', '.$userinfo['firstname'].' ('.$author_status.') '.$row['timestamp'].' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.'
'.$row['comment'].'
"; echo '


'; } // echo"
"; } else { Display::display_warning_message(get_lang('LockByTeacher'),false); } } else { Display::display_normal_message(get_lang('DiscussNotAvailable')); } } echo "
"; // echo "
"; echo "
"; // echo "
"; /* ============================================================================== FOOTER ============================================================================== */ //$_SESSION['_gid']; Display::display_footer(); /* ============================================================================== FUNCTIONS ============================================================================== */ /** * @author Patrick Cool , Ghent University * @desc This function checks weither the proposed reflink is not in use yet. It is a recursive function because every newly created reflink suggestion * has to be checked also */ function createreflink($testvalue) { global $groupfilter; $counter=''; while (!checktitle($testvalue.$counter)) { $counter++; echo $counter."-".$testvalue.$counter."
"; } // the reflink has not been found yet, so it is OK return $testvalue.$counter; } /** * @author Patrick Cool , Ghent University **/ function checktitle($paramwk) { global $tbl_wiki; global $groupfilter; $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($paramwk)))).'" AND '.$groupfilter.''; // to do: check if need entity $result=api_sql_query($sql,__FILE__,__LINE__); $numberofresults=Database::num_rows($result); if ($numberofresults==0) // the value has not been found and is this available { return true; } else // the value has been found { return false; } } /** * @author Juan Carlos Raña * check wikilinks that has a page **/ function links_to($input) { $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE); $all_links = array(); foreach ($input_array as $key=>$value) { if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') { if (strpos($value, "|") !== false) { $full_link_array=explode("|", $value); $link=trim($full_link_array[0]); $title=trim($full_link_array[1]); } else { $link=$value; $title=$value; } unset($input_array[$key-1]); unset($input_array[$key+1]); $all_links[]= Database::escape_string(str_replace(' ','',$link)).' '; //remove blank spaces within the links. But to remove links at the end add a blank space } } $output=implode($all_links); 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 **/ function make_wiki_link_clickable($input) { if (isset($_SESSION['_gid'])) { $_clean['group_id']=(int)$_SESSION['_gid']; } if (isset($_GET['group_id'])) { $_clean['group_id']=(int)Security::remove_XSS($_GET['group_id']); } $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE); //now doubles brackets foreach ($input_array as $key=>$value) { if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') //now doubles brackets { if ($_clean['group_id']==0) { $titleg_ex=''; } else { $titleg_ex='(g'.$_clean['group_id'].')'; } //now full wikilink if (strpos($value, "|") !== false) { $full_link_array=explode("|", $value); $link=trim($full_link_array[0]); $title=trim($full_link_array[1]); } else { $link=$value; $title=$value; } //if wikilink is homepage if($link=='index'){ $title=get_lang('DefaultTitle'); } if ($link==get_lang('DefaultTitle')){ $link='index'; } // note: checkreflink checks if the link is still free. If it is not used then it returns true, if it is used, then it returns false. Now the title may be different if (checktitle(strtolower(str_replace(' ','',$link)))) { $input_array[$key]=''.$title.$titleg_ex.''; } else { $input_array[$key]=''.$title.$titleg_ex.''; } unset($input_array[$key-1]); unset($input_array[$key+1]); } } $output=implode('',$input_array); return $output; } /** * This function saves a change in a wiki page * @author Patrick Cool , Ghent University * @return language string saying that the changes are stored **/ function save_wiki() { global $tbl_wiki; // cleaning the variables $_clean['reflink']=Database::escape_string($_POST['reflink']); $_clean['title']=Database::escape_string($_POST['title']); $_clean['content']= html_entity_decode(Database::escape_string(stripslashes(urldecode($_POST['content'])))); $_clean['user_id']=(int)Database::escape_string(api_get_user_id()); $_clean['assignment']=Database::escape_string($_POST['assignment']); $_clean['comment']=Database::escape_string($_POST['comment']); $_clean['progress']=Database::escape_string($_POST['progress']); $_clean['startdate_assig']=Database::escape_string($_POST['startdate_assig']); $_clean['enddate_assig']=Database::escape_string($_POST['enddate_assig']); $_clean['version']=Database::escape_string($_POST['version'])+1; $_clean['linksto'] = links_to($_clean['content']); //and check links content if (isset($_SESSION['_gid'])) { $_clean['group_id']=Database::escape_string($_SESSION['_gid']); } if (isset($_GET['group_id'])) { $_clean['group_id']=Database::escape_string($_GET['group_id']); } if ($_clean['group_id']) { $sql="INSERT INTO ".$tbl_wiki." (reflink, title,content,user_id, group_id, assignment, comment, progress, startdate_assig, enddate_assig, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['version']."','".$_clean['linksto']."','".$_SERVER['REMOTE_ADDR']."')"; } else { $sql="INSERT INTO ".$tbl_wiki." (reflink, title,content,user_id, assignment, comment, progress, startdate_assig, enddate_assig, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['version']."','".$_clean['linksto']."','".$_SERVER['REMOTE_ADDR']."')"; } $result=api_sql_query($sql); $Id = Database::insert_id(); api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id()); check_emailcue($_clean['reflink'], 'P'); return get_lang('ChangesStored'); } /** * This function delete a wiki * @author Juan Carlos Raña **/ function delete_wiki() { global $tbl_wiki, $tbl_discuss, $groupfilter; api_sql_query('DELETE FROM '.$tbl_wiki.' WHERE '.$groupfilter.'',__FILE__,__LINE__); //to do: delete discuss and mailcue 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. **/ function save_new_wiki() { global $tbl_wiki; global $assig_user_id; //need for assignments mode // cleaning the variables $_clean['assignment']=Database::escape_string($_POST['assignment']); if($_clean['assignment']==2 || $_clean['assignment']==1) // Unlike ordinary pages of pages of assignments. Allow create a ordinary page although there is a assignment with the same name { $_clean['reflink']=Database::escape_string(str_replace(' ','',$_POST['title']."_uass".$assig_user_id)); } else { $_clean['reflink']=Database::escape_string(str_replace(' ','',$_POST['title'])); } $_clean['title']=Database::escape_string($_POST['title']); $_clean['content']= html_entity_decode(Database::escape_string(stripslashes(urldecode($_POST['content'])))); if($_clean['assignment']==2) // for automatic assignment. Identifies the user as a creator, not the teacher who created { $_clean['user_id']=(int)Database::escape_string($assig_user_id); } else { $_clean['user_id']=(int)Database::escape_string(api_get_user_id()); } $_clean['comment']=Database::escape_string($_POST['comment']); $_clean['progress']=Database::escape_string($_POST['progress']); $_clean['startdate_assig']=Database::escape_string($_POST['startdate_assig']); $_clean['enddate_assig']=Database::escape_string($_POST['enddate_assig']); $_clean['version']=1; if (isset($_SESSION['_gid'])) { $_clean['group_id']=(int)$_SESSION['_gid']; } if (isset($_GET['group_id'])) { $_clean['group_id']=(int)Database::escape_string($_GET['group_id']); } $_clean['linksto'] = links_to($_clean['content']); //check wikilinks //filter no _uass if(eregi("_uass",$_POST['title']) || (strtoupper(trim($_POST['title']))==strtoupper ('index') || strtoupper(trim(htmlentities($_POST['title'])))==strtoupper(htmlentities(get_lang('DefaultTitle'))))) { $message= get_lang('GoAndEditMainPage'); Display::display_warning_message($message,false); } else { $var=$_clean['reflink']; $group_id=Security::remove_XSS($_GET['group_id']); if(!checktitle($var)) { return get_lang('WikiPageTitleExist').''.$_POST['title'].''; } else { if ($_clean['group_id']) { $sql="INSERT INTO ".$tbl_wiki." (reflink, title, content, user_id, group_id, assignment, comment, progress, startdate_assig, enddate_assig, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['version']."','".$_clean['linksto']."','".$_SERVER['REMOTE_ADDR']."')"; } else { $sql="INSERT INTO ".$tbl_wiki." (reflink, title,content,user_id, assignment, comment, progress, startdate_assig, enddate_assig, version, linksto, user_ip) VALUES ('".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['version']."','".$_clean['linksto']."','".$_SERVER['REMOTE_ADDR']."')"; } $result=api_sql_query($sql,__LINE__,__FILE__); $Id = Database::insert_id(); api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id()); check_emailcue(0, 'A'); return get_lang('NewWikiSaved').''.$_POST['title'].''; } }//end filter no _uass } /** * This function displays the form for adding a new wiki page. * @author Patrick Cool , Ghent University * @return html code **/ function display_new_wiki_form() { ?> '; echo '
'; echo get_lang(Title).': '; if(api_is_allowed_to_edit() || api_is_platform_admin()) { //by now only on wiki course $_clean['group_id']=(int)$_SESSION['_gid']; if($_clean['group_id']==0) { echo '    '.get_lang('DefineAssignmentPage').' '; // 1 teacher 2 student //echo'
';//by now turned off //echo ' Start. Date and time: (yyyy-mm-dd hh:mm:ss)'; //by now turned off //echo ' End. Date and time: (yyyy-mm-dd hh:mm:ss)'; //by now turned off //echo'
'; } } echo '
'; echo '
'; api_disp_html_area('content','','300px'); echo '
'; echo '
'; echo get_lang('Comments').':     '; echo get_lang('Progress').':   %'; echo '

'; echo ''; echo '
'; echo ''; } /** * This function displays a wiki entry * @author Patrick Cool , Ghent University * @return html code **/ function display_wiki_entry() { global $tbl_wiki; global $groupfilter; global $page; $_clean['group_id']=(int)$_SESSION['_gid']; if ($_GET['view']) { $_clean['view']=(int)Database::escape_string($_GET['view']); $filter=" AND id='".$_clean['view']."'"; } //first, check page visibility in the first page version $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $KeyVisibility=$row['visibility']; // second, show the last version $sql="SELECT * FROM ".$tbl_wiki."WHERE reflink='".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))."' AND $groupfilter $filter ORDER BY id DESC"; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version // if both are empty and we are displaying the index page then we display the default text. if ($row['content']=='' AND $row['title']=='' AND $page='index') { $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)); $title=get_lang('DefaultTitle'); } else { $content=$row['content']; $title=$row['title']; } //Button lock add new pages if (check_addnewpagelock()) { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $protect_addnewpage= ''.get_lang('AddOptionProtected').''.get_lang('ShowAddOption').''; } } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $protect_addnewpage= ''.get_lang('AddOptionUnprotected').''.get_lang('HideAddOption').''; } } //Button lock page if (check_protect_page()) { $protect_page= ''.get_lang('PageLockedExtra').''.get_lang('PageUnlocked').''; } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $protect_page= ''.get_lang('PageUnlockedExtra').''.get_lang('PageLocked').''; } } //Button visibility page 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').''.get_lang('ShowPage').''; } } else { if(api_is_allowed_to_edit() || api_is_platform_admin()) { $visibility_page= ''.get_lang('ShowPageExtra').''.get_lang('HidePage').''; } } //Button notify page if (check_notify_page($page)) { $notify_page= ''.get_lang('NotifyByEmail').''.get_lang('NotNotifyChanges').''; } else { $notify_page= ''.get_lang('CancelNotifyByEmail').''.get_lang('NotifyChanges').''; } //assignment mode: for identify page type if(stripslashes($row['assignment'])==1) { $icon_assignment=''.get_lang('AssignmentDescExtra').''; } elseif(stripslashes($row['assignment'])==2) { $icon_assignment=''.get_lang('AssignmentWorkExtra').''; } //Show page. Show page to all users if isn't hide page. Mode assignments: if studen is the author, can view if($KeyVisibility=="1" || api_is_allowed_to_edit() || api_is_platform_admin() || ($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))) { echo '
'; if (empty($title)) { $title=get_lang('DefaultTitle'); } if (wiki_exist($title)) { echo $icon_assignment.'   '.stripslashes($title).'
'.$protect_addnewpage.'
'.'   '.$protect_page.''.'   '.$visibility_page.''.'   '.$notify_page.''.'   '.get_lang('Progress').': '.stripslashes($row['progress']).'%   '.get_lang('Rating').': '.stripslashes($row['score']); } else { echo stripslashes($title); } //export to pdf echo ''; echo '
'; // also with export_tcpdf.php echo ''; echo ''; echo ''; echo '
'; echo '
'; //copy last version to doc area echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; //export to print ?> '; echo ''.get_lang('Print').''; echo ''; //export to zip echo ''.get_lang('Export2ZIP').''; //to do. echo '
'; echo '
'.make_wiki_link_clickable(stripslashes($content)).'
'; }//end filter visibility } // end function display_wiki_entry //more for export to course document area. See display_wiki_entry if ($_POST['export2DOC']) { $titleDOC=$_POST['titleDOC']; $contentDOC=$_POST['contentDOC']; //check. to do. $groupIdDOC=$_clean['group_id']; export2doc($titleDOC,$contentDOC,$groupIdDOC); } /** * This function checks if wiki title exist */ function wiki_exist($title) { global $tbl_wiki; global $groupfilter; $sql='SELECT id FROM '.$tbl_wiki.'WHERE title="'.Database::escape_string($title).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $cant=Database::num_rows($result); if ($cant>0) return true; else return false; } /** * This function a wiki warning * @author Patrick Cool , Ghent University * @return html code **/ function display_wiki_warning($variable) { echo '
'.$variable.'
'; } /** * Checks if this navigation tab has to be set to active * @author Patrick Cool , Ghent University * @return html code */ function is_active_navigation_tab($paramwk) { if ($_GET['action']==$paramwk) { return ' class="active"'; } } /** * Lock add pages * @author Juan Carlos Raña */ function check_addnewpagelock() { global $tbl_wiki; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_addlock=$row['addlock']; //change status if ($_GET['actionpage']=='addlock' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['addlock']==1) { $status_addlock=0; } else { $status_addlock=1; } api_sql_query('UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string($status_addlock).'" WHERE '.$groupfilter.'',__LINE__,__FILE__); $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['addlock']==1 || ($row['content']=='' AND $row['title']=='' AND $page='index')) { return false; } else { return true; } } /** * Protect page * @author Juan Carlos Raña */ function check_protect_page() { global $tbl_wiki; global $page; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_editlock=$row['editlock']; $id=$row['id']; ///change status if ($_GET['actionpage']=='lock' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['editlock']==0) { $status_editlock=1; } else { $status_editlock=0; } $sql='UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string($status_editlock).'" WHERE id="'.$id.'"'; api_sql_query($sql,__FILE__,__LINE__); $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['editlock']==0 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) { return false; } else { return true; } } /** * Visibility page * @author Juan Carlos Raña */ function check_visibility_page() { global $tbl_wiki; global $page; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_visibility=$row['visibility']; $id=$row['id']; //need ? check. to do //change status if ($_GET['actionpage']=='visibility' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['visibility']==1) { $status_visibility=0; } else { $status_visibility=1; } $sql='UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string($status_visibility).'" WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter; api_sql_query($sql,__FILE__,__LINE__); //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 reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['visibility']=="1" || ($row['content']=='' AND $row['title']=='' AND $page=='index')) { return false; } else { return true; } } /** * Visibility discussion * @author Juan Carlos Raña */ function check_visibility_discuss() { global $tbl_wiki; global $page; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_visibility_disc=$row['visibility_disc']; $id=$row['id']; //need ? check. to do //change status if ($_GET['actionpage']=='visibility_disc' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['visibility_disc']==1) { $status_visibility_disc=0; } else { $status_visibility_disc=1; } $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; api_sql_query($sql,__FILE__,__LINE__); //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 reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['visibility_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) { return false; } else { return true; } } /** * Lock add discussion * @author Juan Carlos Raña */ function check_addlock_discuss() { global $tbl_wiki; global $page; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_addlock_disc=$row['addlock_disc']; $id=$row['id']; //need ? check. to do //change status if ($_GET['actionpage']=='addlock_disc' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['addlock_disc']==1) { $status_addlock_disc=0; } else { $status_addlock_disc=1; } $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; api_sql_query($sql,__FILE__,__LINE__); //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 reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['addlock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) { return false; } else { return true; } } /** * Lock rating discussion * @author Juan Carlos Raña */ function check_ratinglock_discuss() { global $tbl_wiki; global $page; global $groupfilter; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $status_ratinglock_disc=$row['ratinglock_disc']; $id=$row['id']; //need ? check. to do //change status if ($_GET['actionpage']=='ratinglock_disc' && (api_is_allowed_to_edit() || api_is_platform_admin())) { if ($row['ratinglock_disc']==1) { $status_ratinglock_disc=0; } else { $status_ratinglock_disc=1; } $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 api_sql_query($sql,__FILE__,__LINE__); //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 reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); } //show status if ($row['ratinglock_disc']==1 || ($row['content']=='' AND $row['title']=='' AND $page=='index')) { return false; } else { return true; } } /** * Notify page changes * @author Juan Carlos Raña */ function check_notify_page($reflink) { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $id=$row['id']; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $idm=$row['id']; if (empty($idm)) { $status_notify=0; } else { $status_notify=1; } //change status if ($_GET['actionpage']=='notify') { if ($status_notify==0) { $sql="INSERT INTO ".$tbl_wiki_mailcue." (id, user_id, type, group_id) VALUES ('".$id."','".api_get_user_id()."','P','".$_clean['group_id']."')"; api_sql_query($sql,__FILE__,__LINE__); $status_notify=1; } else { $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"'; //$_clean['group_id'] not necessary api_sql_query($sql,__FILE__,__LINE__); $status_notify=0; } } //show status if ($status_notify==0) { return false; } else { return true; } } /** * Notify discussion changes * @author Juan Carlos Raña */ function check_notify_discuss($reflink) { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $id=$row['id']; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $idm=$row['id']; if (empty($idm)) { $status_notify_disc=0; } else { $status_notify_disc=1; } //change status if ($_GET['actionpage']=='notify_disc') { if ($status_notify_disc==0) { if (!$_POST['Submit']) { $sql="INSERT INTO ".$tbl_wiki_mailcue." (id, user_id, type, group_id) VALUES ('".$id."','".api_get_user_id()."','D','".$_clean['group_id']."')"; api_sql_query($sql,__FILE__,__LINE__); $status_notify_disc=1; } else { $status_notify_disc=0; } } else { if (!$_POST['Submit']) { $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"'; //$_clean['group_id'] not necessary api_sql_query($sql,__FILE__,__LINE__); $status_notify_disc=0; } else { $status_notify_disc=1; } } } //show status if ($status_notify_disc==0) { return false; } else { return true; } } /** * Notify all changes * @author Juan Carlos Raña */ function check_notify_all() { global $tbl_wiki_mailcue; $_clean['group_id']=(int)$_SESSION['_gid']; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $idm=$row['user_id']; if (empty($idm)) { $status_notify_all=0; } else { $status_notify_all=1; } //change status if ($_GET['actionpage']=='notify_all') { if ($status_notify_all==0) { $sql="INSERT INTO ".$tbl_wiki_mailcue." (user_id, type, group_id) VALUES ('".api_get_user_id()."','F','".$_clean['group_id']."')"; api_sql_query($sql,__FILE__,__LINE__); $status_notify_all=1; } else { $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; api_sql_query($sql,__FILE__,__LINE__); $status_notify_all=0; } } //show status if ($status_notify_all==0) { return false; } else { return true; } } /** * Function check emailcue and send email when a page change * @author Juan Carlos Raña */ function check_emailcue($id_or_ref, $type) { global $tbl_wiki; global $groupfilter; global $tbl_wiki_mailcue; global $_course; $_clean['group_id']=(int)$_SESSION['_gid']; $group_properties = GroupManager :: get_group_properties($_clean['group_id']); $group_name= $group_properties['name']; if ($type=='P') { //if modifying a wiki page $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$id_or_ref.'" AND '.$groupfilter.' ORDER BY id ASC'; $result=api_sql_query($sql,__LINE__,__FILE__); $row=Database::fetch_array($result); $id=$row['id']; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full $result=api_sql_query($sql,__LINE__,__FILE__); $emailtext=get_lang('EmailWikipageModified'); } elseif ($type=='D') { //if added a post to discuss $id=$id_or_ref; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full $result=api_sql_query($sql,__LINE__,__FILE__); $emailtext=get_lang('EmailWikiPageDiscAdded'); } elseif($type=='A') { //for added pages $id=0; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=full $result=api_sql_query($sql,__LINE__,__FILE__); $emailtext=get_lang('EmailWikiPageAdded'); } elseif($type=='E') { $id=0; $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'"'; //type: P=page, D=discuss, F=wiki $result=api_sql_query($sql,__LINE__,__FILE__); $emailtext=get_lang('EmailWikipageDedeleted'); } //TODO: if visibility off turn notify off ? //make and send email while ($row=Database::fetch_array($result)) { if(empty($charset)){$charset='ISO-8859-1';} $headers = 'Content-Type: text/html; charset='. $charset; $userinfo=Database::get_user_info_from_id($row['user_id']); $name_to=$userinfo['firstname'].' '.$userinfo['lastname']; $email_to=$userinfo['email']; $sender_name=get_setting('emailAdministrator'); $sender_email=get_setting('emailAdministrator'); $email_subject = get_lang('EmailWikiChanges').' - '.$_course['official_code']; $email_body= get_lang('DearUser').' '.$userinfo['firstname'].' '.$userinfo['lastname'].',

\n\r'; $email_body .= $emailtext.' '.$_course['name'].' - '.$group_name.'


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

\n'; api_mail_html($name_to, $email_to, $email_subject, $email_body, $sender_name, $sender_email, $headers); } } /** * Function export last wiki page version to document area * @author Juan Carlos Raña */ function export2doc($wikiTitle, $wikiContents, $groupId) { if ( 0 != $groupId) { $groupPart = '_group' . $groupId; // and add groupId to put the same title document in different groups $group_properties = GroupManager :: get_group_properties($groupId); $groupPath = $group_properties['directory']; } else { $groupPart = ''; $groupPath =''; } require_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php'); require_once (api_get_path(LIBRARY_PATH).'document.lib.php'); $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath; $exportFile = replace_dangerous_char( $wikiTitle, 'strict' ) . $groupPart; $i = 1; while ( file_exists($exportDir . '/' .$exportFile.'_'.$i.'.html') ) $i++; //only export last version, but in new export new version in document area $wikiFileName = $exportFile . '_' . $i . '.html'; $exportPath = $exportDir . '/' . $wikiFileName; $wikiContents = stripslashes($wikiContents); file_put_contents( $exportPath, $wikiContents ); $doc_id = add_document($_course, $groupPath.'/'.$wikiFileName,'file',filesize($exportPath),$wikiFileName); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId); // to do: link to go document area } /** * Function wizard individual assignment * @author Juan Carlos Raña */ function auto_add_page_users($assignment_type) { global $assig_user_id; //need to identify end reflinks //extract course members if(!empty($_SESSION["id_session"])){ $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true, $_SESSION['id_session']); } else { $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true); } $all_students_pages = array(); //data about teacher $userinfo=Database::get_user_info_from_id(api_get_user_id()); require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php'); if (api_get_user_id()<>0) { $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $photo= ''.$name.''; } else { $photo= ''.$name.''; } //teacher assignement title $title_orig=$_POST['title']; //teacher assignement reflink $link2teacher=$_POST['title']= $title_orig."_uass".api_get_user_id(); //first: teacher name, photo, and assignment description (original content) $content_orig_A='
'.$photo.get_lang('Teacher').': '.$userinfo['firstname'].$userinfo['lastname'].'

'; $content_orig_B='

'.get_lang('AssignmentDescription').'


'.$_POST['content']; //Second: student list (names, photo and links to their works). //Third: Create Students work pages. foreach($a_course_users as $user_id=>$o_course_user) { if($o_course_user['user_id'] != api_get_user_id()) //except that puts the task { $assig_user_id= $o_course_user['user_id']; //identifies each page as created by the student, not by teacher $image_path = UserManager::get_user_picture_path_by_id($assig_user_id,'web',false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $name= $o_course_user['lastname'].', '.$o_course_user['firstname']; $photo= ''.$name.''; if($assignment_type==1) { $_POST['title']= $title_orig; $_POST['comment']=get_lang('AssignmentFirstComToStudent'); $_POST['content']='
'.$photo.get_lang('Student').': '.$name.'
[['.$link2teacher.' | '.get_lang('AssignmentLinktoTeacherPage').']] '.$content_orig_B; //AssignmentLinktoTeacherPage $all_students_pages[] = '
  • '.$o_course_user['lastname'].', '.$o_course_user['firstname'].' [['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']]
  • '; $_POST['assignment']=2; } save_new_wiki(); } }//end foreach for each user foreach($a_course_users as $user_id=>$o_course_user) { if($o_course_user['user_id'] == api_get_user_id()) { $assig_user_id=$o_course_user['user_id']; if($assignment_type==1) { $_POST['title']= $title_orig; $_POST['comment']=get_lang('AssignmentDesc'); sort($all_students_pages); $_POST['content']=$content_orig_A.$content_orig_B.'
    '.get_lang('AssignmentLinkstoStudentsPage').'
    '.$title_orig.'
      '.implode($all_students_pages).'

    '; $_POST['assignment']=1; } save_new_wiki(); } } //end foreach to teacher } ?>