diff --git a/main/wiki/export_html2pdf.php b/main/wiki/export_html2pdf.php index ff85298d44..fdcdb54596 100644 --- a/main/wiki/export_html2pdf.php +++ b/main/wiki/export_html2pdf.php @@ -88,6 +88,7 @@ $html2pdf->pdf->SetAuthor('Wiki Dokeos'); $html2pdf->pdf->SetTitle($titlePDF); $html2pdf->pdf->SetSubject('Exported from Dokeos Wiki'); $html2pdf->pdf->SetKeywords('Dokeos Wiki'); -$html2pdf->WriteHTML(utf8_decode($htmlbuffer)); +//$html2pdf->WriteHTML(utf8_decode($htmlbuffer)); +$html2pdf->WriteHTML($htmlbuffer); $html2pdf->Output($titlePDF.'.pdf', 'D'); ?> \ No newline at end of file diff --git a/main/wiki/index.php b/main/wiki/index.php index 7c2ff6084d..4e33a2052c 100644 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -1,2094 +1,2098 @@ -, Ghent University, Belgium -* @Author Juan Carlos Raña -* @Copyright Ghent University -* @Copyright Patrick Cool -* -* @package dokeos.wiki -*/ - - -// name of the language file that needs to be included -$language_file = 'wiki'; - -// security -if(isset($_GET['id_session'])) -{ - $_SESSION['id_session'] = Security::remove_XSS($_GET['id_session']); -} - -// including the global dokeos file -include('../inc/global.inc.php'); - -// section (for the tabs) -$this_section=SECTION_COURSES; - -// including additional library scripts - -require_once (api_get_path(LIBRARY_PATH).'course.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'text.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php'); -require_once (api_get_path(LIBRARY_PATH).'security.lib.php'); -require_once (api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php'); -require_once (api_get_path(INCLUDE_PATH).'conf/mail.conf.php'); -require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); -require_once 'wiki.inc.php'; - -// additional style information -$htmlHeadXtra[] =''; - -// Database table definition -$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.php", "name" => get_lang('Groups')); - $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'].'"'; - - //ensure this tool in groups whe it's private or deactivated - if ($group_properties['wiki_state']==0) - { - echo api_not_allowed(); - } - elseif ($group_properties['wiki_state']==2) - { - if (!api_is_allowed_to_edit() and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) - { - echo api_not_allowed(); - } - } - -} -else -{ - $groupfilter='group_id=0'; -} - -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 - -/* -============================================================================== -MAIN CODE -============================================================================== -*/ - -// Tool introduction -Display::display_introduction_section(TOOL_WIKI); - -/* ------------------------------------------------------------ -Wiki configuration settings ------------------------------------------------------------ -*/ - -$fck_attribute['Width'] = '100%'; -$fck_attribute['Height'] = '400'; -if(!api_is_allowed_to_edit()) -{ - $fck_attribute['Config']['UserStatus'] = 'student'; - $fck_attribute['ToolbarSet'] = 'Wiki_Student'; -} -else -{ - $fck_attribute['ToolbarSet'] = 'Wiki'; -} - -/* ------------------------------------------------------------ - ACTIONS ------------------------------------------------------------ -*/ - - -//release of blocked pages to prevent concurrent editions -$sql='SELECT * FROM '.$tbl_wiki.'WHERE is_editing!="0"'; -$result=api_sql_query($sql,__LINE__,__FILE__); -while ($is_editing_block=Database::fetch_array($result)) -{ - $max_edit_time=1200; // 20 minutes - $timestamp_edit=convert_date_to_number($is_editing_block['time_edit']); - $time_editing=time()-$timestamp_edit; - - - //first prevent concurrent users and double version - if($is_editing_block['is_editing']==$_user['user_id']) - { - $_SESSION['_version']=$is_editing_block['version']; - } - else - { - unset ( $_SESSION['_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']==$_user['user_id'] && $_GET['action']!='edit')) - { - $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" WHERE is_editing="'.$is_editing_block['is_editing'].'"'; - api_sql_query($sql,__FILE__,__LINE__); - } - -} - - -// saving a change -if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') -{ - - if(empty($_POST['title'])) - { - Display::display_error_message(get_lang("NoWikiPageTitle")); - } - elseif(!double_post($_POST['wpost_id'])) - { - //double post - } - elseif ($_POST['version']!=$_SESSION['_version']) - { - //prevent concurrent users and double version - Display::display_error_message(get_lang("EditedByAnotherUser")); - } - - else - { - $return_message=save_wiki(); - Display::display_confirmation_message($return_message, false); - } -} - -//saving a new wiki entry -if (isset($_POST['SaveWikiNew'])) -{ - if(empty($_POST['title'])) - { - Display::display_error_message(get_lang("NoWikiPageTitle")); - } - elseif(!double_post($_POST['wpost_id'])) - { - //double post - } - else - { - $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment - if ($_clean['assignment']==1) - { - auto_add_page_users($_clean['assignment']); - } - else - { - $return_message=save_new_wiki(); - Display::display_confirmation_message($return_message, false); - } - } -} - - -// check last version -if ($_GET['view']) -{ - $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.Database::escape_string($_GET['view']).'"'; //current view - $result=api_sql_query($sql,__LINE__,__FILE__); - $current_row=Database::fetch_array($result); - - $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; //last version - $result=api_sql_query($sql,__LINE__,__FILE__); - $last_row=Database::fetch_array($result); - - if ($_GET['view']<$last_row['id']) - { - $message= '
'.get_lang('NoAreSeeingTheLastVersion').'
'.get_lang("Version").' ('.$current_row['version'].' / '.$last_row['version'].')
'.get_lang("ConvertToLastVersion").': '.get_lang("Restore").'
'; - - Display::display_warning_message($message,false); - } - - ///restore page - if ($_GET['action']=='restorepage') - { - //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())) - { - Display::display_normal_message(get_lang('OnlyEditPagesCourseManager')); - } - elseif($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id']) - { - //checking for concurrent users - $timestamp_edit=convert_date_to_number($last_row['time_edit']); - $time_editing=time()-$timestamp_edit; - $max_edit_time=1200; // 20 minutes - $rest_time=$max_edit_time-$time_editing; - - $userinfo=Database::get_user_info_from_id($last_row['is_editing']); - - $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '.$userinfo['lastname'].', '.$userinfo['firstname'].'. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').''; - Display::display_normal_message($is_being_edited); - } - else - { - $PassEdit=false; - - //check if is a wiki group - if($current_row['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; - } - - // check if is an assignment - if(stripslashes($current_row['assignment'])==1) - { - Display::display_normal_message(get_lang('EditAssignmentWarning')); - $icon_assignment=''.get_lang('AssignmentDescExtra').''; - } - elseif(stripslashes($current_row['assignment'])==2) - { - $icon_assignment=''.get_lang('AssignmentWorkExtra').''; - if((api_get_user_id()==$current_row['user_id'])==false) - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $PassEdit=true; - } - else - { - Display::display_warning_message(get_lang('LockByTeacher')); - $PassEdit=false; - } - } - 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 - { - Display::display_confirmation_message(restore_wikipage($current_row['reflink'], $current_row['title'], $current_row['content'], $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': '.$last_row['title'].'',false); - } - } - } - } -} - - -if ($_GET['action']=='deletewiki'){ - - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - if ($_GET['delete'] == 'yes') - { - $return_message=delete_wiki(); - Display::display_confirmation_message($return_message); - } - } -} - - -if ($_GET['action']=='discuss' && $_POST['Submit']) -{ - Display::display_confirmation_message(get_lang('CommentAdded')); -} - - -/* ------------------------------------------------------------ -WIKI WRAPPER ------------------------------------------------------------ -*/ - -echo "
"; - -/** Actions bar (= action of the wiki tool, not of the page)**/ -echo ''; - - -/* ------------------------------------------------------------ -MAIN WIKI AREA ------------------------------------------------------------ -*/ - -echo "
"; -/** menuwiki (= actions of the page, not of the wiki tool) **/ -if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted'))) -{ - echo "'; -} - -/////////////////////// more options /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='more') -{ - - echo '
'.get_lang('More').'
'; - - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - //TODO: config area and private stats - - } - - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo ''; - echo ''; - echo ''; - echo'
'; - - - //Submenu Most linked pages - //echo '
  • '.get_lang('MostLinkedPages').'
  • ';//TODO - - //Submenu Dead end pages - //echo '
  • '.get_lang('DeadEndPages').'
  • ';//TODO - - //Submenu Most new pages (not versions) - //echo '
  • '.get_lang('MostNewPages').'
  • ';//TODO - - //Submenu Most long pages - //echo '
  • '.get_lang('MostLongPages').'
  • ';//TODO - - //Submenu Protected pages - //echo '
  • '.get_lang('ProtectedPages').'
  • ';//TODO - - //Submenu Hidden pages - //echo '
  • '.get_lang('HiddenPages').'
  • ';//TODO - - //Submenu Most discuss pages - //echo '
  • '.get_lang('MostDiscussPages').'
  • ';//TODO - - //Submenu Best scored pages - //echo '
  • '.get_lang('BestScoredPages').'
  • ';//TODO - - //Submenu Pages with more progress - //echo '
  • '.get_lang('MProgressPages').'
  • ';//TODO - - //Submenu Most active users in discuss - //echo '
  • '.get_lang('MostDiscussUsers').'
  • ';//TODO - - //Submenu Individual assignments - //echo '
  • '.get_lang('Assignments').'
  • ';//TODO - - //Submenu Delayed assignments - //echo '
  • '.get_lang('DelayedAssignments').'
  • ';//TODO - - //Submenu Random page - //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO - -} - -/////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='mactiveusers') -{ - echo '
    '.get_lang('MostActiveUsers').'
    '; - - $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY user_id'; - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - $userinfo=Database::get_user_info_from_id($obj->user_id); - $row = array (); - - $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; - $row[] =''.$obj->NUM_EDIT.''; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Author'), true, array ('style' => 'width:30px;')); - $table->set_header(1,get_lang('Contributions'), true); - $table->display(); - } -} - - -/////////////////////// User contributions /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='usercontrib') -{ - $userinfo=Database::get_user_info_from_id(Security::remove_XSS($_GET['user_id'])); - - echo ''; - - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'"'; - } - else - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'" AND visibility=1'; - } - - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get author - $userinfo=Database::get_user_info_from_id($obj->user_id); - - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; - $row[] =$ShowAssignment; - - $row[] = ''.$obj->title.''; - $row[] =$obj->version; - $row[] =$obj->comment; - //$row[] = api_strlen($obj->comment)>30 ? api_substr($obj->comment,0,30).'...' : $obj->comment; - $row[] =$obj->progress.' %'; - $row[] =$obj->score; - //if(api_is_allowed_to_edit() || api_is_platform_admin()) - //{ - //$row[] =$obj->user_ip; - //} - - $rows[] = $row; - - } - - $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'user_id'=>Security::remove_XSS($_GET['user_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - - $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;')); - $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;')); - $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;')); - $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;')); - $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;')); - $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;')); - //if(api_is_allowed_to_edit() || api_is_platform_admin()) - //{ - //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;')); - //} - - $table->display(); - } -} - -/////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='mostchanged') -{ - echo '
    '.get_lang('MostChangedPages').'
    '; - - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink'; - } - else - { - $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink'; - } - - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] =$ShowAssignment; - $row[] = ''.$obj->title.''; - $row[] = $obj->MAX; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(1,get_lang('Title'), true); - $table->set_header(2,get_lang('Changes'), true); - $table->display(); - } - -} - -/////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='mvisited') -{ - echo '
    '.get_lang('MostVisitedPages').'
    '; - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink'; - } - else - { - $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink'; - } - - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] =$ShowAssignment; - $row[] = ''.$obj->title.''; - $row[] = $obj->tsum; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(1,get_lang('Title'), true); - $table->set_header(2,get_lang('Visits'), true); - $table->display(); - } -} - -/////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='wanted') -{ - echo '
    '.get_lang('WantedPages').'
    '; - - $pages = array(); - $refs = array(); - $sort_wanted=array(); - - //get name pages - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - while ($row=Database::fetch_array($allpages)) - { - $pages[] = $row['reflink']; - } - - //get name refs in last pages and make a unique list - $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; - $allpages=api_sql_query($sql,__FILE__,__LINE__); - while ($row=Database::fetch_array($allpages)) - { - //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check - $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " " - $refs = array_merge($refs, $rf); - if ($n++ > 299) - { - $refs = array_unique($refs); - $n=0; - } // (clean-up only every 300th loop). Thanks to Erfurt Wiki - } - - //sort linksto. Find linksto into reflink. If not found ->page is wanted - natcasesort($refs); - echo '
      '; - foreach($refs as $v) - { - if(!in_array($v, $pages)) - { - if (trim($v)!="") - { - echo '
    • '.str_replace('_',' ',$v).'
    • '; - } - } - } - echo '
    '; -} - -/////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='orphaned') -{ - echo '
    '.get_lang('OrphanedPages').'
    '; - - $pages = array(); - $refs = array(); - $orphaned = array(); - - //get name pages - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; - $allpages=api_sql_query($sql,__FILE__,__LINE__); - while ($row=Database::fetch_array($allpages)) - { - $pages[] = $row['reflink']; - } - - //get name refs in last pages and make a unique list - $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; - $allpages=api_sql_query($sql,__FILE__,__LINE__); - while ($row=Database::fetch_array($allpages)) - { - //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check - $rf = explode(" ", trim($row["linksto"])); //fix replace explode("\n", trim($row["linksto"])) with explode(" ", trim($row["linksto"])) - - $refs = array_merge($refs, $rf); - if ($n++ > 299) - { - $refs = array_unique($refs); - $n=0; - } // (clean-up only every 300th loop). Thanks to Erfurt Wiki - } - - //search each name of list linksto into list reflink - foreach($pages as $v) - { - if(!in_array($v, $refs)) - { - $orphaned[] = $v; - } - } - - //change reflink by title - foreach($orphaned as $vshow) - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" GROUP BY reflink'; - } - else - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" AND visibility=1 GROUP BY reflink'; - } - - $allpages=api_sql_query($sql,__FILE__,__LINE__); - - echo '
      '; - while ($row=Database::fetch_array($allpages)) - { - //fix assignment icon - if($row['assignment']==1) - { - $ShowAssignment=''; - } - elseif ($row['assignment']==2) - { - $ShowAssignment=''; - } - elseif ($row['assignment']==0) - { - $ShowAssignment=''; - } - - echo '
    • '.$ShowAssignment.''.$row['title'].'
    • '; - } - echo '
    '; - } - -} - -/////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='delete') -{ - - if(!$_GET['title']) - { - Display::display_error_message(get_lang('MustSelectPage')); - exit; - } - - echo '
    '; - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - echo '
    '.get_lang('DeletePageHistory').'
    '; - - if($page=="index") - { - Display::display_warning_message(get_lang('WarningDeleteMainPage'),false); - } - - $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 '.$tbl_wiki_discuss.' FROM '.$tbl_wiki.', '.$tbl_wiki_discuss.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_discuss.'.publication_id='.$tbl_wiki.'.id'; - api_sql_query($sql,__FILE__,__LINE__); - - $sql='DELETE '.$tbl_wiki_mailcue.' FROM '.$tbl_wiki.', '.$tbl_wiki_mailcue.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_mailcue.'.id='.$tbl_wiki.'.id'; - api_sql_query($sql,__FILE__,__LINE__); - - $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.''; - api_sql_query($sql,__FILE__,__LINE__); - - check_emailcue(0, 'E'); - - Display::display_confirmation_message(get_lang('WikiPageDeleted')); - } - } - else - { - Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki")); - } - - echo '
    '; -} - - -/////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='deletewiki') -{ - - echo '
    '.get_lang('DeleteWiki').'
    '; - echo '
    '; - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $message = get_lang('ConfirmDeleteWiki'); - $message .= '

    - '.get_lang('No').' -   |   - '.get_lang('Yes').' -

    '; - - if (!isset($_GET['delete'])) - { - Display::display_warning_message($message,false); - } - } - else - { - Display::display_normal_message(get_lang("OnlyAdminDeleteWiki")); - } - echo '
    '; -} - -/////////////////////// search wiki pages /////////////////////// -if ($_GET['action']=='searchpages') -{ - echo '
    '.get_lang('SearchPages').'
    '; - echo '
    '; - // initiate the object - $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action='.Security::remove_XSS($_GET['action']).'&group_id='.Security::remove_XSS($_GET['group_id'])); - - // settting the form elements - - $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles"'); - $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent')); - $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"'); - - // setting the rules - $form->addRule('search_term', '
    '.get_lang('ThisFieldIsRequired'), 'required'); - $form->addRule('search_term', get_lang('TooShort'),'minlength',3); - - if ($form->validate()) - { - $form->display(); - $values = $form->exportValues(); - display_wiki_search_results($values['search_term'], $values['search_content']); - } - else - { - $form->display(); - } - echo '
    '; -} - - -/////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado - -if ($_GET['action']=='links') -{ - - if (!$_GET['title']) - { - Display::display_error_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__); - $row=Database::fetch_array($result); - - //get type assignment icon - - if($row['assignment']==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($row['assignment']==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($row['assignment']==0) - { - $ShowAssignment=''; - } - - //fix Title to reflink (link Main Page) - - if ($page==get_lang('DefaultTitle')) - { - $page='index'; - } - - echo '
    '; - echo get_lang('LinksPagesFrom').': '.$ShowAssignment.' '.Security::remove_XSS($row['title']).''; - echo '
    '; - - //fix index to title Main page into linksto - if ($page=='index') - { - $page=str_replace(' ','_',get_lang('DefaultTitle')); - } - - //table - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word. - } - else - { - $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE visibility=1 AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word - } - - $allpages=api_sql_query($sql,__LINE__,__FILE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get author - $userinfo=Database::get_user_info_from_id($obj->user_id); - - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] =$ShowAssignment; - $row[] = ''.Security::remove_XSS($obj->title).''; - $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(1,get_lang('Title'), true); - $table->set_header(2,get_lang('Author'), true); - $table->set_header(3,get_lang('Date'), true); - $table->display(); - } - } -} - - -/////////////////////// adding a new page /////////////////////// - - -// Display the form for adding a new wiki page -if ($_GET['action']=='addnew') -{ - - echo '
    '.get_lang('AddNew').'
    '; - - //first, check if page index was created. chektitle=false - if (checktitle('index')) - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - Display::display_normal_message(get_lang('GoAndEditMainPage')); - } - else - { - return Display::display_normal_message(get_lang('WikiStandBy')); - } - } - - elseif (check_addnewpagelock() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false)) - { - Display::display_error_message(get_lang('AddPagesLocked')); - } - else - { - if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0) - { - display_new_wiki_form(); - } - else - { - Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers')); - } - } - -} - - - -/////////////////////// show home page /////////////////////// - -if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew'])) -{ - display_wiki_entry(); -} - -/////////////////////// show current page /////////////////////// - -if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew'])) -{ - if($_GET['title']) - { - display_wiki_entry(); - } - else - { - Display::display_error_message(get_lang('MustSelectPage')); - } -} - - -/////////////////////// 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 - - - - if ($row['content']=='' AND $row['title']=='' AND $page=='') - { - Display::display_error_message(get_lang('MustSelectPage')); - exit; - } - elseif ($row['content']=='' AND $row['title']=='' AND $page=='index') - { - $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)); - $title=get_lang('DefaultTitle'); - $page_id=0; - } - else - { - $content=$row['content']; - $title=$row['title']; - $page_id=$row['page_id']; - } - - //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['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit())) - { - Display::display_error_message(get_lang('OnlyEditPagesCourseManager')); - } - else - { - $PassEdit=false; - - //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; - } - - // check if is a assignment - 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').''; - if((api_get_user_id()==$row['user_id'])==false) - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $PassEdit=true; - } - else - { - Display::display_warning_message(get_lang('LockByTeacher')); - $PassEdit=false; - } - } - 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 - { - - //previous checking for concurrent editions - if($row['is_editing']==0) - { - Display::display_normal_message(get_lang('WarningMaxEditingTime')); - - $time_edit = date("Y-m-d H:i:s"); - $sql='UPDATE '.$tbl_wiki.' SET is_editing="'.$_user['user_id'].'", time_edit="'.$time_edit.'" WHERE id="'.$row['id'].'"'; - api_sql_query($sql,__FILE__,__LINE__); - } - elseif($row['is_editing']!=$_user['user_id']) - { - $timestamp_edit=convert_date_to_number($row['time_edit']); - $time_editing=time()-$timestamp_edit; - $max_edit_time=1200; // 20 minutes - $rest_time=$max_edit_time-$time_editing; - - $userinfo=Database::get_user_info_from_id($row['is_editing']); - - $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '.$userinfo['lastname'].', '.$userinfo['firstname'].'. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').''; - Display::display_normal_message($is_being_edited); - exit; - } - - echo '
    '; - echo $icon_assignment.'   '.$title.'
    '; - echo '
    '; - 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 ''; //off for now - - echo ''; //get current version - - echo get_lang('Progress').':   %'; - echo '

    '; - echo '';//prevent double post - echo ''; //for save icon - echo '';//for save button - echo '
    '; - echo '
    '; - } - } - } -} - -/////////////////////// page history /////////////////////// - - -if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences'])) -{ - if (!$_GET['title']) - { - Display::display_error_message(get_lang("MustSelectPage")); - exit; - } - - echo '
    '; - $_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. TODO: 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['dtime'], 0, 4); - $month = substr($row['dtime'], 5, 2); - $day = substr($row['dtime'], 8, 2); - $hours=substr($row['dtime'], 11,2); - $minutes=substr($row['dtime'], 14,2); - $seconds=substr($row['dtime'], 17,2); - - 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 $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; - echo ''; - echo ' ('.get_lang('Version').' '.$row['version'].')'; - echo ' '.get_lang('By').' '; - 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').': '.api_substr(api_htmlentities($row['comment'], ENT_QUOTES, $charset),0,100); - if (api_strlen($row['comment'])>100) - { - echo '... '; - } - } - else - { - echo get_lang('Comments').': ---'; - } - echo ' )
    • '; - - $counter++; - } //end while - echo '
      '; - 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(isset($_POST['HistoryDifferences'])) - { - include('diff.inc.php'); - //title - echo '
    '.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedLine).' '.get_lang(WikiDiffDeletedLine).' '.get_lang(WikiDiffMovedLine).'
    '; - } - if(isset($_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['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedTex).' '.get_lang(WikiDiffDeletedTex).'
    '; - } - - echo '


    '; - - if(isset($_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 ''.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 '
    '; - - echo '
    '; - - } - - if(isset($_POST['HistoryDifferences2'])) - { - - $lines1 = array(strip_tags($version_old['content'])); //without <> tags - $lines2 = array(strip_tags($version_new['content'])); //without <> tags - - $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 ''.get_lang('Legend').'
    ' . "\n"; - echo ''; - echo ''; - echo '
    '; - echo ''; - echo ''.get_lang('WikiDiffAddedTex').'
    '; - echo ''.get_lang('WikiDiffDeletedTex').'
    '; - echo '
    '; - - echo '
    '; - - } - } - } - echo '
    '; -} - - -/////////////////////// recent changes /////////////////////// - -// -//rss feed. TODO -// - -if ($_GET['action']=='recentchanges') -{ - $_clean['group_id']=(int)$_SESSION['_gid']; - - if (check_notify_all()) - { - $notify_all= ''.get_lang('FullNotifyByEmail').''.get_lang('NotNotifyChanges').''; - } - else - { - $notify_all= ''.get_lang('FullCancelNotifyByEmail').''.get_lang('NotifyChanges').''; - } - - echo '
    '.$notify_all.''.get_lang('RecentChanges').'
    '; - - - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY dtime DESC'; - } - else - { - $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 ORDER BY dtime DESC'; - } - - $allpages=api_sql_query($sql,__LINE__,__FILE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get author - $userinfo=Database::get_user_info_from_id($obj->user_id); - - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.":".$seconds; - $row[] = $ShowAssignment; - $row[] = ''.$obj->title.''; - $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy'); - $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;')); - $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(2,get_lang('Title'), true); - $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;')); - $table->set_header(4,get_lang('Author'), true); - - $table->display(); - } -} - - -/////////////////////// all pages /////////////////////// - - -if ($_GET['action']=='allpages') -{ - echo '
    '.get_lang('AllPages').'
    '; - - $_clean['group_id']=(int)$_SESSION['_gid']; - - - if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden - { - $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version - } - else - { - $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version - } - - $allpages=api_sql_query($sql,__LINE__,__FILE__); - - //show table - if (mysql_num_rows($allpages) > 0) - { - $row = array (); - while ($obj = mysql_fetch_object($allpages)) - { - //get author - $userinfo=Database::get_user_info_from_id($obj->user_id); - - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - - //get type assignment icon - if($obj->assignment==1) - { - $ShowAssignment=''.get_lang('AssignmentDesc').''; - } - elseif ($obj->assignment==2) - { - $ShowAssignment=''.get_lang('AssignmentWork').''; - } - elseif ($obj->assignment==0) - { - $ShowAssignment=''; - } - - $row = array (); - $row[] =$ShowAssignment; - $row[] = ''.Security::remove_XSS($obj->title).''; - $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; - - if(api_is_allowed_to_edit()|| api_is_platform_admin()) - { - $showdelete=' '.get_lang('Delete').''; - } - - $row[] = ''.get_lang('EditPage').' '.get_lang('Discuss').' '.get_lang('History').' '.get_lang('LinksPages').''.$showdelete; - $rows[] = $row; - } - - $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC'); - $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); - $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); - $table->set_header(1,get_lang('Title'), true); - $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true); - $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true); - $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:100px;')); - $table->display(); - } -} - -/////////////////////// discuss pages /////////////////////// - - -if ($_GET['action']=='discuss') -{ - if (!$_GET['title']) - { - Display::display_error_message(get_lang("MustSelectPage")); - exit; - } - - //first extract the date of last version - $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); - $lastversiondate=$row['dtime']; - $lastuserinfo=Database::get_user_info_from_id($row['user_id']); - - //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); - $id=$row['id']; - $firstuserid=$row['user_id']; - - //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 '
    '; - - // discussion action: protecting (locking) the discussion - if (check_addlock_discuss()) - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $addlock_disc= ''.get_lang('LockDiscussExtra').''; - } - else - { - $addlock_disc= ''.get_lang('LockDiscussExtra').''; - } - - } - else - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $addlock_disc= ''.get_lang('UnlockDiscussExtra').''; - } - } - 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() || api_is_platform_admin()) - { - $visibility_disc= ''.get_lang('ShowDiscussExtra').''; - } - } - echo ''; - 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) - { - $ratinglock_disc= ''.get_lang('LockRatingDiscussExtra').''; - } - } - else - { - if(api_is_allowed_to_edit() || api_is_platform_admin()) - { - $ratinglock_disc= ''.get_lang('UnlockRatingDiscussExtra').''; - } - } - echo ''; - 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 ''; - - echo $icon_assignment.'   '.$row['title']; - - echo ' ('.get_lang('MostRecentVersionBy').' '.$lastuserinfo['firstname'].' '.$lastuserinfo['lastname'].' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: 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 - { - ?> -
    - - - - ';//prevent double post ?> - - - - - - - - - ';// must pass a default value to avoid rate automatically - } - ?> - - - - - -
    :
    :
      '.get_lang('Send').''; ?>
    -
    - - '; - $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='".$firstuserid."' 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;// - - if ($countWPost_score!=0) - { - $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10'; - } - else - { - $avg_WPost_score = $countWPost_score; - } - - 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. TODO - 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['dtime'].' - '.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(); +, Ghent University, Belgium +* @Author Juan Carlos Raña +* @Copyright Ghent University +* @Copyright Patrick Cool +* +* @package dokeos.wiki +*/ + + +// name of the language file that needs to be included +$language_file = 'wiki'; + +// security +if(isset($_GET['id_session'])) +{ + $_SESSION['id_session'] = Security::remove_XSS($_GET['id_session']); +} + +// including the global dokeos file +include('../inc/global.inc.php'); + +// section (for the tabs) +$this_section=SECTION_COURSES; + +// including additional library scripts + +require_once (api_get_path(LIBRARY_PATH).'course.lib.php'); +require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php'); +require_once (api_get_path(LIBRARY_PATH).'text.lib.php'); +require_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php'); +require_once (api_get_path(LIBRARY_PATH).'security.lib.php'); +require_once (api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php'); +require_once (api_get_path(INCLUDE_PATH).'conf/mail.conf.php'); +require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php'); +require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); +require_once 'wiki.inc.php'; + +// additional style information +$htmlHeadXtra[] =''; + +// Database table definition +$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.php", "name" => get_lang('Groups')); + $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'].'"'; + + //ensure this tool in groups whe it's private or deactivated + if ($group_properties['wiki_state']==0) + { + echo api_not_allowed(); + } + elseif ($group_properties['wiki_state']==2) + { + if (!api_is_allowed_to_edit() and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) + { + echo api_not_allowed(); + } + } + +} +else +{ + $groupfilter='group_id=0'; +} + +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 + +/* +============================================================================== +MAIN CODE +============================================================================== +*/ + +// Tool introduction +Display::display_introduction_section(TOOL_WIKI); + +/* +----------------------------------------------------------- +Wiki configuration settings +----------------------------------------------------------- +*/ + +$fck_attribute['Width'] = '100%'; +$fck_attribute['Height'] = '400'; +if(!api_is_allowed_to_edit()) +{ + $fck_attribute['Config']['UserStatus'] = 'student'; + $fck_attribute['ToolbarSet'] = 'Wiki_Student'; +} +else +{ + $fck_attribute['ToolbarSet'] = 'Wiki'; +} + +/* +----------------------------------------------------------- + ACTIONS +----------------------------------------------------------- +*/ + + +//release of blocked pages to prevent concurrent editions +$sql='SELECT * FROM '.$tbl_wiki.'WHERE is_editing!="0"'; +$result=api_sql_query($sql,__LINE__,__FILE__); +while ($is_editing_block=Database::fetch_array($result)) +{ + $max_edit_time=1200; // 20 minutes + $timestamp_edit=convert_date_to_number($is_editing_block['time_edit']); + $time_editing=time()-$timestamp_edit; + + + //first prevent concurrent users and double version + if($is_editing_block['is_editing']==$_user['user_id']) + { + $_SESSION['_version']=$is_editing_block['version']; + } + else + { + unset ( $_SESSION['_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']==$_user['user_id'] && $_GET['action']!='edit')) + { + $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00" WHERE is_editing="'.$is_editing_block['is_editing'].'"'; + api_sql_query($sql,__FILE__,__LINE__); + } + +} + + +// saving a change +if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') +{ + + if(empty($_POST['title'])) + { + Display::display_error_message(get_lang("NoWikiPageTitle")); + } + elseif(!double_post($_POST['wpost_id'])) + { + //double post + } + elseif ($_POST['version']!='' && $_POST['version']!=$_SESSION['_version']) + { + //prevent concurrent users and double version + Display::display_error_message(get_lang("EditedByAnotherUser")); + } + + else + { + $return_message=save_wiki(); + Display::display_confirmation_message($return_message, false); + } +} + +//saving a new wiki entry +if (isset($_POST['SaveWikiNew'])) +{ + if(empty($_POST['title'])) + { + Display::display_error_message(get_lang("NoWikiPageTitle")); + } + elseif(!double_post($_POST['wpost_id'])) + { + //double post + } + else + { + $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment + if ($_clean['assignment']==1) + { + auto_add_page_users($_clean['assignment']); + } + else + { + $return_message=save_new_wiki(); + Display::display_confirmation_message($return_message, false); + } + } +} + + +// check last version +if ($_GET['view']) +{ + $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.Database::escape_string($_GET['view']).'"'; //current view + $result=api_sql_query($sql,__LINE__,__FILE__); + $current_row=Database::fetch_array($result); + + $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.' ORDER BY id DESC'; //last version + $result=api_sql_query($sql,__LINE__,__FILE__); + $last_row=Database::fetch_array($result); + + if ($_GET['view']<$last_row['id']) + { + $message= '
    '.get_lang('NoAreSeeingTheLastVersion').'
    '.get_lang("Version").' ('.$current_row['version'].' / '.$last_row['version'].')
    '.get_lang("ConvertToLastVersion").': '.get_lang("Restore").'
    '; + + Display::display_warning_message($message,false); + } + + ///restore page + if ($_GET['action']=='restorepage') + { + //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() && $_clean['group_id']==0)) + { + Display::display_normal_message(get_lang('OnlyEditPagesCourseManager')); + } + else + { + $PassEdit=false; + + //check if is a wiki group + if($current_row['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; + } + + // check if is an assignment + if(stripslashes($current_row['assignment'])==1) + { + Display::display_normal_message(get_lang('EditAssignmentWarning')); + $icon_assignment=''.get_lang('AssignmentDescExtra').''; + } + elseif(stripslashes($current_row['assignment'])==2) + { + $icon_assignment=''.get_lang('AssignmentWorkExtra').''; + if((api_get_user_id()==$current_row['user_id'])==false) + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $PassEdit=true; + } + else + { + Display::display_warning_message(get_lang('LockByTeacher')); + $PassEdit=false; + } + } + 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($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id']) + { + //checking for concurrent users + $timestamp_edit=convert_date_to_number($last_row['time_edit']); + $time_editing=time()-$timestamp_edit; + $max_edit_time=1200; // 20 minutes + $rest_time=$max_edit_time-$time_editing; + + $userinfo=Database::get_user_info_from_id($last_row['is_editing']); + + $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '.$userinfo['lastname'].', '.$userinfo['firstname'].'. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').''; + Display::display_normal_message($is_being_edited); + + } + else + { + Display::display_confirmation_message(restore_wikipage($current_row['page_id'], $current_row['reflink'], $current_row['title'], $current_row['content'], $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': '.$last_row['title'].'',false); + } + } + } + } + } +} + + +if ($_GET['action']=='deletewiki'){ + + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + if ($_GET['delete'] == 'yes') + { + $return_message=delete_wiki(); + Display::display_confirmation_message($return_message); + } + } +} + + +if ($_GET['action']=='discuss' && $_POST['Submit']) +{ + Display::display_confirmation_message(get_lang('CommentAdded')); +} + + +/* +----------------------------------------------------------- +WIKI WRAPPER +----------------------------------------------------------- +*/ + +echo "
    "; + +/** Actions bar (= action of the wiki tool, not of the page)**/ +echo ''; + + +/* +----------------------------------------------------------- +MAIN WIKI AREA +----------------------------------------------------------- +*/ + +echo "
    "; +/** menuwiki (= actions of the page, not of the wiki tool) **/ +if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted'))) +{ + echo "'; +} + +/////////////////////// more options /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='more') +{ + + echo '
    '.get_lang('More').'
    '; + + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + //TODO: config area and private stats + + } + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    '; + echo ''; + echo ''; + echo ''; + echo'
    '; + + + //Submenu Most linked pages + //echo '
  • '.get_lang('MostLinkedPages').'
  • ';//TODO + + //Submenu Dead end pages + //echo '
  • '.get_lang('DeadEndPages').'
  • ';//TODO + + //Submenu Most new pages (not versions) + //echo '
  • '.get_lang('MostNewPages').'
  • ';//TODO + + //Submenu Most long pages + //echo '
  • '.get_lang('MostLongPages').'
  • ';//TODO + + //Submenu Protected pages + //echo '
  • '.get_lang('ProtectedPages').'
  • ';//TODO + + //Submenu Hidden pages + //echo '
  • '.get_lang('HiddenPages').'
  • ';//TODO + + //Submenu Most discuss pages + //echo '
  • '.get_lang('MostDiscussPages').'
  • ';//TODO + + //Submenu Best scored pages + //echo '
  • '.get_lang('BestScoredPages').'
  • ';//TODO + + //Submenu Pages with more progress + //echo '
  • '.get_lang('MProgressPages').'
  • ';//TODO + + //Submenu Most active users in discuss + //echo '
  • '.get_lang('MostDiscussUsers').'
  • ';//TODO + + //Submenu Individual assignments + //echo '
  • '.get_lang('Assignments').'
  • ';//TODO + + //Submenu Delayed assignments + //echo '
  • '.get_lang('DelayedAssignments').'
  • ';//TODO + + //Submenu Random page + //echo '
  • '.get_lang('RandomPage').'
  • ';//TODO + +} + +/////////////////////// Most active users /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='mactiveusers') +{ + echo '
    '.get_lang('MostActiveUsers').'
    '; + + $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY user_id'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + $userinfo=Database::get_user_info_from_id($obj->user_id); + $row = array (); + + $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; + $row[] =''.$obj->NUM_EDIT.''; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Author'), true, array ('style' => 'width:30px;')); + $table->set_header(1,get_lang('Contributions'), true); + $table->display(); + } +} + + +/////////////////////// User contributions /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='usercontrib') +{ + $userinfo=Database::get_user_info_from_id(Security::remove_XSS($_GET['user_id'])); + + echo ''; + + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'"'; + } + else + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND user_id="'.Security::remove_XSS($_GET['user_id']).'" AND visibility=1'; + } + + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get author + $userinfo=Database::get_user_info_from_id($obj->user_id); + + //get time + $year = substr($obj->dtime, 0, 4); + $month = substr($obj->dtime, 5, 2); + $day = substr($obj->dtime, 8, 2); + $hours = substr($obj->dtime, 11,2); + $minutes = substr($obj->dtime, 14,2); + $seconds = substr($obj->dtime, 17,2); + + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + $row[] =$ShowAssignment; + + $row[] = ''.$obj->title.''; + $row[] =$obj->version; + $row[] =$obj->comment; + //$row[] = api_strlen($obj->comment)>30 ? api_substr($obj->comment,0,30).'...' : $obj->comment; + $row[] =$obj->progress.' %'; + $row[] =$obj->score; + //if(api_is_allowed_to_edit() || api_is_platform_admin()) + //{ + //$row[] =$obj->user_ip; + //} + + $rows[] = $row; + + } + + $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'user_id'=>Security::remove_XSS($_GET['user_id']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + + $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;')); + $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;')); + $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;')); + $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;')); + $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;')); + $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;')); + //if(api_is_allowed_to_edit() || api_is_platform_admin()) + //{ + //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;')); + //} + + $table->display(); + } +} + +/////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='mostchanged') +{ + echo '
    '.get_lang('MostChangedPages').'
    '; + + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink'; + } + else + { + $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink'; + } + + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] =$ShowAssignment; + $row[] = ''.$obj->title.''; + $row[] = $obj->MAX; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(1,get_lang('Title'), true); + $table->set_header(2,get_lang('Changes'), true); + $table->display(); + } + +} + +/////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='mvisited') +{ + echo '
    '.get_lang('MostVisitedPages').'
    '; + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink'; + } + else + { + $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 GROUP BY reflink'; + } + + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] =$ShowAssignment; + $row[] = ''.$obj->title.''; + $row[] = $obj->tsum; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(1,get_lang('Title'), true); + $table->set_header(2,get_lang('Visits'), true); + $table->display(); + } +} + +/////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='wanted') +{ + echo '
    '.get_lang('WantedPages').'
    '; + + $pages = array(); + $refs = array(); + $sort_wanted=array(); + + //get name pages + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + while ($row=Database::fetch_array($allpages)) + { + $pages[] = $row['reflink']; + } + + //get name refs in last pages and make a unique list + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check + $rf = explode(" ", trim($row["linksto"]));//wanted pages without /n only blank " " + $refs = array_merge($refs, $rf); + if ($n++ > 299) + { + $refs = array_unique($refs); + $n=0; + } // (clean-up only every 300th loop). Thanks to Erfurt Wiki + } + + //sort linksto. Find linksto into reflink. If not found ->page is wanted + natcasesort($refs); + echo '
      '; + foreach($refs as $v) + { + if(!in_array($v, $pages)) + { + if (trim($v)!="") + { + echo '
    • '.str_replace('_',' ',$v).'
    • '; + } + } + } + echo '
    '; +} + +/////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='orphaned') +{ + echo '
    '.get_lang('OrphanedPages').'
    '; + + $pages = array(); + $refs = array(); + $orphaned = array(); + + //get name pages + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' GROUP BY reflink ORDER BY reflink ASC'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + $pages[] = $row['reflink']; + } + + //get name refs in last pages and make a unique list + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; + $allpages=api_sql_query($sql,__FILE__,__LINE__); + while ($row=Database::fetch_array($allpages)) + { + //$row['linksto']= str_replace("\n".$row["reflink"]."\n", "\n", $row["linksto"]); //remove self reference. TODO check + $rf = explode(" ", trim($row["linksto"])); //fix replace explode("\n", trim($row["linksto"])) with explode(" ", trim($row["linksto"])) + + $refs = array_merge($refs, $rf); + if ($n++ > 299) + { + $refs = array_unique($refs); + $n=0; + } // (clean-up only every 300th loop). Thanks to Erfurt Wiki + } + + //search each name of list linksto into list reflink + foreach($pages as $v) + { + if(!in_array($v, $refs)) + { + $orphaned[] = $v; + } + } + + //change reflink by title + foreach($orphaned as $vshow) + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" GROUP BY reflink'; + } + else + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND reflink="'.$vshow.'" AND visibility=1 GROUP BY reflink'; + } + + $allpages=api_sql_query($sql,__FILE__,__LINE__); + + echo '
      '; + while ($row=Database::fetch_array($allpages)) + { + //fix assignment icon + if($row['assignment']==1) + { + $ShowAssignment=''; + } + elseif ($row['assignment']==2) + { + $ShowAssignment=''; + } + elseif ($row['assignment']==0) + { + $ShowAssignment=''; + } + + echo '
    • '.$ShowAssignment.''.$row['title'].'
    • '; + } + echo '
    '; + } + +} + +/////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='delete') +{ + + if(!$_GET['title']) + { + Display::display_error_message(get_lang('MustSelectPage')); + exit; + } + + echo '
    '; + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + echo '
    '.get_lang('DeletePageHistory').'
    '; + + if($page=="index") + { + Display::display_warning_message(get_lang('WarningDeleteMainPage'),false); + } + + $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 '.$tbl_wiki_discuss.' FROM '.$tbl_wiki.', '.$tbl_wiki_discuss.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_discuss.'.publication_id='.$tbl_wiki.'.id'; + api_sql_query($sql,__FILE__,__LINE__); + + $sql='DELETE '.$tbl_wiki_mailcue.' FROM '.$tbl_wiki.', '.$tbl_wiki_mailcue.' WHERE '.$tbl_wiki.'.reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki_mailcue.'.id='.$tbl_wiki.'.id'; + api_sql_query($sql,__FILE__,__LINE__); + + $sql='DELETE FROM '.$tbl_wiki.' WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.''; + api_sql_query($sql,__FILE__,__LINE__); + + check_emailcue(0, 'E'); + + Display::display_confirmation_message(get_lang('WikiPageDeleted')); + } + } + else + { + Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki")); + } + + echo '
    '; +} + + +/////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='deletewiki') +{ + + echo '
    '.get_lang('DeleteWiki').'
    '; + echo '
    '; + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $message = get_lang('ConfirmDeleteWiki'); + $message .= '

    + '.get_lang('No').' +   |   + '.get_lang('Yes').' +

    '; + + if (!isset($_GET['delete'])) + { + Display::display_warning_message($message,false); + } + } + else + { + Display::display_normal_message(get_lang("OnlyAdminDeleteWiki")); + } + echo '
    '; +} + +/////////////////////// search wiki pages /////////////////////// +if ($_GET['action']=='searchpages') +{ + echo '
    '.get_lang('SearchPages').'
    '; + echo '
    '; + // initiate the object + $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action='.Security::remove_XSS($_GET['action']).'&group_id='.Security::remove_XSS($_GET['group_id'])); + + // settting the form elements + + $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles"'); + $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent')); + $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"'); + + // setting the rules + $form->addRule('search_term', '
    '.get_lang('ThisFieldIsRequired'), 'required'); + $form->addRule('search_term', get_lang('TooShort'),'minlength',3); + + if ($form->validate()) + { + $form->display(); + $values = $form->exportValues(); + display_wiki_search_results($values['search_term'], $values['search_content']); + } + else + { + $form->display(); + } + echo '
    '; +} + + +/////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado + +if ($_GET['action']=='links') +{ + + if (!$_GET['title']) + { + Display::display_error_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__); + $row=Database::fetch_array($result); + + //get type assignment icon + + if($row['assignment']==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($row['assignment']==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($row['assignment']==0) + { + $ShowAssignment=''; + } + + //fix Title to reflink (link Main Page) + + if ($page==get_lang('DefaultTitle')) + { + $page='index'; + } + + echo '
    '; + echo get_lang('LinksPagesFrom').': '.$ShowAssignment.' '.Security::remove_XSS($row['title']).''; + echo '
    '; + + //fix index to title Main page into linksto + if ($page=='index') + { + $page=str_replace(' ','_',get_lang('DefaultTitle')); + } + + //table + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word. + } + else + { + $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE visibility=1 AND linksto LIKE '%".html_entity_decode(Database::escape_string(stripslashes(urldecode($page))))." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s1.reflink = s2.reflink AND ".$groupfilter.")"; //add blank space after like '%" " %' to identify each word + } + + $allpages=api_sql_query($sql,__LINE__,__FILE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get author + $userinfo=Database::get_user_info_from_id($obj->user_id); + + //get time + $year = substr($obj->dtime, 0, 4); + $month = substr($obj->dtime, 5, 2); + $day = substr($obj->dtime, 8, 2); + $hours = substr($obj->dtime, 11,2); + $minutes = substr($obj->dtime, 14,2); + $seconds = substr($obj->dtime, 17,2); + + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] =$ShowAssignment; + $row[] = ''.Security::remove_XSS($obj->title).''; + $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; + $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(1,get_lang('Title'), true); + $table->set_header(2,get_lang('Author'), true); + $table->set_header(3,get_lang('Date'), true); + $table->display(); + } + } +} + + +/////////////////////// adding a new page /////////////////////// + + +// Display the form for adding a new wiki page +if ($_GET['action']=='addnew') +{ + + echo '
    '.get_lang('AddNew').'
    '; + + //first, check if page index was created. chektitle=false + if (checktitle('index')) + { + if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) + { + Display::display_normal_message(get_lang('GoAndEditMainPage')); + } + else + { + return Display::display_normal_message(get_lang('WikiStandBy')); + } + } + + elseif (check_addnewpagelock() && (api_is_allowed_to_edit()==false || api_is_platform_admin()==false)) + { + Display::display_error_message(get_lang('AddPagesLocked')); + } + else + { + if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0) + { + display_new_wiki_form(); + } + else + { + Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers')); + } + } + +} + + + +/////////////////////// show home page /////////////////////// + +if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew'])) +{ + display_wiki_entry(); +} + +/////////////////////// show current page /////////////////////// + +if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew'])) +{ + if($_GET['title']) + { + display_wiki_entry(); + } + else + { + Display::display_error_message(get_lang('MustSelectPage')); + } +} + + +/////////////////////// 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 + + + + if ($row['content']=='' AND $row['title']=='' AND $page=='') + { + Display::display_error_message(get_lang('MustSelectPage')); + exit; + } + elseif ($row['content']=='' AND $row['title']=='' AND $page=='index') + { + $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)); + $title=get_lang('DefaultTitle'); + $page_id=0; + } + else + { + $content=$row['content']; + $title=$row['title']; + $page_id=$row['page_id']; + } + + //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher. And users in groups + if(($row['reflink']=='index' || $row['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit() && $_clean['group_id']==0)) + { + Display::display_error_message(get_lang('OnlyEditPagesCourseManager')); + } + else + { + $PassEdit=false; + + //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; + } + + // check if is a assignment + 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').''; + if((api_get_user_id()==$row['user_id'])==false) + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $PassEdit=true; + } + else + { + Display::display_warning_message(get_lang('LockByTeacher')); + $PassEdit=false; + } + } + 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 + { + + //previous checking for concurrent editions + if($row['is_editing']==0) + { + Display::display_normal_message(get_lang('WarningMaxEditingTime')); + + $time_edit = date("Y-m-d H:i:s"); + $sql='UPDATE '.$tbl_wiki.' SET is_editing="'.$_user['user_id'].'", time_edit="'.$time_edit.'" WHERE id="'.$row['id'].'"'; + api_sql_query($sql,__FILE__,__LINE__); + } + elseif($row['is_editing']!=$_user['user_id']) + { + $timestamp_edit=convert_date_to_number($row['time_edit']); + $time_editing=time()-$timestamp_edit; + $max_edit_time=1200; // 20 minutes + $rest_time=$max_edit_time-$time_editing; + + $userinfo=Database::get_user_info_from_id($row['is_editing']); + + $is_being_edited= get_lang('ThisPageisBeginEditedBy').' '.$userinfo['lastname'].', '.$userinfo['firstname'].'. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').''; + Display::display_normal_message($is_being_edited); + exit; + } + + echo '
    '; + echo $icon_assignment.'   '.$title.'
    '; + echo '
    '; + 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 ''; //off for now + + echo ''; //get current version + + echo get_lang('Progress').':   %'; + echo '

    '; + echo '';//prevent double post + echo ''; //for save icon + echo '';//for save button + echo '
    '; + echo '
    '; + } + } + } +} + +/////////////////////// page history /////////////////////// + + +if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifferences'])) +{ + if (!$_GET['title']) + { + Display::display_error_message(get_lang("MustSelectPage")); + exit; + } + + echo '
    '; + $_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. TODO: 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['dtime'], 0, 4); + $month = substr($row['dtime'], 5, 2); + $day = substr($row['dtime'], 8, 2); + $hours=substr($row['dtime'], 11,2); + $minutes=substr($row['dtime'], 14,2); + $seconds=substr($row['dtime'], 17,2); + + 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 $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + echo ''; + echo ' ('.get_lang('Version').' '.$row['version'].')'; + echo ' '.get_lang('By').' '; + 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').': '.api_substr(api_htmlentities($row['comment'], ENT_QUOTES, $charset),0,100); + if (api_strlen($row['comment'])>100) + { + echo '... '; + } + } + else + { + echo get_lang('Comments').': ---'; + } + echo ' )
    • '; + + $counter++; + } //end while + echo '
      '; + 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(isset($_POST['HistoryDifferences'])) + { + include('diff.inc.php'); + //title + echo '
    '.stripslashes($version_new['title']).' ('.get_lang('DifferencesNew').' '.stripslashes($version_new['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedLine).' '.get_lang(WikiDiffDeletedLine).' '.get_lang(WikiDiffMovedLine).'
    '; + } + if(isset($_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['dtime']).' '.get_lang('DifferencesOld').' '.stripslashes($version_old['dtime']).') '.get_lang('Legend').': '.get_lang(WikiDiffAddedTex).' '.get_lang(WikiDiffDeletedTex).'
    '; + } + + echo '


    '; + + if(isset($_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 ''.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 '
    '; + + echo '
    '; + + } + + if(isset($_POST['HistoryDifferences2'])) + { + + $lines1 = array(strip_tags($version_old['content'])); //without <> tags + $lines2 = array(strip_tags($version_new['content'])); //without <> tags + + $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 ''.get_lang('Legend').'
    ' . "\n"; + echo ''; + echo ''; + echo '
    '; + echo ''; + echo ''.get_lang('WikiDiffAddedTex').'
    '; + echo ''.get_lang('WikiDiffDeletedTex').'
    '; + echo '
    '; + + echo '
    '; + + } + } + } + echo '
    '; +} + + +/////////////////////// recent changes /////////////////////// + +// +//rss feed. TODO +// + +if ($_GET['action']=='recentchanges') +{ + $_clean['group_id']=(int)$_SESSION['_gid']; + + if (check_notify_all()) + { + $notify_all= ''.get_lang('FullNotifyByEmail').''.get_lang('NotNotifyChanges').''; + } + else + { + $notify_all= ''.get_lang('FullCancelNotifyByEmail').''.get_lang('NotifyChanges').''; + } + + echo '
    '.$notify_all.''.get_lang('RecentChanges').'
    '; + + + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' ORDER BY dtime DESC'; + } + else + { + $sql='SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.' AND visibility=1 ORDER BY dtime DESC'; + } + + $allpages=api_sql_query($sql,__LINE__,__FILE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get author + $userinfo=Database::get_user_info_from_id($obj->user_id); + + //get time + $year = substr($obj->dtime, 0, 4); + $month = substr($obj->dtime, 5, 2); + $day = substr($obj->dtime, 8, 2); + $hours = substr($obj->dtime, 11,2); + $minutes = substr($obj->dtime, 14,2); + $seconds = substr($obj->dtime, 17,2); + + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.":".$seconds; + $row[] = $ShowAssignment; + $row[] = ''.$obj->title.''; + $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy'); + $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;')); + $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(2,get_lang('Title'), true); + $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;')); + $table->set_header(4,get_lang('Author'), true); + + $table->display(); + } +} + + +/////////////////////// all pages /////////////////////// + + +if ($_GET['action']=='allpages') +{ + echo '
    '.get_lang('AllPages').'
    '; + + $_clean['group_id']=(int)$_SESSION['_gid']; + + + if(api_is_allowed_to_edit() || api_is_platform_admin()) //only by professors if page is hidden + { + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version + } + else + { + $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE visibility=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.reflink = s2.reflink AND '.$groupfilter.')'; // warning don't use group by reflink because don't return the last version + } + + $allpages=api_sql_query($sql,__LINE__,__FILE__); + + //show table + if (mysql_num_rows($allpages) > 0) + { + $row = array (); + while ($obj = mysql_fetch_object($allpages)) + { + //get author + $userinfo=Database::get_user_info_from_id($obj->user_id); + + //get time + $year = substr($obj->dtime, 0, 4); + $month = substr($obj->dtime, 5, 2); + $day = substr($obj->dtime, 8, 2); + $hours = substr($obj->dtime, 11,2); + $minutes = substr($obj->dtime, 14,2); + $seconds = substr($obj->dtime, 17,2); + + //get type assignment icon + if($obj->assignment==1) + { + $ShowAssignment=''.get_lang('AssignmentDesc').''; + } + elseif ($obj->assignment==2) + { + $ShowAssignment=''.get_lang('AssignmentWork').''; + } + elseif ($obj->assignment==0) + { + $ShowAssignment=''; + } + + $row = array (); + $row[] =$ShowAssignment; + $row[] = ''.Security::remove_XSS($obj->title).''; + $row[] = $obj->user_id <>0 ? ''.$userinfo['lastname'].', '.$userinfo['firstname'].'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; + $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + + if(api_is_allowed_to_edit()|| api_is_platform_admin()) + { + $showdelete=' '.get_lang('Delete').''; + } + + $row[] = ''.get_lang('EditPage').' '.get_lang('Discuss').' '.get_lang('History').' '.get_lang('LinksPages').''.$showdelete; + $rows[] = $row; + } + + $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC'); + $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'group_id'=>Security::remove_XSS($_GET['group_id']))); + $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;')); + $table->set_header(1,get_lang('Title'), true); + $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true); + $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true); + $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:100px;')); + $table->display(); + } +} + +/////////////////////// discuss pages /////////////////////// + + +if ($_GET['action']=='discuss') +{ + if (!$_GET['title']) + { + Display::display_error_message(get_lang("MustSelectPage")); + exit; + } + + //first extract the date of last version + $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); + $lastversiondate=$row['dtime']; + $lastuserinfo=Database::get_user_info_from_id($row['user_id']); + + //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); + $id=$row['id']; + $firstuserid=$row['user_id']; + + //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 '
    '; + + // discussion action: protecting (locking) the discussion + if (check_addlock_discuss()) + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $addlock_disc= ''.get_lang('LockDiscussExtra').''; + } + else + { + $addlock_disc= ''.get_lang('LockDiscussExtra').''; + } + + } + else + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $addlock_disc= ''.get_lang('UnlockDiscussExtra').''; + } + } + 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() || api_is_platform_admin()) + { + $visibility_disc= ''.get_lang('ShowDiscussExtra').''; + } + } + echo ''; + 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) + { + $ratinglock_disc= ''.get_lang('LockRatingDiscussExtra').''; + } + } + else + { + if(api_is_allowed_to_edit() || api_is_platform_admin()) + { + $ratinglock_disc= ''.get_lang('UnlockRatingDiscussExtra').''; + } + } + echo ''; + 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 ''; + + echo $icon_assignment.'   '.$row['title']; + + echo ' ('.get_lang('MostRecentVersionBy').' '.$lastuserinfo['firstname'].' '.$lastuserinfo['lastname'].' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: 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 + { + ?> +
    + + + + ';//prevent double post ?> + + + + + + + + + ';// must pass a default value to avoid rate automatically + } + ?> + + + + + +
    :
    :
      '.get_lang('Send').''; ?>
    +
    + + '; + $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='".$firstuserid."' 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;// + + if ($countWPost_score!=0) + { + $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10'; + } + else + { + $avg_WPost_score = $countWPost_score; + } + + 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. TODO + 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['dtime'].' - '.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(); ?> \ No newline at end of file diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index dbc1df727f..b97a730711 100644 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -38,6 +38,7 @@ FUNCTIONS FOR WIKI ============================================================================== */ +// including the global dokeos file /** * @author Patrick Cool , Ghent University @@ -334,7 +335,7 @@ function save_wiki() { * This function restore a wikipage * @author Juan Carlos Raña **/ -function restore_wikipage($r_reflink, $r_title, $r_content, $r_group_id, $r_assignment, $r_progress, $c_version, $r_version, $r_linksto) +function restore_wikipage($r_page_id, $r_reflink, $r_title, $r_content, $r_group_id, $r_assignment, $r_progress, $c_version, $r_version, $r_linksto) { global $tbl_wiki; @@ -344,7 +345,7 @@ function restore_wikipage($r_reflink, $r_title, $r_content, $r_group_id, $r_assi $r_version = $r_version+1; $r_comment = get_lang('RestoredFromVersion').': '.$c_version; - $sql="INSERT INTO ".$tbl_wiki." (reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip) VALUES ('".$r_reflink."','".$r_title."','".$r_content."','".$r_user_id."','".$r_group_id."','".$r_dtime."','".$r_assignment."','".$r_comment."','".$r_progress."','".$r_version."','".$r_linksto."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."')"; + $sql="INSERT INTO ".$tbl_wiki." (page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip) VALUES ('".$r_page_id."','".$r_reflink."','".$r_title."','".$r_content."','".$r_user_id."','".$r_group_id."','".$r_dtime."','".$r_assignment."','".$r_comment."','".$r_progress."','".$r_version."','".$r_linksto."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."')"; $result=api_sql_query($sql); $Id = Database::insert_id(); @@ -525,6 +526,7 @@ function display_wiki_entry() global $tbl_wiki; global $groupfilter; global $page; + $_clean['group_id']=(int)$_SESSION['_gid']; if ($_GET['view']) @@ -556,7 +558,7 @@ function display_wiki_entry() // if both are empty and we are displaying the index page then we display the default text. if ($row['content']=='' AND $row['title']=='' AND $page=='index') { - if(api_is_allowed_to_edit() || api_is_platform_admin()) + if(api_is_allowed_to_edit() || api_is_platform_admin() || GroupManager :: is_user_in_group(api_get_user_id(),$_SESSION['_gid'])) { $content=sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)); $title=get_lang('DefaultTitle');