index.php 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  5. * @author Juan Carlos Raña <herodoto@telefonica.net>
  6. *
  7. * @package chamilo.wiki
  8. */
  9. /**
  10. * Code
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = 'wiki';
  14. // including the global initialization file
  15. require_once '../inc/global.inc.php';
  16. // section (for the tabs)
  17. $this_section = SECTION_COURSES;
  18. $current_course_tool = TOOL_WIKI;
  19. require_once 'wiki.inc.php';
  20. $course_id = api_get_course_int_id();
  21. // additional style information
  22. $htmlHeadXtra[] ='<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CODE_PATH).'wiki/css/default.css"/>';
  23. // javascript for advanced parameters menu
  24. $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
  25. function advanced_parameters() {
  26. if(document.getElementById(\'options\').style.display == \'none\') {
  27. document.getElementById(\'options\').style.display = \'block\';
  28. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  29. } else {
  30. document.getElementById(\'options\').style.display = \'none\';
  31. document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
  32. }
  33. }
  34. function setFocus(){
  35. $("#search_title").focus();
  36. }
  37. $(document).ready(function () {
  38. setFocus();
  39. });
  40. </script>';
  41. // Database table definition
  42. $tbl_wiki = Database::get_course_table(TABLE_WIKI);
  43. $tbl_wiki_discuss = Database::get_course_table(TABLE_WIKI_DISCUSS);
  44. $tbl_wiki_mailcue = Database::get_course_table(TABLE_WIKI_MAILCUE);
  45. $tbl_wiki_conf = Database::get_course_table(TABLE_WIKI_CONF);
  46. /*
  47. Constants and variables
  48. */
  49. $tool_name = get_lang('ToolWiki');
  50. $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"));
  51. //condition for the session
  52. $session_id = api_get_session_id();
  53. $condition_session = api_get_session_condition($session_id);
  54. $course_id = api_get_course_int_id();
  55. /* ACCESS */
  56. api_protect_course_script();
  57. api_block_anonymous_users();
  58. /* TRACKING */
  59. event_access_tool(TOOL_WIKI);
  60. /*
  61. HEADER & TITLE
  62. */
  63. // If it is a group wiki then the breadcrumbs will be different.
  64. //Setting variable
  65. $_clean['group_id'] = 0;
  66. if ($_SESSION['_gid'] OR $_GET['group_id']) {
  67. if (isset($_SESSION['_gid'])) {
  68. $_clean['group_id']=intval($_SESSION['_gid']);
  69. }
  70. if (isset($_GET['group_id'])) {
  71. $_clean['group_id']=intval($_GET['group_id']);
  72. }
  73. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  74. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  75. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_clean['group_id'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
  76. $add_group_to_title = ' '.$group_properties['name'];
  77. $groupfilter='group_id="'.$_clean['group_id'].'"';
  78. //ensure this tool in groups whe it's private or deactivated
  79. if ($group_properties['wiki_state']==0) {
  80. api_not_allowed();
  81. } elseif ($group_properties['wiki_state']==2) {
  82. if (!api_is_allowed_to_edit(false,true) and !GroupManager :: is_user_in_group($_user['user_id'], $_SESSION['_gid'])) {
  83. api_not_allowed();
  84. }
  85. }
  86. } else {
  87. $groupfilter='group_id=0';
  88. }
  89. if ($_POST['action']=='export_to_pdf' && isset($_POST['wiki_id']) && api_get_setting('students_export2pdf') == 'true') {
  90. export_to_pdf($_POST['wiki_id'], api_get_course_id());
  91. exit;
  92. }
  93. Display::display_header($tool_name, 'Wiki');
  94. $is_allowed_to_edit = api_is_allowed_to_edit(false,true);
  95. //api_display_tool_title($tool_name.$add_group_to_title);
  96. /*
  97. INITIALISATION
  98. */
  99. //the page we are dealing with
  100. if (!isset($_GET['title'])) {
  101. $page = 'index';
  102. } else {
  103. $page = $_GET['title'];
  104. }
  105. // some titles are not allowed
  106. // $not_allowed_titles=array("Index", "RecentChanges","AllPages", "Categories"); //not used for now
  107. /*
  108. MAIN CODE
  109. */
  110. // Tool introduction
  111. Display::display_introduction_section(TOOL_WIKI);
  112. /*
  113. ACTIONS
  114. */
  115. //release of blocked pages to prevent concurrent editions
  116. echo '<div style="overflow:hidden">';
  117. $sql = "SELECT * FROM $tbl_wiki WHERE c_id = $course_id AND is_editing != '0' ".$condition_session;
  118. $result=Database::query($sql);
  119. while ($is_editing_block=Database::fetch_array($result)) {
  120. $max_edit_time = 1200; // 20 minutes
  121. $timestamp_edit = strtotime($is_editing_block['time_edit']);
  122. $time_editing = time()-$timestamp_edit;
  123. //first prevent concurrent users and double version
  124. if ($is_editing_block['is_editing']==$_user['user_id']) {
  125. $_SESSION['_version']=$is_editing_block['version'];
  126. } else {
  127. unset ( $_SESSION['_version'] );
  128. }
  129. //second checks if has exceeded the time that a page may be available or if a page was edited and saved by its author
  130. if ($time_editing>$max_edit_time || ($is_editing_block['is_editing']==$_user['user_id'] && $_GET['action']!='edit')) {
  131. $sql='UPDATE '.$tbl_wiki.' SET is_editing="0", time_edit="0000-00-00 00:00:00"
  132. WHERE c_id = '.$course_id.' AND is_editing="'.$is_editing_block['is_editing'].'" '.$condition_session;
  133. Database::query($sql);
  134. }
  135. }
  136. echo '</div>';
  137. // saving a change
  138. if (isset($_POST['SaveWikiChange']) AND $_POST['title']<>'') {
  139. if(empty($_POST['title'])) {
  140. Display::display_error_message(get_lang("NoWikiPageTitle"));
  141. } elseif(!double_post($_POST['wpost_id'])) {
  142. //double post
  143. } elseif ($_POST['version']!='' && $_SESSION['_version']!=0 && $_POST['version']!=$_SESSION['_version']) {
  144. //prevent concurrent users and double version
  145. Display::display_error_message(get_lang("EditedByAnotherUser"));
  146. } else {
  147. $return_message=save_wiki();
  148. Display::display_confirmation_message($return_message, false);
  149. }
  150. }
  151. //saving a new wiki entry
  152. echo '<div style="overflow:hidden">';
  153. if (isset($_POST['SaveWikiNew'])) {
  154. if (empty($_POST['title'])) {
  155. Display::display_error_message(get_lang("NoWikiPageTitle"));
  156. } elseif (strtotime(get_date_from_select('startdate_assig')) > strtotime(get_date_from_select('enddate_assig'))) {
  157. Display::display_error_message(get_lang("EndDateCannotBeBeforeTheStartDate"));
  158. } elseif(!double_post($_POST['wpost_id'])) {
  159. //double post
  160. } else {
  161. $_clean['assignment']=Database::escape_string($_POST['assignment']); // for mode assignment
  162. if ($_clean['assignment']==1) {
  163. auto_add_page_users($_clean['assignment']);
  164. } else {
  165. $return_message=save_new_wiki();
  166. if ($return_message==false) {
  167. Display::display_error_message(get_lang('NoWikiPageTitle'), false);
  168. } else {
  169. Display::display_confirmation_message($return_message, false);
  170. }
  171. }
  172. }
  173. }
  174. echo '</div>';
  175. // check last version
  176. if ($_GET['view']) {
  177. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND id="'.Database::escape_string($_GET['view']).'"'; //current view
  178. $result=Database::query($sql);
  179. $current_row=Database::fetch_array($result);
  180. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; //last version
  181. $result=Database::query($sql);
  182. $last_row=Database::fetch_array($result);
  183. if ($_GET['view']<$last_row['id']) {
  184. $message= '<center>'.get_lang('NoAreSeeingTheLastVersion').'<br /> '.get_lang("Version").' (<a href="index.php?cidReq='.$_course['id'].'&action=showpage&amp;title='.api_htmlentities(urlencode($current_row['reflink'])).'&group_id='.$current_row['group_id'].'&session_id='.$current_row['session_id'].'&view='.Security::remove_XSS($_GET['view']).'" title="'.get_lang('CurrentVersion').'">'.$current_row['version'].'</a> / <a href="index.php?cidReq='.$_course['id'].'&action=showpage&amp;title='.api_htmlentities(urlencode($last_row['reflink'])).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'" title="'.get_lang('LastVersion').'">'.$last_row['version'].'</a>) <br />'.get_lang("ConvertToLastVersion").': <a href="index.php?cidReq='.$_course['id'].'&action=restorepage&amp;title='.api_htmlentities(urlencode($last_row['reflink'])).'&group_id='.$last_row['group_id'].'&session_id='.$last_row['session_id'].'&view='.Security::remove_XSS($_GET['view']).'">'.get_lang("Restore").'</a></center>';
  185. Display::display_warning_message($message,false);
  186. }
  187. ///restore page
  188. if ($_GET['action']=='restorepage') {
  189. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher
  190. if (($current_row['reflink']=='index' || $current_row['reflink']=='' || $current_row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && intval($_GET['group_id'])==0)) {
  191. Display::display_normal_message(get_lang('OnlyEditPagesCourseManager'));
  192. } else {
  193. $PassEdit=false;
  194. //check if is a wiki group
  195. if ($current_row['group_id']!=0) {
  196. //Only teacher, platform admin and group members can edit a wiki group
  197. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],intval($_GET['group_id']))) {
  198. $PassEdit=true;
  199. } else {
  200. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  201. }
  202. } else {
  203. $PassEdit=true;
  204. }
  205. // check if is an assignment
  206. if ($current_row['assignment']==1) {
  207. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  208. $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
  209. } elseif($current_row['assignment']==2) {
  210. $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
  211. if ((api_get_user_id()==$current_row['user_id'])==false) {
  212. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  213. $PassEdit=true;
  214. } else {
  215. Display::display_warning_message(get_lang('LockByTeacher'));
  216. $PassEdit=false;
  217. }
  218. } else {
  219. $PassEdit=true;
  220. }
  221. }
  222. if ($PassEdit) { //show editor if edit is allowed
  223. if ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) {
  224. Display::display_normal_message(get_lang('PageLockedExtra'));
  225. } else {
  226. if ($last_row['is_editing']!=0 && $last_row['is_editing']!=$_user['user_id']) {
  227. //checking for concurrent users
  228. $timestamp_edit=strtotime($last_row['time_edit']);
  229. $time_editing=time()-$timestamp_edit;
  230. $max_edit_time=1200; // 20 minutes
  231. $rest_time=$max_edit_time-$time_editing;
  232. $userinfo = api_get_user_info($last_row['is_editing']);
  233. $is_being_edited= get_lang('ThisPageisBeginEditedBy').' <a href=../user/userInfo.php?uInfo='.
  234. $userinfo['user_id'].'>'.
  235. Display::tag('span', $userinfo['complete_name_login_as']).
  236. get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
  237. Display::display_normal_message($is_being_edited, false);
  238. } else {
  239. Display::display_confirmation_message(restore_wikipage($current_row['page_id'], $current_row['reflink'], api_htmlentities($current_row['title']), api_htmlentities($current_row['content']), $current_row['group_id'], $current_row['assignment'], $current_row['progress'], $current_row['version'], $last_row['version'], $current_row['linksto']).': <a href="index.php?cidReq='.$_course['id'].'&action=showpage&amp;title='.api_htmlentities(urlencode($last_row['reflink'])).'&session_id='.$last_row['session_id'].'&group_id='.$last_row['group_id'].'">'.api_htmlentities($last_row['title']).'</a>',false);
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. echo '<div style="overflow:hidden">';
  247. if ($_GET['action']=='deletewiki') {
  248. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  249. if ($_GET['delete'] == 'yes') {
  250. $return_message=delete_wiki();
  251. Display::display_confirmation_message($return_message);
  252. }
  253. }
  254. }
  255. if ($_GET['action']=='discuss' && $_POST['Submit']) {
  256. Display::display_confirmation_message(get_lang('CommentAdded'));
  257. }
  258. echo '</div>';
  259. /* WIKI WRAPPER */
  260. echo '<div id="wikiwrapper">';
  261. /** Actions bar (= action of the wiki tool, not of the page)**/
  262. //dynamic wiki menu
  263. ?>
  264. <script type="text/javascript">
  265. function menu_wiki(){
  266. if(document.getElementById("menuwiki").style.width=="180px"){
  267. var w=74;
  268. var b=2;
  269. var h=30;
  270. }
  271. else{
  272. var w=180;
  273. var b=1;
  274. var h=220;
  275. }
  276. document.getElementById("menuwiki").style.width=w+"px";
  277. document.getElementById("menuwiki").style.height=h+"px";
  278. document.getElementById("menuwiki").style.border=b+"px solid #cccccc";
  279. }
  280. </script>
  281. <?php
  282. echo '<div id="menuwiki" style="padding:2px;">';
  283. echo '&nbsp;<a href="index.php?cidReq='.$_course['id'].'&action=show&amp;title=index&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('show').'>'.Display::return_icon('wiki.png',get_lang('HomeWiki'),'',ICON_SIZE_MEDIUM).'</a>&nbsp;';
  284. echo '&nbsp;<a href="javascript:void(0)" onClick="menu_wiki()">'.Display::return_icon('menu.png',get_lang('Menu'),'',ICON_SIZE_SMALL).'</a>';
  285. ///menu home
  286. echo '<ul>';
  287. if ( api_is_allowed_to_session_edit(false,true) ) {
  288. //menu add page
  289. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=addnew&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('addnew').'>'.get_lang('AddNew').'</a> ';
  290. }
  291. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  292. // page action: enable or disable the adding of new pages
  293. if (check_addnewpagelock()==0) {
  294. $protect_addnewpage= '<img src="../img/off.png" title="'.get_lang('AddOptionProtected').'" alt="'.get_lang('AddOptionProtected').'" width="8" height="8" />';
  295. $lock_unlock_addnew='unlockaddnew';
  296. } else {
  297. $protect_addnewpage= '<img src="../img/on.png" title="'.get_lang('AddOptionUnprotected').'" alt="'.get_lang('AddOptionUnprotected').'" width="8" height="8" />';
  298. $lock_unlock_addnew='lockaddnew';
  299. }
  300. }
  301. echo '<a href="index.php?action=show&amp;actionpage='.$lock_unlock_addnew.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$protect_addnewpage.'</a></li>';
  302. ///menu find
  303. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=searchpages&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('searchpages').'>'.get_lang('SearchPages').'</a></li>';
  304. ///menu all pages
  305. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=allpages&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('allpages').'>'.get_lang('AllPages').'</a></li>';
  306. ///menu recent changes
  307. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=recentchanges&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('recentchanges').'>'.get_lang('RecentChanges').'</a></li>';
  308. ///menu delete all wiki
  309. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  310. echo '<li><a href="index.php?action=deletewiki&amp;title='.api_htmlentities(urlencode($page)).'"'.is_active_navigation_tab('deletewiki').'>'.get_lang('DeleteWiki').'</a></li>';
  311. }
  312. ///menu more
  313. echo '<li><a href="index.php?action=more&amp;title='.api_htmlentities(urlencode($page)).'"'.is_active_navigation_tab('more').'>'.get_lang('More').'</a></li>';
  314. echo '</ul>';
  315. echo '</div>';
  316. /*
  317. MAIN WIKI AREA
  318. */
  319. echo '<div id="mainwiki">';
  320. /** menuwiki (= actions of the page, not of the wiki tool) **/
  321. if (!in_array($_GET['action'], array('addnew', 'searchpages', 'allpages', 'recentchanges', 'deletewiki', 'more', 'mactiveusers', 'mvisited', 'mostchanged', 'orphaned', 'wanted'))) {
  322. echo '<div class="actions">';
  323. //menu show page
  324. echo '&nbsp;&nbsp;<a href="index.php?cidReq='.$_course['id'].'&action=showpage&amp;title='.api_htmlentities(urlencode($page)).'&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('showpage').'>'.Display::return_icon('page.png',get_lang('ShowThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
  325. if (api_is_allowed_to_session_edit(false,true) ) {
  326. //menu edit page
  327. echo '<a href="index.php?cidReq='.$_course['id'].'&action=edit&amp;title='.api_htmlentities(urlencode($page)).'&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('edit').'>'.Display::return_icon('edit.png',get_lang('EditThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
  328. //menu discuss page
  329. echo '<a href="index.php?action=discuss&amp;title='.api_htmlentities(urlencode($page)).'"'.is_active_navigation_tab('discuss').'>'.Display::return_icon('discuss.png',get_lang('DiscussThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
  330. }
  331. //menu history
  332. echo '<a href="index.php?cidReq='.$_course['id'].'&action=history&amp;title='.api_htmlentities(urlencode($page)).'&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('history').'>'.Display::return_icon('history.png',get_lang('ShowPageHistory'),'',ICON_SIZE_MEDIUM).'</a>';
  333. //menu linkspages
  334. echo '<a href="index.php?action=links&amp;title='.api_htmlentities(urlencode($page)).'&session_id='.$session_id.'&group_id='.$_clean['group_id'].'"'.is_active_navigation_tab('links').'>'.Display::return_icon('what_link_here.png',get_lang('LinksPages'),'',ICON_SIZE_MEDIUM).'</a>';
  335. //menu delete wikipage
  336. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  337. echo '<a href="index.php?action=delete&amp;title='.api_htmlentities(urlencode($page)).'"'.is_active_navigation_tab('delete').'>'.Display::return_icon('delete.png',get_lang('DeleteThisPage'),'',ICON_SIZE_MEDIUM).'</a>';
  338. }
  339. echo '</div>';
  340. }
  341. //In new pages go to new page
  342. if (isset($_POST['SaveWikiNew'])) {
  343. display_wiki_entry($_POST['reflink']);
  344. }
  345. //More for export to course document area. See display_wiki_entry
  346. if ($_POST['export2DOC']) {
  347. $doc_id = $_POST['doc_id'];
  348. $export2doc = export2doc($doc_id);
  349. if ($export2doc) {
  350. Display::display_confirmation_message(get_lang('ThePageHasBeenExportedToDocArea'));
  351. }
  352. }
  353. if ($_GET['action']=='more') {
  354. echo '<div class="actions">'.get_lang('More').'</div>';
  355. echo '<table border="0">';
  356. echo ' <tr>';
  357. echo ' <td>';
  358. echo ' <ul>';
  359. //Submenu Most active users
  360. echo ' <li><a href="index.php?cidReq='.$_course['id'].'&action=mactiveusers&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostActiveUsers').'</a></li>';
  361. //Submenu Most visited pages
  362. echo ' <li><a href="index.php?cidReq='.$_course['id'].'&action=mvisited&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostVisitedPages').'</a></li>';
  363. //Submenu Most changed pages
  364. echo ' <li><a href="index.php?cidReq='.$_course['id'].'&action=mostchanged&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostChangedPages').'</a></li>';
  365. echo ' </ul>';
  366. echo ' </td>';
  367. echo ' <td>';
  368. echo ' <ul>';
  369. //Submenu Orphaned pages
  370. echo ' <li><a href="index.php?cidReq='.$_course['id'].'&action=orphaned&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('OrphanedPages').'</a></li>';
  371. //Submenu Wanted pages
  372. echo ' <li><a href="index.php?cidReq='.$_course['id'].'&action=wanted&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('WantedPages').'</a></li>';
  373. //Submenu Most linked pages
  374. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mostlinked&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostLinkedPages').'</a></li>';
  375. echo '</ul>';
  376. echo '</td>';
  377. echo '<td style="vertical-align:top">';
  378. echo '<ul>';
  379. //Submenu Statistics
  380. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  381. echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=statistics&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('Statistics').'</a></li>';
  382. }
  383. echo ' </ul>';
  384. echo' </td>';
  385. echo ' </tr>';
  386. echo '</table>';
  387. //Submenu Dead end pages
  388. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=deadend&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('DeadEndPages').'</a></li>';//TODO:
  389. //Submenu Most new pages (not versions)
  390. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mnew&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostNewPages').'</a></li>';//TODO:
  391. //Submenu Most long pages
  392. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mnew&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostLongPages').'</a></li>';//TODO:
  393. //Submenu Protected pages
  394. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=protected&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('ProtectedPages').'</a></li>';//TODO:
  395. //Submenu Hidden pages
  396. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=hidden&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('HiddenPages').'</a></li>';//TODO:
  397. //Submenu Most discuss pages
  398. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mdiscuss&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussPages').'</a></li>';//TODO:
  399. //Submenu Best scored pages
  400. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mscored&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('BestScoredPages').'</a></li>';//TODO:
  401. //Submenu Pages with more progress
  402. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mprogress&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MProgressPages').'</a></li>';//TODO:
  403. //Submenu Most active users in discuss
  404. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mactiveusers&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('MostDiscussUsers').'</a></li>';//TODO:
  405. //Submenu Random page
  406. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=mrandom&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('RandomPage').'</a></li>';//TODO:
  407. //Submenu Task
  408. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=datetasks&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('Task').'</a></li>';//TODO:task list order by start date or end date
  409. //Submenu Who and Where
  410. //echo '<li><a href="index.php?cidReq='.$_course['id'].'&action=whoandwhere&session_id='.$session_id.'&group_id='.$_clean['group_id'].'">'.get_lang('WhoAndWhere').'</a></li>';//TODO:Who and where everyone is working now?
  411. }
  412. // Statistics Juan Carlos Raña Trabado
  413. if ($_GET['action']=='statistics' && (api_is_allowed_to_edit(false,true) || api_is_platform_admin())) {
  414. echo '<div class="actions">'.get_lang('Statistics').'</div>';
  415. //check all versions of all pages
  416. $total_words = 0;
  417. $total_links = 0;
  418. $total_links_anchors = 0;
  419. $total_links_mail = 0;
  420. $total_links_ftp = 0;
  421. $total_links_irc = 0;
  422. $total_links_news = 0;
  423. $total_wlinks = 0;
  424. $total_images = 0;
  425. $clean_total_flash = 0;
  426. $total_flash = 0;
  427. $total_mp3 = 0;
  428. $total_flv_p = 0;
  429. $total_flv = 0;
  430. $total_youtube = 0;
  431. $total_multimedia = 0;
  432. $total_tables = 0;
  433. $sql="SELECT *, COUNT(*) AS TOTAL_VERS, SUM(hits) AS TOTAL_VISITS FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
  434. $allpages=Database::query($sql);
  435. while ($row=Database::fetch_array($allpages)) {
  436. $total_versions = $row['TOTAL_VERS'];
  437. $total_visits = intval($row['TOTAL_VISITS']);
  438. }
  439. $sql="SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session."";
  440. $allpages=Database::query($sql);
  441. while ($row=Database::fetch_array($allpages)) {
  442. $total_words = $total_words+word_count($row['content']);
  443. $total_links = $total_links+substr_count($row['content'], "href=");
  444. $total_links_anchors = $total_links_anchors+substr_count($row['content'], 'href="#');
  445. $total_links_mail = $total_links_mail+substr_count($row['content'], 'href="mailto');
  446. $total_links_ftp = $total_links_ftp+substr_count($row['content'], 'href="ftp');
  447. $total_links_irc = $total_links_irc+substr_count($row['content'], 'href="irc');
  448. $total_links_news = $total_links_news+substr_count($row['content'], 'href="news');
  449. $total_wlinks = $total_wlinks+substr_count($row['content'], "[[");
  450. $total_images = $total_images+substr_count($row['content'], "<img");
  451. $clean_total_flash = preg_replace('/player.swf/', ' ', $row['content']);
  452. $total_flash = $total_flash+substr_count($clean_total_flash, '.swf"');//.swf" end quotes prevent insert swf through flvplayer (is not counted)
  453. $total_mp3 = $total_mp3+substr_count($row['content'], ".mp3");
  454. $total_flv_p = $total_flv_p+substr_count($row['content'], ".flv");
  455. $total_flv = $total_flv_p/5;
  456. $total_youtube = $total_youtube+substr_count($row['content'], "http://www.youtube.com");
  457. $total_multimedia = $total_multimedia+substr_count($row['content'], "video/x-msvideo");
  458. $total_tables = $total_tables+substr_count($row['content'], "<table");
  459. }
  460. //check only last version of all pages (current page)
  461. $sql =' SELECT *, COUNT(*) AS TOTAL_PAGES, SUM(hits) AS TOTAL_VISITS_LV FROM '.$tbl_wiki.' s1
  462. WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
  463. $allpages=Database::query($sql);
  464. while ($row=Database::fetch_array($allpages)) {
  465. $total_pages = $row['TOTAL_PAGES'];
  466. $total_visits_lv = intval($row['TOTAL_VISITS_LV']);
  467. }
  468. $total_words_lv = 0;
  469. $total_links_lv = 0;
  470. $total_links_anchors_lv = 0;
  471. $total_links_mail_lv = 0;
  472. $total_links_ftp_lv = 0;
  473. $total_links_irc_lv = 0;
  474. $total_links_news_lv = 0;
  475. $total_wlinks_lv = 0;
  476. $total_images_lv = 0;
  477. $clean_total_flash_lv = 0;
  478. $total_flash_lv = 0;
  479. $total_mp3_lv = 0;
  480. $total_flv_p_lv = 0;
  481. $total_flv_lv = 0;
  482. $total_youtube_lv = 0;
  483. $total_multimedia_lv = 0;
  484. $total_tables_lv = 0;
  485. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
  486. $allpages=Database::query($sql);
  487. while ($row=Database::fetch_array($allpages)) {
  488. $total_words_lv = $total_words_lv+word_count($row['content']);
  489. $total_links_lv = $total_links_lv+substr_count($row['content'], "href=");
  490. $total_links_anchors_lv = $total_links_anchors_lv+substr_count($row['content'], 'href="#');
  491. $total_links_mail_lv = $total_links_mail_lv+substr_count($row['content'], 'href="mailto');
  492. $total_links_ftp_lv = $total_links_ftp_lv+substr_count($row['content'], 'href="ftp');
  493. $total_links_irc_lv = $total_links_irc_lv+substr_count($row['content'], 'href="irc');
  494. $total_links_news_lv = $total_links_news_lv+substr_count($row['content'], 'href="news');
  495. $total_wlinks_lv = $total_wlinks_lv+substr_count($row['content'], "[[");
  496. $total_images_lv = $total_images_lv+substr_count($row['content'], "<img");
  497. $clean_total_flash_lv = preg_replace('/player.swf/', ' ', $row['content']);
  498. $total_flash_lv = $total_flash_lv+substr_count($clean_total_flash_lv, '.swf"');//.swf" end quotes prevent insert swf through flvplayer (is not counted)
  499. $total_mp3_lv = $total_mp3_lv+substr_count($row['content'], ".mp3");
  500. $total_flv_p_lv = $total_flv_p_lv+substr_count($row['content'], ".flv");
  501. $total_flv_lv = $total_flv_p_lv/5;
  502. $total_youtube_lv = $total_youtube_lv+substr_count($row['content'], "http://www.youtube.com");
  503. $total_multimedia_lv = $total_multimedia_lv+substr_count($row['content'], "video/x-msvideo");
  504. $total_tables_lv = $total_tables_lv+substr_count($row['content'], "<table");
  505. }
  506. //Total pages edited at this time
  507. $total_editing_now=0;
  508. $sql='SELECT *, COUNT(*) AS TOTAL_EDITING_NOW FROM '.$tbl_wiki.' s1
  509. WHERE is_editing!=0 AND s1.c_id = '.$course_id.' AND
  510. id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';//Can not use group by because the mark is set in the latest version
  511. $allpages=Database::query($sql);
  512. while ($row=Database::fetch_array($allpages)) {
  513. $total_editing_now = $row['TOTAL_EDITING_NOW'];
  514. }
  515. //Total hidden pages
  516. $total_hidden=0;
  517. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND visibility=0 AND '.$groupfilter.$condition_session.' GROUP BY reflink';// or group by page_id. As the mark of hidden places it in all versions of the page, I can use group by to see the first
  518. $allpages=Database::query($sql);
  519. while ($row=Database::fetch_array($allpages)) {
  520. $total_hidden = $total_hidden+1;
  521. }
  522. //Total protect pages
  523. $total_protected=0;
  524. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND editlock=1 AND '.$groupfilter.$condition_session.' GROUP BY reflink';// or group by page_id. As the mark of protected page is the first version of the page, I can use group by
  525. $allpages=Database::query($sql);
  526. while ($row=Database::fetch_array($allpages)) {
  527. $total_protected = $total_protected+1;
  528. }
  529. //Total empty versions
  530. $total_empty_content=0;
  531. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND content="" AND '.$groupfilter.$condition_session.'';
  532. $allpages=Database::query($sql);
  533. while ($row=Database::fetch_array($allpages)) {
  534. $total_empty_content = $total_empty_content+1;
  535. }
  536. //Total empty pages (last version)
  537. $total_empty_content_lv=0;
  538. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  539. WHERE s1.c_id = '.$course_id.' AND content="" AND id=(
  540. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s1.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';
  541. $allpages=Database::query($sql);
  542. while ($row=Database::fetch_array($allpages)) {
  543. $total_empty_content_lv = $total_empty_content_lv+1;
  544. }
  545. //Total locked discuss pages
  546. $total_lock_disc=0;
  547. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND addlock_disc=0 AND '.$groupfilter.$condition_session.' GROUP BY reflink';//group by because mark lock in all vers, then always is ok
  548. $allpages=Database::query($sql);
  549. while ($row=Database::fetch_array($allpages)) {
  550. $total_lock_disc = $total_lock_disc+1;
  551. }
  552. //Total hidden discuss pages
  553. $total_hidden_disc=0;
  554. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND visibility_disc=0 AND '.$groupfilter.$condition_session.' GROUP BY reflink';//group by because mark lock in all vers, then always is ok
  555. $allpages=Database::query($sql);
  556. while ($row=Database::fetch_array($allpages)) {
  557. $total_hidden_disc = $total_hidden_disc+1;
  558. }
  559. //Total versions with any short comment by user or system
  560. $total_comment_version=0;
  561. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND comment!="" AND '.$groupfilter.$condition_session.'';
  562. $allpages=Database::query($sql);
  563. while ($row=Database::fetch_array($allpages)) {
  564. $total_comment_version = $total_comment_version+1;
  565. }
  566. //Total pages that can only be scored by teachers
  567. $total_only_teachers_rating=0;
  568. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND ratinglock_disc=0 AND '.$groupfilter.$condition_session.' GROUP BY reflink';//group by because mark lock in all vers, then always is ok
  569. $allpages=Database::query($sql);
  570. while ($row=Database::fetch_array($allpages)) {
  571. $total_only_teachers_rating = $total_only_teachers_rating+1;
  572. }
  573. //Total pages scored by peers
  574. $total_rating_by_peers=0;
  575. $total_rating_by_peers=$total_pages-$total_only_teachers_rating;//put always this line alfter check num all pages and num pages rated by teachers
  576. //Total pages identified as standard task
  577. $total_task=0;
  578. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.' WHERE '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND '.$tbl_wiki_conf.'.task!="" AND '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND '.$tbl_wiki.'.'.$groupfilter.$condition_session;
  579. $allpages=Database::query($sql);
  580. while ($row=Database::fetch_array($allpages)) {
  581. $total_task=$total_task+1;
  582. }
  583. //Total pages identified as teacher page (wiki portfolio mode - individual assignment)
  584. $total_teacher_assignment=0;
  585. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE s1.c_id = '.$course_id.' AND assignment=1 AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';//mark all versions, but do not use group by reflink because y want the pages not versions
  586. $allpages=Database::query($sql);
  587. while ($row=Database::fetch_array($allpages)) {
  588. $total_teacher_assignment=$total_teacher_assignment+1;
  589. }
  590. //Total pages identifies as student page (wiki portfolio mode - individual assignment)
  591. $total_student_assignment=0;
  592. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  593. WHERE s1.c_id = '.$course_id.' AND assignment=2 AND
  594. id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';//mark all versions, but do not use group by reflink because y want the pages not versions
  595. $allpages=Database::query($sql);
  596. while ($row=Database::fetch_array($allpages)) {
  597. $total_student_assignment=$total_student_assignment+1;
  598. }
  599. //Current Wiki status add new pages
  600. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY addlock';//group by because mark 0 in all vers, then always is ok
  601. $allpages=Database::query($sql);
  602. while ($row=Database::fetch_array($allpages)) {
  603. $wiki_add_lock=$row['addlock'];
  604. }
  605. if ($wiki_add_lock==1){
  606. $status_add_new_pag=get_lang('Yes');
  607. }
  608. else{
  609. $status_add_new_pag=get_lang('No');
  610. }
  611. //Creation date of the oldest wiki page and version
  612. $first_wiki_date='0000-00-00 00:00:00';
  613. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' ORDER BY dtime ASC LIMIT 1';
  614. $allpages=Database::query($sql);
  615. while ($row=Database::fetch_array($allpages)) {
  616. $first_wiki_date=$row['dtime'];
  617. }
  618. //Date of publication of the latest wiki version
  619. $last_wiki_date='0000-00-00 00:00:00';
  620. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' ORDER BY dtime DESC LIMIT 1';
  621. $allpages=Database::query($sql);
  622. while ($row=Database::fetch_array($allpages)) {
  623. $last_wiki_date=$row['dtime'];
  624. }
  625. //Average score of all wiki pages. (If a page has not scored zero rated)
  626. $media_score =0;
  627. $sql="SELECT *, SUM(score) AS TOTAL_SCORE FROM ".$tbl_wiki." WHERE c_id = $course_id AND ".$groupfilter.$condition_session." GROUP BY reflink ";//group by because mark in all versions, then always is ok. Do not use "count" because using "group by", would give a wrong value
  628. $allpages=Database::query($sql);
  629. while ($row=Database::fetch_array($allpages)) {
  630. $total_score=$total_score+$row['TOTAL_SCORE'];
  631. }
  632. if (!empty($total_pages)) {
  633. $media_score = $total_score/$total_pages;//put always this line alfter check num all pages
  634. }
  635. //Average user progress in his pages
  636. $media_progress=0;
  637. $sql='SELECT *, SUM(progress) AS TOTAL_PROGRESS FROM '.$tbl_wiki.' s1 WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')';//As the value is only the latest version I can not use group by
  638. $allpages=Database::query($sql);
  639. while ($row=Database::fetch_array($allpages)) {
  640. $total_progress = $row['TOTAL_PROGRESS'];
  641. }
  642. if (!empty($total_pages)) {
  643. $media_progress=$total_progress/$total_pages;//put always this line alfter check num all pages
  644. }
  645. //Total users that have participated in the Wiki
  646. $total_users=0;
  647. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY user_id';//as the mark of user it in all versions of the page, I can use group by to see the first
  648. $allpages=Database::query($sql);
  649. while ($row=Database::fetch_array($allpages)) {
  650. $total_users = $total_users+1;
  651. }
  652. //Total of different IP addresses that have participated in the wiki
  653. $total_ip=0;
  654. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY user_ip';
  655. $allpages=Database::query($sql);
  656. while ($row=Database::fetch_array($allpages)) {
  657. $total_ip = $total_ip+1;
  658. }
  659. ?>
  660. <style>
  661. thead {background:#E2E2E2}
  662. tbody tr:hover {
  663. background: #F9F9F9;
  664. cursor:default;
  665. }
  666. </style>
  667. <?php
  668. echo '<table width="100%" border="1">';
  669. echo '<thead>';
  670. echo '<tr>';
  671. echo '<td colspan="2">'.get_lang('General').'</td>';
  672. echo '</tr>';
  673. echo '</thead>';
  674. echo '<tr>';
  675. echo '<td>'.get_lang('StudentAddNewPages').'</td>';
  676. echo '<td>'.$status_add_new_pag.'</td>';
  677. echo '</tr>';
  678. echo '<tr>';
  679. echo '<td>'.get_lang('DateCreateOldestWikiPage').'</td>';
  680. echo '<td>'.$first_wiki_date.'</td>';
  681. echo '</tr>';
  682. echo '<tr>';
  683. echo '<td>'.get_lang('DateEditLatestWikiVersion').'</td>';
  684. echo '<td>'.$last_wiki_date.'</td>';
  685. echo '</tr>';
  686. echo '<tr>';
  687. echo '<td>'.get_lang('AverageScoreAllPages').'</td>';
  688. echo '<td>'.$media_score.' %</td>';
  689. echo '</tr>';
  690. echo '<tr>';
  691. echo '<td>'.get_lang('AverageMediaUserProgress').'</td>';
  692. echo '<td>'.$media_progress.' %</td>';
  693. echo '</tr>';
  694. echo '<tr>';
  695. echo '<td>'.get_lang('TotalWikiUsers').'</td>';
  696. echo '<td>'.$total_users.'</td>';
  697. echo '</tr>';
  698. echo '<tr>';
  699. echo '<td>'.get_lang('TotalIpAdress').'</td>';
  700. echo '<td>'.$total_ip.'</td>';
  701. echo '</tr>';
  702. echo '</table>';
  703. echo '<br/>';
  704. echo '<table width="100%" border="1">';
  705. echo '<thead>';
  706. echo '<tr>';
  707. echo '<td colspan="2">'.get_lang('Pages').' '.get_lang('And').' '.get_lang('Versions').'</td>';
  708. echo '</tr>';
  709. echo '</thead>';
  710. echo '<tr>';
  711. echo '<td>'.get_lang('Pages').' - '.get_lang('NumContributions').'</td>';
  712. echo '<td>'.$total_pages.' ('.get_lang('Versions').': '.$total_versions.')</td>';
  713. echo '</tr>';
  714. echo '<tr>';
  715. echo '<td>'.get_lang('EmptyPages').'</td>';
  716. echo '<td>'.$total_empty_content_lv.' ('.get_lang('Versions').': '.$total_empty_content.')</td>';
  717. echo '</tr>';
  718. echo '<tr>';
  719. echo '<td>'.get_lang('NumAccess').'</td>';
  720. echo '<td>'.$total_visits_lv.' ('.get_lang('Versions').': '.$total_visits.')</td>';
  721. echo '</tr>';
  722. echo '<tr>';
  723. echo '<td>'.get_lang('TotalPagesEditedAtThisTime').'</td>';
  724. echo '<td>'.$total_editing_now.'</td>';
  725. echo '</tr>';
  726. echo '<tr>';
  727. echo '<td>'.get_lang('TotalHiddenPages').'</td>';
  728. echo '<td>'.$total_hidden.'</td>';
  729. echo '</tr>';
  730. echo '<tr>';
  731. echo '<td>'.get_lang('NumProtectedPages').'</td>';
  732. echo '<td>'.$total_protected.'</td>';
  733. echo '</tr>';
  734. echo '<tr>';
  735. echo '<td>'.get_lang('LockedDiscussPages').'</td>';
  736. echo '<td>'.$total_lock_disc.'</td>';
  737. echo '</tr>';
  738. echo '<tr>';
  739. echo '<td>'.get_lang('HiddenDiscussPages').'</td>';
  740. echo '<td>'.$total_hidden_disc.'</td>';
  741. echo '</tr>';
  742. echo '<tr>';
  743. echo '<td>'.get_lang('TotalComments').'</td>';
  744. echo '<td>'.$total_comment_version.'</td>';
  745. echo '</tr>';
  746. echo '<tr>';
  747. echo '<td>'.get_lang('TotalOnlyRatingByTeacher').'</td>';
  748. echo '<td>'.$total_only_teachers_rating.'</td>';
  749. echo '</tr>';
  750. echo '<tr>';
  751. echo '<td>'.get_lang('TotalRatingPeers').'</td>';
  752. echo '<td>'.$total_rating_by_peers.'</td>';
  753. echo '</tr>';
  754. echo '<tr>';
  755. echo '<td>'.get_lang('TotalTeacherAssignments').' - '.get_lang('PortfolioMode').'</td>';
  756. echo '<td>'.$total_teacher_assignment.'</td>';
  757. echo '</tr>';
  758. echo '<tr>';
  759. echo '<td>'.get_lang('TotalStudentAssignments').' - '.get_lang('PortfolioMode').'</td>';
  760. echo '<td>'.$total_student_assignment.'</td>';
  761. echo '</tr>';
  762. echo '<tr>';
  763. echo '<td>'.get_lang('TotalTask').' - '.get_lang('StandardMode').'</td>';
  764. echo '<td>'.$total_task.'</td>';
  765. echo '</tr>';
  766. echo '</table>';
  767. echo '<br/>';
  768. echo '<table width="100%" border="1">';
  769. echo '<thead>';
  770. echo '<tr>';
  771. echo '<td colspan="3">'.get_lang('ContentPagesInfo').'</td>';
  772. echo '</tr>';
  773. echo '<tr>';
  774. echo '<td></td>';
  775. echo '<td>'.get_lang('InTheLastVersion').'</td>';
  776. echo '<td>'.get_lang('InAllVersions').'</td>';
  777. echo '</tr>';
  778. echo '</thead>';
  779. echo '<tr>';
  780. echo '<td>'.get_lang('NumWords').'</td>';
  781. echo '<td>'.$total_words_lv.'</td>';
  782. echo '<td>'.$total_words.'</td>';
  783. echo '</tr>';
  784. echo '<tr>';
  785. echo '<td>'.get_lang('NumlinksHtmlImagMedia').'</td>';
  786. echo '<td>'.$total_links_lv.' ('.get_lang('Anchors').':'.$total_links_anchors_lv.', Mail:'.$total_links_mail_lv.', FTP:'.$total_links_ftp_lv.' IRC:'.$total_links_irc_lv.', News:'.$total_links_news_lv.', ... ) </td>';
  787. echo '<td>'.$total_links.' ('.get_lang('Anchors').':'.$total_links_anchors.', Mail:'.$total_links_mail.', FTP:'.$total_links_ftp.', IRC:'.$total_links_irc.', News:'.$total_links_news.', ... ) </td>';
  788. echo '</tr>';
  789. echo '<tr>';
  790. echo '<td>'.get_lang('NumWikilinks').'</td>';
  791. echo '<td>'.$total_wlinks_lv.'</td>';
  792. echo '<td>'.$total_wlinks.'</td>';
  793. echo '</tr>';
  794. echo '<tr>';
  795. echo '<td>'.get_lang('NumImages').'</td>';
  796. echo '<td>'.$total_images_lv.'</td>';
  797. echo '<td>'.$total_images.'</td>';
  798. echo '</tr>';
  799. echo '<tr>';
  800. echo '<td>'.get_lang('NumFlash').'</td>';
  801. echo '<td>'.$total_flash_lv.'</td>';
  802. echo '<td>'.$total_flash.'</td>';
  803. echo '</tr>';
  804. echo '<tr>';
  805. echo '<td>'.get_lang('NumMp3').'</td>';
  806. echo '<td>'.$total_mp3_lv.'</td>';
  807. echo '<td>'.$total_mp3.'</td>';
  808. echo '</tr>';
  809. echo '<tr>';
  810. echo '<td>'.get_lang('NumFlvVideo').'</td>';
  811. echo '<td>'.$total_flv_lv.'</td>';
  812. echo '<td>'.$total_flv.'</td>';
  813. echo '</tr>';
  814. echo '<tr>';
  815. echo '<td>'.get_lang('NumYoutubeVideo').'</td>';
  816. echo '<td>'.$total_youtube_lv.'</td>';
  817. echo '<td>'.$total_youtube.'</td>';
  818. echo '</tr>';
  819. echo '<tr>';
  820. echo '<td>'.get_lang('NumOtherAudioVideo').'</td>';
  821. echo '<td>'.$total_multimedia_lv.'</td>';
  822. echo '<td>'.$total_multimedia.'</td>';
  823. echo '</tr>';
  824. echo '<tr>';
  825. echo '<td>'.get_lang('NumTables').'</td>';
  826. echo '<td>'.$total_tables_lv.'</td>';
  827. echo '<td>'.$total_tables.'</td>';
  828. echo '</tr>';
  829. echo '</table>';
  830. echo '<br/>';
  831. }
  832. // Most active users Juan Carlos Raña Trabado
  833. if ($_GET['action']=='mactiveusers') {
  834. echo '<div class="actions">'.get_lang('MostActiveUsers').'</div>';
  835. $sql='SELECT *, COUNT(*) AS NUM_EDIT FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY user_id';
  836. $allpages=Database::query($sql);
  837. //show table
  838. if (Database::num_rows($allpages) > 0) {
  839. $row = array ();
  840. while ($obj = Database::fetch_object($allpages)) {
  841. $userinfo = api_get_user_info($obj->user_id);
  842. $row = array ();
  843. if ($obj->user_id <> 0) {
  844. $row[] = '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  845. Display::tag('span', api_htmlentities($userinfo['complete_name_login_as'])).
  846. '</a><a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=usercontrib&user_id='.urlencode($row['user_id']).
  847. '&session_id='.intval($_GET['session_id']).'&group_id='.intval($_GET['group_id']).'"></a>';
  848. }
  849. else {
  850. $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
  851. }
  852. $row[] ='<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=usercontrib&user_id='.urlencode($obj->user_id).'&session_id='.intval($_GET['session_id']).'&group_id='.intval($_GET['group_id']).'">'.$obj->NUM_EDIT.'</a>';
  853. $rows[] = $row;
  854. }
  855. $table = new SortableTableFromArrayConfig($rows,1,10,'MostActiveUsersA_table','','','DESC');
  856. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>intval($_GET['session_id']),'group_id'=>intval($_GET['group_id'])));
  857. $table->set_header(0,get_lang('Author'), true);
  858. $table->set_header(1,get_lang('Contributions'), true,array ('style' => 'width:30px;'));
  859. $table->display();
  860. }
  861. }
  862. // User contributions Juan Carlos Raña Trabado
  863. if ($_GET['action']=='usercontrib') {
  864. $userinfo = api_get_user_info($_GET['user_id']);
  865. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
  866. echo '<div class="actions">'.get_lang('UserContributions').': <a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  867. Display::tag('span', api_htmlentities($userinfo['complete_name'])).
  868. '</a><a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=usercontrib&user_id='.urlencode($row['user_id']).
  869. '&session_id='.intval($_GET['session_id']).'&group_id='.intval($_GET['group_id']).'"></a></div>';
  870. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  871. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND user_id="'.Database::escape_string($_GET['user_id']).'"';
  872. } else {
  873. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND user_id="'.Database::escape_string($_GET['user_id']).'" AND visibility=1';
  874. }
  875. $allpages=Database::query($sql);
  876. //show table
  877. if (Database::num_rows($allpages) > 0) {
  878. $row = array ();
  879. while ($obj = Database::fetch_object($allpages)) {
  880. //get author
  881. //$userinfo=api_get_user_info($obj->user_id);
  882. //get time
  883. $year = substr($obj->dtime, 0, 4);
  884. $month = substr($obj->dtime, 5, 2);
  885. $day = substr($obj->dtime, 8, 2);
  886. $hours = substr($obj->dtime, 11,2);
  887. $minutes = substr($obj->dtime, 14,2);
  888. $seconds = substr($obj->dtime, 17,2);
  889. //get type assignment icon
  890. if ($obj->assignment==1) {
  891. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
  892. } elseif ($obj->assignment==2) {
  893. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  894. } elseif ($obj->assignment==0) {
  895. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  896. }
  897. $row = array ();
  898. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  899. $row[] =$ShowAssignment;
  900. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&view='.$obj->id.'&session_id='.Security::remove_XSS($_GET['$session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.api_htmlentities($obj->title).'</a>';
  901. $row[] =Security::remove_XSS($obj->version);
  902. $row[] =Security::remove_XSS($obj->comment);
  903. $row[] =Security::remove_XSS($obj->progress).' %';
  904. $row[] =Security::remove_XSS($obj->score);
  905. $rows[] = $row;
  906. }
  907. $table = new SortableTableFromArrayConfig($rows,2,10,'UsersContributions_table','','','ASC');
  908. $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']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  909. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  910. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  911. $table->set_header(2,get_lang('Title'), true, array ('style' => 'width:200px;'));
  912. $table->set_header(3,get_lang('Version'), true, array ('style' => 'width:30px;'));
  913. $table->set_header(4,get_lang('Comment'), true, array ('style' => 'width:200px;'));
  914. $table->set_header(5,get_lang('Progress'), true, array ('style' => 'width:30px;'));
  915. $table->set_header(6,get_lang('Rating'), true, array ('style' => 'width:30px;'));
  916. //if(api_is_allowed_to_edit() || api_is_platform_admin())
  917. //{
  918. //$table->set_header(7,get_lang('IP'), true, array ('style' => 'width:30px;'));
  919. //}
  920. $table->display();
  921. }
  922. }
  923. /////////////////////// Most changed pages /////////////////////// Juan Carlos Raña Trabado
  924. if ($_GET['action']=='mostchanged') {
  925. echo '<div class="actions">'.get_lang('MostChangedPages').'</div>';
  926. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  927. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY reflink';//TODO:check MAX and group by return last version
  928. } else {
  929. $sql='SELECT *, MAX(version) AS MAX FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1 GROUP BY reflink'; //TODO:check MAX and group by return last version
  930. }
  931. $allpages=Database::query($sql);
  932. //show table
  933. if (Database::num_rows($allpages) > 0) {
  934. $row = array ();
  935. while ($obj = Database::fetch_object($allpages)) {
  936. //get type assignment icon
  937. if ($obj->assignment==1) {
  938. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  939. } elseif ($obj->assignment==2) {
  940. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  941. } elseif ($obj->assignment==0) {
  942. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  943. }
  944. $row = array ();
  945. $row[] =$ShowAssignment;
  946. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.api_htmlentities($obj->title).'</a>';
  947. $row[] = $obj->MAX;
  948. $rows[] = $row;
  949. }
  950. $table = new SortableTableFromArrayConfig($rows,2,10,'MostChangedPages_table','','','DESC');
  951. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  952. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  953. $table->set_header(1,get_lang('Title'), true);
  954. $table->set_header(2,get_lang('Changes'), true);
  955. $table->display();
  956. }
  957. }
  958. /////////////////////// Most visited pages /////////////////////// Juan Carlos Raña Trabado
  959. if ($_GET['action']=='mvisited') {
  960. echo '<div class="actions">'.get_lang('MostVisitedPages').'</div>';
  961. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  962. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY reflink';
  963. } else {
  964. $sql='SELECT *, SUM(hits) AS tsum FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1 GROUP BY reflink';
  965. }
  966. $allpages=Database::query($sql);
  967. //show table
  968. if (Database::num_rows($allpages) > 0) {
  969. $row = array ();
  970. while ($obj = Database::fetch_object($allpages)) {
  971. //get type assignment icon
  972. if ($obj->assignment==1) {
  973. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  974. } elseif ($obj->assignment==2) {
  975. $ShowAssignment=$ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  976. } elseif ($obj->assignment==0) {
  977. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  978. }
  979. $row = array ();
  980. $row[] =$ShowAssignment;
  981. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.api_htmlentities($obj->title).'</a>';
  982. $row[] = $obj->tsum;
  983. $rows[] = $row;
  984. }
  985. $table = new SortableTableFromArrayConfig($rows,2,10,'MostVisitedPages_table','','','DESC');
  986. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  987. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  988. $table->set_header(1,get_lang('Title'), true);
  989. $table->set_header(2,get_lang('Visits'), true);
  990. $table->display();
  991. }
  992. }
  993. /////////////////////// Wanted pages /////////////////////// Juan Carlos Raña Trabado
  994. if ($_GET['action']=='wanted') {
  995. echo '<div class="actions">'.get_lang('WantedPages').'</div>';
  996. $pages = array();
  997. $refs = array();
  998. $wanted = array();
  999. //get name pages
  1000. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY reflink ORDER BY reflink ASC';
  1001. $allpages=Database::query($sql);
  1002. while ($row=Database::fetch_array($allpages)) {
  1003. if ($row['reflink']=='index'){
  1004. $row['reflink']=str_replace(' ','_',get_lang('DefaultTitle'));
  1005. }
  1006. $pages[] = $row['reflink'];
  1007. }
  1008. //get name refs in last pages
  1009. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  1010. WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.$condition_session.')';
  1011. $allpages=Database::query($sql);
  1012. while ($row=Database::fetch_array($allpages)) {
  1013. $refs = explode(" ", trim($row["linksto"]));
  1014. // Find linksto into reflink. If not found ->page is wanted
  1015. foreach ($refs as $v) {
  1016. if (!in_array($v, $pages)) {
  1017. if (trim($v)!="") {
  1018. $wanted[]=$v;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. $wanted=array_unique($wanted);//make a unique list
  1024. //show table
  1025. foreach ($wanted as $wanted_show) {
  1026. $row = array ();
  1027. $wanted_show=Security::remove_XSS($wanted_show);
  1028. $row[] = '<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?cidReq=&action=addnew&title='.str_replace('_',' ',$wanted_show).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'" class="new_wiki_link">'.str_replace('_',' ',$wanted_show).'</a>';
  1029. $rows[] = $row;
  1030. }
  1031. $table = new SortableTableFromArrayConfig($rows,0,10,'WantedPages_table','','','DESC');
  1032. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1033. $table->set_header(0,get_lang('Title'), true);
  1034. $table->display();
  1035. }
  1036. /////////////////////// Orphaned pages /////////////////////// Juan Carlos Raña Trabado
  1037. if ($_GET['action']=='orphaned') {
  1038. echo '<div class="actions">'.get_lang('OrphanedPages').'</div>';
  1039. $pages = array();
  1040. $refs = array();
  1041. $list_refs = array();
  1042. $orphaned = array();
  1043. //get name pages
  1044. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY reflink ORDER BY reflink ASC';
  1045. $allpages=Database::query($sql);
  1046. while ($row=Database::fetch_array($allpages)) {
  1047. $pages[] = $row['reflink'];
  1048. }
  1049. //get name refs in last pages and make a unique list
  1050. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  1051. WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.$condition_session.')';
  1052. $allpages=Database::query($sql);
  1053. while ($row=Database::fetch_array($allpages)) {
  1054. $row['linksto']= str_replace($row["reflink"], " ", trim($row["linksto"])); //remove self reference
  1055. $refs = explode(" ", trim($row["linksto"]));
  1056. foreach ($refs as $ref_linked){
  1057. if ($ref_linked==str_replace(' ','_',get_lang('DefaultTitle'))) {
  1058. $ref_linked='index';
  1059. }
  1060. $array_refs_linked[]= $ref_linked;
  1061. }
  1062. }
  1063. $array_refs_linked = array_unique($array_refs_linked);
  1064. //search each name of list linksto into list reflink
  1065. foreach ($pages as $v) {
  1066. if (!in_array($v, $array_refs_linked)) {
  1067. $orphaned[] = $v;
  1068. }
  1069. }
  1070. foreach ($orphaned as $orphaned_show) {
  1071. // get visibility status and title
  1072. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND reflink="'.Database::escape_string($orphaned_show).'" GROUP BY reflink';
  1073. $allpages=Database::query($sql);
  1074. while ($row=Database::fetch_array($allpages)) {
  1075. $orphaned_title=$row['title'];
  1076. $orphaned_visibility=$row['visibility'];
  1077. if ($row['assignment']==1) {
  1078. $ShowAssignment=Display::return_icon('wiki_assignment.png','','',ICON_SIZE_SMALL);
  1079. } elseif ($row['assignment']==2) {
  1080. $ShowAssignment=Display::return_icon('wiki_work.png','','',ICON_SIZE_SMALL);
  1081. } elseif ($row['assignment']==0) {
  1082. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1083. }
  1084. }
  1085. if (!api_is_allowed_to_edit(false,true) || !api_is_platform_admin() AND $orphaned_visibility==0){
  1086. continue;
  1087. }
  1088. //show table
  1089. $row = array ();
  1090. $row[] =$ShowAssignment;
  1091. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($orphaned_show)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.api_htmlentities($orphaned_title).'</a>';
  1092. $rows[] = $row;
  1093. }
  1094. $table = new SortableTableFromArrayConfig($rows,1,10,'OrphanedPages_table','','','DESC');
  1095. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1096. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1097. $table->set_header(1,get_lang('Title'), true);
  1098. $table->display();
  1099. }
  1100. /////////////////////// Most linked pages /////////////////////// Juan Carlos Raña Trabado
  1101. if ($_GET['action']=='mostlinked') {
  1102. echo '<div class="actions">'.get_lang('MostLinkedPages').'</div>';
  1103. $pages = array();
  1104. $refs = array();
  1105. $linked = array();
  1106. //get name pages
  1107. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' GROUP BY reflink ORDER BY reflink ASC';
  1108. $allpages=Database::query($sql);
  1109. while ($row=Database::fetch_array($allpages)) {
  1110. if ($row['reflink']=='index'){
  1111. $row['reflink']=str_replace(' ','_',get_lang('DefaultTitle'));
  1112. }
  1113. $pages[] = $row['reflink'];
  1114. }
  1115. //get name refs in last pages
  1116. $sql='SELECT * FROM '.$tbl_wiki.' s1 WHERE s1.c_id = '.$course_id.' AND id=(SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.$condition_session.')';
  1117. $allpages=Database::query($sql);
  1118. while ($row=Database::fetch_array($allpages)) {
  1119. $row['linksto']= str_replace($row["reflink"], " ", trim($row["linksto"])); //remove self reference
  1120. $refs = explode(" ", trim($row["linksto"]));
  1121. // Find linksto into reflink. If found ->page is linked
  1122. foreach ($refs as $v) {
  1123. if (in_array($v, $pages)) {
  1124. if (trim($v)!="") {
  1125. $linked[]=$v;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. $linked=array_unique($linked);//make a unique list. TODO:delete this line and count how many for each page
  1131. //show table
  1132. foreach ($linked as $linked_show) {
  1133. $row = array ();
  1134. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode(str_replace('_',' ',$linked_show))).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.str_replace('_',' ',$linked_show).'</a>';
  1135. $rows[] = $row;
  1136. }
  1137. $table = new SortableTableFromArrayConfig($rows,0,10,'LinkedPages_table','','','DESC');
  1138. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1139. $table->set_header(0,get_lang('Title'), true);
  1140. $table->display();
  1141. }
  1142. /////////////////////// delete current page /////////////////////// Juan Carlos Raña Trabado
  1143. if ($_GET['action']=='delete') {
  1144. if (!$_GET['title']) {
  1145. Display::display_error_message(get_lang('MustSelectPage'));
  1146. exit;
  1147. }
  1148. echo '<div style="overflow:hidden">';
  1149. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  1150. echo '<div id="wikititle">'.get_lang('DeletePageHistory').'</div>';
  1151. if ($page=="index") {
  1152. Display::display_warning_message(get_lang('WarningDeleteMainPage'),false);
  1153. }
  1154. $message = get_lang('ConfirmDeletePage')."</p>"."<p>"."<a href=\"index.php\">".get_lang("No")."</a>"."&nbsp;&nbsp;|&nbsp;&nbsp;"."<a href=\"".api_get_self()."?action=delete&amp;title=".api_htmlentities(urlencode($page))."&amp;delete=yes\">".get_lang("Yes")."</a>"."</p>";
  1155. if (!isset ($_GET['delete'])) {
  1156. Display::display_warning_message($message,false);
  1157. }
  1158. if ($_GET['delete'] == 'yes') {
  1159. $sql='DELETE '.$tbl_wiki_discuss.' FROM '.$tbl_wiki.', '.$tbl_wiki_discuss.'
  1160. WHERE '.$tbl_wiki.'.c_id = '.$course_id.' AND '.$tbl_wiki_discuss.'.c_id = '.$course_id.' AND '.$tbl_wiki.'.reflink="'.Database::escape_string($page).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki.'.session_id='.$session_id.' AND '.$tbl_wiki_discuss.'.publication_id='.$tbl_wiki.'.id';
  1161. Database::query($sql);
  1162. $sql='DELETE '.$tbl_wiki_mailcue.' FROM '.$tbl_wiki.', '.$tbl_wiki_mailcue.'
  1163. WHERE '.$tbl_wiki.'.c_id = '.$course_id.' AND '.$tbl_wiki_mailcue.'.c_id = '.$course_id.' AND '.$tbl_wiki.'.reflink="'.Database::escape_string($page).'" AND '.$tbl_wiki.'.'.$groupfilter.' AND '.$tbl_wiki.'.session_id='.$session_id.' AND '.$tbl_wiki_mailcue.'.id='.$tbl_wiki.'.id';
  1164. Database::query($sql);
  1165. $sql='DELETE FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.'';
  1166. Database::query($sql);
  1167. check_emailcue(0, 'E');
  1168. Display::display_confirmation_message(get_lang('WikiPageDeleted'));
  1169. }
  1170. } else {
  1171. Display::display_normal_message(get_lang("OnlyAdminDeletePageWiki"));
  1172. }
  1173. echo '</div>';
  1174. }
  1175. /////////////////////// delete all wiki /////////////////////// Juan Carlos Raña Trabado
  1176. if ($_GET['action']=='deletewiki') {
  1177. echo '<div class="actions">'.get_lang('DeleteWiki').'</div>';
  1178. echo '<div style="overflow:hidden">';
  1179. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  1180. $message = get_lang('ConfirmDeleteWiki');
  1181. $message .= '<p>
  1182. <a href="index.php">'.get_lang('No').'</a>
  1183. &nbsp;&nbsp;|&nbsp;&nbsp;
  1184. <a href="'.api_get_self().'?action=deletewiki&amp;delete=yes">'.get_lang('Yes').'</a>
  1185. </p>';
  1186. if (!isset($_GET['delete'])) {
  1187. Display::display_warning_message($message,false);
  1188. }
  1189. } else {
  1190. Display::display_normal_message(get_lang("OnlyAdminDeleteWiki"));
  1191. }
  1192. echo '</div>';
  1193. }
  1194. /////////////////////// search wiki pages ///////////////////////
  1195. if ($_GET['action']=='searchpages') {
  1196. echo '<div class="actions">'.get_lang('SearchPages').'</div>';
  1197. echo '<div style="overflow:hidden">';
  1198. if ($_GET['mode_table']) {
  1199. if (! $_GET['SearchPages_table_page_nr']) {
  1200. $_GET['search_term']=$_POST['search_term'];
  1201. $_GET['search_content']=$_POST['search_content'];
  1202. $_GET['all_vers']=$_POST['all_vers'];
  1203. }
  1204. display_wiki_search_results(api_htmlentities($_GET['search_term']),api_htmlentities($_GET['search_content']),api_htmlentities($_GET['all_vers']));
  1205. } else {
  1206. // initiate the object
  1207. $form = new FormValidator('wiki_search','post', api_get_self().'?cidReq='.Security::remove_XSS($_GET['cidReq']).'&action='.Security::remove_XSS($_GET['action']).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'&mode_table=yes1&search_term='.Security::remove_XSS($_GET['search_term']).'&search_content='.Security::remove_XSS($_GET['search_content']).'&all_vers='.Security::remove_XSS($_GET['all_vers']));
  1208. // settting the form elements
  1209. $form->addElement('text', 'search_term', get_lang('SearchTerm'),'class="input_titles" id="search_title"');
  1210. $form->addElement('checkbox', 'search_content', null, get_lang('AlsoSearchContent'));
  1211. $form->addElement('checkbox', 'all_vers', null, get_lang('IncludeAllVersions'));
  1212. $form->addElement('style_submit_button', 'SubmitWikiSearch', get_lang('Search'), 'class="search"');
  1213. // setting the rules
  1214. $form->addRule('search_term', get_lang('ThisFieldIsRequired'), 'required');
  1215. $form->addRule('search_term', get_lang('TooShort'),'minlength',3); //TODO: before fixing the pagination rules worked, not now
  1216. if ($form->validate()) {
  1217. $form->display();
  1218. $values = $form->exportValues();
  1219. display_wiki_search_results($values['search_term'], $values['search_content'], $values['all_vers']);
  1220. } else {
  1221. $form->display();
  1222. }
  1223. }
  1224. echo '</div>';
  1225. }
  1226. /////////////////////// What links here. Show pages that have linked this page /////////////////////// Juan Carlos Raña Trabado
  1227. if ($_GET['action']=='links') {
  1228. if (!$_GET['title']) {
  1229. Display::display_error_message(get_lang("MustSelectPage"));
  1230. } else {
  1231. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.'';
  1232. $result=Database::query($sql);
  1233. $row=Database::fetch_array($result);
  1234. //get type assignment icon
  1235. if ($row['assignment']==1) {
  1236. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  1237. } elseif ($row['assignment']==2) {
  1238. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  1239. } elseif ($row['assignment']==0) {
  1240. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1241. }
  1242. //fix Title to reflink (link Main Page)
  1243. if ($page==get_lang('DefaultTitle')) {
  1244. $page='index';
  1245. }
  1246. echo '<div id="wikititle">';
  1247. echo get_lang('LinksPagesFrom').': '.$ShowAssignment.' <a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.Security::remove_XSS($page).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($row['title']).'</a>';
  1248. echo '</div>';
  1249. //fix index to title Main page into linksto
  1250. if ($page=='index') {
  1251. $page=str_replace(' ','_',get_lang('DefaultTitle'));
  1252. }
  1253. //table
  1254. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  1255. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND linksto LIKE '%".Database::escape_string($page)." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";//add blank space after like '%" " %' to identify each word
  1256. } else {
  1257. $sql="SELECT * FROM ".$tbl_wiki." s1 WHERE s1.c_id = $course_id AND visibility=1 AND linksto LIKE '%".Database::escape_string($page)." %' AND id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";//add blank space after like '%" " %' to identify each word
  1258. }
  1259. $allpages=Database::query($sql);
  1260. //show table
  1261. if (Database::num_rows($allpages) > 0) {
  1262. $row = array ();
  1263. while ($obj = Database::fetch_object($allpages)) {
  1264. //get author
  1265. $userinfo = api_get_user_info($obj->user_id);
  1266. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
  1267. //get time
  1268. $year = substr($obj->dtime, 0, 4);
  1269. $month = substr($obj->dtime, 5, 2);
  1270. $day = substr($obj->dtime, 8, 2);
  1271. $hours = substr($obj->dtime, 11,2);
  1272. $minutes = substr($obj->dtime, 14,2);
  1273. $seconds = substr($obj->dtime, 17,2);
  1274. //get type assignment icon
  1275. if ($obj->assignment==1) {
  1276. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  1277. } elseif ($obj->assignment==2) {
  1278. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  1279. } elseif ($obj->assignment==0) {
  1280. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1281. }
  1282. $row = array ();
  1283. $row[] =$ShowAssignment;
  1284. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.Security::remove_XSS($obj->reflink).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($obj->title).'</a>';
  1285. if ($obj->user_id <>0) {
  1286. $row[] = '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  1287. Display::tag('span', api_htmlentities($userinfo['complete_name_login_as'])).'</a>';
  1288. }
  1289. else {
  1290. $row[] = get_lang('Anonymous').' ('.$obj->user_ip.')';
  1291. }
  1292. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  1293. $rows[] = $row;
  1294. }
  1295. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  1296. $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'])));
  1297. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1298. $table->set_header(1,get_lang('Title'), true);
  1299. $table->set_header(2,get_lang('Author'), true);
  1300. $table->set_header(3,get_lang('Date'), true);
  1301. $table->display();
  1302. }
  1303. }
  1304. }
  1305. // Adding a new page
  1306. // Display the form for adding a new wiki page
  1307. echo '<div style="overflow:hidden">';
  1308. if ($_GET['action']=='addnew') {
  1309. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  1310. api_not_allowed();
  1311. }
  1312. echo '<div class="actions">'.get_lang('AddNew').'</div>';
  1313. echo '<br/>';
  1314. //first, check if page index was created. chektitle=false
  1315. if (checktitle('index')) {
  1316. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid'])) {
  1317. Display::display_normal_message(get_lang('GoAndEditMainPage'));
  1318. } else {
  1319. return Display::display_normal_message(get_lang('WikiStandBy'));
  1320. }
  1321. } elseif (check_addnewpagelock()==0 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) {
  1322. Display::display_error_message(get_lang('AddPagesLocked'));
  1323. } else {
  1324. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'],$_SESSION['_gid']) || Security::remove_XSS($_GET['group_id'])==0) {
  1325. display_new_wiki_form();
  1326. } else {
  1327. Display::display_normal_message(get_lang('OnlyAddPagesGroupMembers'));
  1328. }
  1329. }
  1330. }
  1331. // Show home page
  1332. if (!$_GET['action'] OR $_GET['action']=='show' AND !isset($_POST['SaveWikiNew'])) {
  1333. display_wiki_entry($newtitle);
  1334. }
  1335. // Show current page
  1336. if ($_GET['action']=='showpage' AND !isset($_POST['SaveWikiNew'])) {
  1337. if ($_GET['title']) {
  1338. display_wiki_entry($newtitle);
  1339. } else {
  1340. Display::display_error_message(get_lang('MustSelectPage'));
  1341. }
  1342. }
  1343. // Edit current page
  1344. if ($_GET['action']=='edit') {
  1345. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  1346. api_not_allowed();
  1347. }
  1348. $_clean['group_id']=(int)$_SESSION['_gid'];
  1349. $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
  1350. WHERE
  1351. '.$tbl_wiki.'.c_id = '.$course_id.' AND
  1352. '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND
  1353. '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
  1354. '.$tbl_wiki.'.reflink="'.Database::escape_string($page).'" AND
  1355. '.$tbl_wiki.'.'.$groupfilter.$condition_session.'
  1356. ORDER BY id DESC';
  1357. $result=Database::query($sql);
  1358. $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
  1359. if ($row['content']=='' AND $row['title']=='' AND $page=='') {
  1360. Display::display_error_message(get_lang('MustSelectPage'));
  1361. exit;
  1362. } elseif ($row['content']=='' AND $row['title']=='' AND $page=='index') {
  1363. //Table structure for better export to pdf
  1364. $default_table_for_content_Start='<table align="center" border="0"><tr><td align="center">';
  1365. $default_table_for_content_End='</td></tr></table>';
  1366. $content=$default_table_for_content_Start.sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)).$default_table_for_content_End;
  1367. $title=get_lang('DefaultTitle');
  1368. $page_id=0;
  1369. } else {
  1370. $content = api_html_entity_decode($row['content']);
  1371. $title = api_html_entity_decode($row['title']);
  1372. $page_id = $row['page_id'];
  1373. }
  1374. //Only teachers and platform admin can edit the index page. Only teachers and platform admin can edit an assignment teacher. And users in groups
  1375. if (($row['reflink']=='index' || $row['reflink']=='' || $row['assignment']==1) && (!api_is_allowed_to_edit(false,true) && $_GET['group_id'] == 0)) {
  1376. Display::display_error_message(get_lang('OnlyEditPagesCourseManager'));
  1377. } else {
  1378. $PassEdit=false;
  1379. //check if is a wiki group
  1380. if ($_clean['group_id']!=0) {
  1381. //Only teacher, platform admin and group members can edit a wiki group
  1382. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group($_user['user_id'], $_GET['group_id'])) {
  1383. $PassEdit=true;
  1384. } else {
  1385. Display::display_normal_message(get_lang('OnlyEditPagesGroupMembers'));
  1386. }
  1387. } else {
  1388. $PassEdit=true;
  1389. }
  1390. // check if is a assignment
  1391. if ($row['assignment']==1) {
  1392. Display::display_normal_message(get_lang('EditAssignmentWarning'));
  1393. $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
  1394. } elseif ($row['assignment']==2) {
  1395. $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
  1396. if ((api_get_user_id()==$row['user_id'])==false) {
  1397. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  1398. $PassEdit=true;
  1399. } else {
  1400. Display::display_warning_message(get_lang('LockByTeacher'));
  1401. $PassEdit=false;
  1402. }
  1403. } else {
  1404. $PassEdit=true;
  1405. }
  1406. }
  1407. if ($PassEdit) { //show editor if edit is allowed
  1408. if ($row['editlock']==1 && (api_is_allowed_to_edit(false,true)==false || api_is_platform_admin()==false)) {
  1409. Display::display_normal_message(get_lang('PageLockedExtra'));
  1410. } else {
  1411. //check tasks
  1412. if (!empty($row['startdate_assig']) && $row['startdate_assig']!='0000-00-00 00:00:00' && time()<strtotime($row['startdate_assig'])) {
  1413. $message=get_lang('TheTaskDoesNotBeginUntil').': '.api_get_local_time($row['startdate_assig'], null, date_default_timezone_get());
  1414. Display::display_warning_message($message);
  1415. if (!api_is_allowed_to_edit(false,true)) {
  1416. exit;
  1417. }
  1418. }
  1419. //
  1420. if (!empty($row['enddate_assig']) && $row['enddate_assig']!='0000-00-00 00:00:00' && time()>strtotime($row['enddate_assig']) && $row['enddate_assig']!='0000-00-00 00:00:00' && $row['delayedsubmit']==0) {
  1421. $message=get_lang('TheDeadlineHasBeenCompleted').': '.api_get_local_time($row['enddate_assig'], null, date_default_timezone_get());
  1422. Display::display_warning_message($message);
  1423. if (!api_is_allowed_to_edit(false,true)) {
  1424. exit;
  1425. }
  1426. }
  1427. //
  1428. if (!empty($row['max_version']) && $row['version']>=$row['max_version']) {
  1429. $message=get_lang('HasReachedMaxiNumVersions');
  1430. Display::display_warning_message($message);
  1431. if (!api_is_allowed_to_edit(false,true)) {
  1432. exit;
  1433. }
  1434. }
  1435. //
  1436. if (!empty($row['max_text']) && $row['max_text']<=word_count($row['content'])) {
  1437. $message=get_lang('HasReachedMaxNumWords');
  1438. Display::display_warning_message($message);
  1439. if (!api_is_allowed_to_edit(false,true)) {
  1440. exit;
  1441. }
  1442. }
  1443. ////
  1444. if (!empty($row['task'])) {
  1445. //previous change 0 by text
  1446. if ($row['startdate_assig']=='0000-00-00 00:00:00') {
  1447. $message_task_startdate=get_lang('No');
  1448. } else {
  1449. $message_task_startdate=api_get_local_time($row['startdate_assig'], null, date_default_timezone_get());
  1450. }
  1451. if ($row['enddate_assig']=='0000-00-00 00:00:00') {
  1452. $message_task_enddate=get_lang('No');
  1453. } else {
  1454. $message_task_endate=api_get_local_time($row['enddate_assig'], null, date_default_timezone_get());
  1455. }
  1456. if ($row['delayedsubmit']==0) {
  1457. $message_task_delayedsubmit=get_lang('No');
  1458. } else {
  1459. $message_task_delayedsubmit=get_lang('Yes');
  1460. }
  1461. if ($row['max_version']==0) {
  1462. $message_task_max_version=get_lang('No');
  1463. } else {
  1464. $message_task_max_version=$row['max_version'];
  1465. }
  1466. if ($row['max_text']==0) {
  1467. $message_task_max_text=get_lang('No');
  1468. } else {
  1469. $message_task_max_text=$row['max_text'];
  1470. }
  1471. //comp message
  1472. $message_task='<b>'.get_lang('DescriptionOfTheTask').'</b><p>'.$row['task'].'</p><hr>';
  1473. $message_task.='<p>'.get_lang('StartDate').': '.$message_task_startdate.'</p>';
  1474. $message_task.='<p>'.get_lang('EndDate').': '.$message_task_enddate;
  1475. $message_task.=' ('.get_lang('AllowLaterSends').') '.$message_task_delayedsubmit.'</p>';
  1476. $message_task.='<p>'.get_lang('OtherSettings').': '.get_lang('NMaxVersion').': '.$message_task_max_version;
  1477. $message_task.=' '.get_lang('NMaxWords').': '.$message_task_max_text;
  1478. //display message
  1479. Display::display_normal_message($message_task,false);
  1480. }
  1481. if ($row['progress']==$row['fprogress1'] && !empty($row['fprogress1'])) {
  1482. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback1']).'</p>';
  1483. Display::display_normal_message($feedback_message, false);
  1484. } elseif ($row['progress']==$row['fprogress2'] && !empty($row['fprogress2'])) {
  1485. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback2']).'</p>';
  1486. Display::display_normal_message($feedback_message, false);
  1487. } elseif ($row['progress']==$row['fprogress3'] && !empty($row['fprogress3'])) {
  1488. $feedback_message='<b>'.get_lang('Feedback').'</b><p>'.api_htmlentities($row['feedback3']).'</p>';
  1489. Display::display_normal_message($feedback_message, false);
  1490. }
  1491. //previous checking for concurrent editions
  1492. if ($row['is_editing']==0) {
  1493. echo '<div style="z-index:0">';
  1494. Display::display_normal_message(get_lang('WarningMaxEditingTime'));
  1495. echo '</div>';
  1496. $time_edit = date("Y-m-d H:i:s");
  1497. $sql='UPDATE '.$tbl_wiki.' SET is_editing="'.$_user['user_id'].'", time_edit="'.$time_edit.'" WHERE c_id = '.$course_id.' AND id="'.$row['id'].'"';
  1498. Database::query($sql);
  1499. } elseif ($row['is_editing']!=$_user['user_id']) {
  1500. $timestamp_edit=strtotime($row['time_edit']);
  1501. $time_editing=time()-$timestamp_edit;
  1502. $max_edit_time=1200; // 20 minutes
  1503. $rest_time=$max_edit_time-$time_editing;
  1504. $userinfo = api_get_user_info($row['is_editing']);
  1505. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
  1506. $is_being_edited= get_lang('ThisPageisBeginEditedBy').
  1507. ' <a href=../user/userInfo.php?uInfo='.
  1508. $userinfo['user_id'].'>'.
  1509. Display::tag('span', api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])), array('title'=>$username)).
  1510. '</a>. '.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
  1511. Display::display_normal_message($is_being_edited, false);
  1512. exit;
  1513. }
  1514. //form
  1515. echo '<form name="form1" method="post" action="'.api_get_self().'?action=showpage&amp;title='.api_htmlentities(urlencode($page)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">';
  1516. echo '<div id="wikititle">';
  1517. echo '<div style="width:70%;float:left;">'.$icon_assignment.str_repeat('&nbsp;',3).api_htmlentities($title).'</div>';
  1518. if ((api_is_allowed_to_edit(false,true) || api_is_platform_admin()) && $row['reflink']!='index') {
  1519. echo'<a href="javascript://" onclick="advanced_parameters()" ><span id="plus_minus" style="float:right">&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'</span></a>';
  1520. echo '<div id="options" style="display:none; margin: 20px;" >';
  1521. //task
  1522. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktask" onclick="javascript: if(this.checked){document.getElementById(\'option4\').style.display=\'block\';}else{document.getElementById(\'option4\').style.display=\'none\';}"/>&nbsp;'.Display::return_icon('wiki_task.png', get_lang('DefineTask'),'',ICON_SIZE_SMALL).' '.get_lang('DescriptionOfTheTask').'';
  1523. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error4" style="display:none;color:red"></span>';
  1524. echo '<div id="option4" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1525. echo '<table border="0" style="font-weight:normal">';
  1526. echo '<tr>';
  1527. echo '<td>'.get_lang('DescriptionOfTheTask').'</td>';
  1528. echo '</tr>';
  1529. echo '<tr>';
  1530. echo '<td>'.api_disp_html_area('task', $row['task'], '', '', null, array('ToolbarSet' => 'wiki_task', 'Width' => '585', 'Height' => '200')).'</td>';
  1531. echo '</tr>';
  1532. echo '</table>';
  1533. echo '</div>';
  1534. //feedback
  1535. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkfeedback" onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display=\'block\';}else{document.getElementById(\'option2\').style.display=\'none\';}"/>&nbsp;'.get_lang('AddFeedback').'';
  1536. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error2" style="display:none;color:red"></span>';
  1537. echo '<div id="option2" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1538. echo '<table border="0" style="font-weight:normal" align="center">';
  1539. echo '<tr>';
  1540. echo '<td colspan="2">'.get_lang('Feedback1').'</td>';
  1541. echo '<td colspan="2">'.get_lang('Feedback2').'</td>';
  1542. echo '<td colspan="2">'.get_lang('Feedback3').'</td>';
  1543. echo '</tr>';
  1544. echo '<tr>';
  1545. echo '<td colspan="2"><textarea name="feedback1" cols="21" rows="4" >'.api_htmlentities($row['feedback1']).'</textarea></td>';
  1546. echo '<td colspan="2"><textarea name="feedback2" cols="21" rows="4" >'.api_htmlentities($row['feedback2']).'</textarea></td>';
  1547. echo '<td colspan="2"><textarea name="feedback3" cols="21" rows="4" >'.api_htmlentities($row['feedback3']).'</textarea></td>';
  1548. echo '</tr>';
  1549. echo '<tr>';
  1550. echo '<td>'.get_lang('FProgress').':</td>';
  1551. echo '<td><select name="fprogress1">';
  1552. echo '<option value="'.api_htmlentities($row['fprogress1']).'" selected>'.api_htmlentities($row['fprogress1']).'</option>';
  1553. echo '<option value="10">10</option>
  1554. <option value="20">20</option>
  1555. <option value="30">30</option>
  1556. <option value="40">40</option>
  1557. <option value="50">50</option>
  1558. <option value="60">60</option>
  1559. <option value="70">70</option>
  1560. <option value="80">80</option>
  1561. <option value="90">90</option>
  1562. <option value="100">100</option>
  1563. </select> %</td>';
  1564. echo '<td>'.get_lang('FProgress').':</td>';
  1565. echo '<td><select name="fprogress2">';
  1566. echo '<option value="'.api_htmlentities($row['fprogress2']).'" selected>'.api_htmlentities($row['fprogress2']).'</option>';;
  1567. echo '<option value="10">10</option>
  1568. <option value="20">20</option>
  1569. <option value="30">30</option>
  1570. <option value="40">40</option>
  1571. <option value="50">50</option>
  1572. <option value="60">60</option>
  1573. <option value="70">70</option>
  1574. <option value="80">80</option>
  1575. <option value="90">90</option>
  1576. <option value="100">100</option>
  1577. </select> %</td>';
  1578. echo '<td>'.get_lang('FProgress').':</td>';
  1579. echo '<td><select name="fprogress3">';
  1580. echo '<option value="'.api_htmlentities($row['fprogress3']).'" selected>'.api_htmlentities($row['fprogress3']).'</option>';
  1581. echo '<option value="10">10</option>
  1582. <option value="20">20</option>
  1583. <option value="30">30</option>
  1584. <option value="40">40</option>
  1585. <option value="50">50</option>
  1586. <option value="60">60</option>
  1587. <option value="70">70</option>
  1588. <option value="80">80</option>
  1589. <option value="90">90</option>
  1590. <option value="100">100</option>
  1591. </select> %</td>';
  1592. echo '</tr>';
  1593. echo '</table>';
  1594. echo '</div>';
  1595. //time limit
  1596. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktimelimit" onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display=\'block\'; $pepe=\'a\';}else{document.getElementById(\'option1\').style.display=\'none\';}"/>&nbsp;'.get_lang('PutATimeLimit').'';
  1597. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error1" style="display:none;color:red"></span>';
  1598. echo '<div id="option1" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1599. echo '<table width="100%" border="0" style="font-weight:normal">';
  1600. echo '<tr>';
  1601. echo '<td align="right" width="150">'.get_lang('StartDate').':</td>';
  1602. echo '<td>';
  1603. if ($row['startdate_assig']=='0000-00-00 00:00:00') {
  1604. echo draw_date_picker('startdate_assig').' <input type="checkbox" name="initstartdate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1605. } else {
  1606. echo draw_date_picker('startdate_assig', $row['startdate_assig']).' <input type="checkbox" name="initstartdate" value="1">'.get_lang('Yes').'/'.get_lang('No').'';
  1607. }
  1608. echo '</td>';
  1609. echo '</tr>';
  1610. echo '<tr>';
  1611. echo '<td align="right" width="150">'.get_lang("EndDate").':</td>';
  1612. echo '<td>';
  1613. if ($row['enddate_assig']=='0000-00-00 00:00:00') {
  1614. echo draw_date_picker('enddate_assig').' <input type="checkbox" name="initenddate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1615. } else {
  1616. echo draw_date_picker('enddate_assig', $row['enddate_assig']).' <input type="checkbox" name="initenddate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  1617. }
  1618. echo '</td>';
  1619. echo '</tr>';
  1620. echo '<tr>';
  1621. echo '<td align="right">'.get_lang('AllowLaterSends').':</td>';
  1622. if ($row['delayedsubmit']==1) {
  1623. $check_uncheck='checked';
  1624. }
  1625. echo '<td><input type="checkbox" name="delayedsubmit" value="1" '.$check_uncheck.'></td>';
  1626. echo '</tr>';
  1627. echo'</table>';
  1628. echo '</div>';
  1629. //other limit
  1630. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkotherlimit" onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display=\'block\';}else{document.getElementById(\'option3\').style.display=\'none\';}"/>&nbsp;'.get_lang('OtherSettings').'';
  1631. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error3" style="display:none;color:red"></span>';
  1632. echo '<div id="option3" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  1633. echo '<div style="font-weight:normal"; align="center">'.get_lang('NMaxWords').':&nbsp;<input type="text" name="max_text" size="3" value="'.$row['max_text'].'">&nbsp;&nbsp;'.get_lang('NMaxVersion').':&nbsp;<input type="text" name="max_version" size="3" value="'.$row['max_version'].'"></div>';
  1634. echo '</div>';
  1635. //
  1636. echo '</div>';
  1637. }
  1638. echo '</div>';
  1639. echo '<div id="wikicontent">';
  1640. echo '<input type="hidden" name="page_id" value="'.$page_id.'">';
  1641. echo '<input type="hidden" name="reflink" value="'.api_htmlentities($page).'">';
  1642. echo '<input type="hidden" name="title" value="'.api_htmlentities($title).'">';
  1643. api_disp_html_area('content', $content, '', '', null, api_is_allowed_to_edit(null,true)
  1644. ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400')
  1645. : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student')
  1646. );
  1647. echo '<br/>';
  1648. echo '<br/>';
  1649. //if(api_is_allowed_to_edit() || api_is_platform_admin()) //off for now
  1650. //{
  1651. echo get_lang('Comments').':&nbsp;&nbsp;<input type="text" name="comment" size="40">&nbsp;&nbsp;&nbsp;';
  1652. //}
  1653. echo '<INPUT TYPE="hidden" NAME="assignment" VALUE="'.$row['assignment'].'"/>';
  1654. echo '<INPUT TYPE="hidden" NAME="version" VALUE="'.$row['version'].'"/>';
  1655. //hack date for edit
  1656. echo '<INPUT TYPE="hidden" NAME="startdate_assig" VALUE="'.$row['startdate_assig'].'"/>';
  1657. echo '<INPUT TYPE="hidden" NAME="enddate_assig" VALUE="'.$row['enddate_assig'].'"/>';
  1658. //
  1659. echo get_lang('Progress').':&nbsp;&nbsp;<select name="progress" id="progress">';
  1660. echo '<option value="'.api_htmlentities($row['progress']).'" selected>'.api_htmlentities($row['progress']).'</option>';
  1661. echo '<option value="10">10</option>
  1662. <option value="20">20</option>
  1663. <option value="30">30</option>
  1664. <option value="40">40</option>
  1665. <option value="50">50</option>
  1666. <option value="60">60</option>
  1667. <option value="70">70</option>
  1668. <option value="80">80</option>
  1669. <option value="90">90</option>
  1670. <option value="100">100</option>
  1671. </select> %';
  1672. echo '<br/><br/>';
  1673. echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post
  1674. echo '<button class="save" type="submit" name="SaveWikiChange">'.get_lang('Save').'</button>';//for save button Don't change name (see fckeditor/editor/plugins/customizations/fckplugin_compressed.js and fckplugin.js
  1675. echo '</div>';
  1676. echo '</form>';
  1677. }
  1678. }
  1679. }
  1680. }
  1681. // Page history
  1682. if ($_GET['action']=='history' or $_POST['HistoryDifferences']) {
  1683. if (!$_GET['title']) {
  1684. Display::display_error_message(get_lang("MustSelectPage"));
  1685. exit;
  1686. }
  1687. echo '<div style="overflow:hidden">';
  1688. $_clean['group_id']=(int)$_SESSION['_gid'];
  1689. //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
  1690. $sql='SELECT * FROM '.$tbl_wiki.'WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1691. $result=Database::query($sql);
  1692. while ($row=Database::fetch_array($result)) {
  1693. $KeyVisibility=$row['visibility'];
  1694. $KeyAssignment=$row['assignment'];
  1695. $KeyTitle=$row['title'];
  1696. $KeyUserId=$row['user_id'];
  1697. }
  1698. if ($KeyAssignment==1) {
  1699. $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
  1700. } elseif($KeyAssignment==2) {
  1701. $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
  1702. }
  1703. //Second, show
  1704. //if the page is hidden and is a job only sees its author and professor
  1705. if($KeyVisibility==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin() || ($KeyAssignment==2 && $KeyVisibility==0 && (api_get_user_id()==$KeyUserId))) {
  1706. // We show the complete history
  1707. if (!$_POST['HistoryDifferences'] && !$_POST['HistoryDifferences2']) {
  1708. $sql='SELECT * FROM '.$tbl_wiki.'WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1709. $result=Database::query($sql);
  1710. $title = Security::remove_XSS($_GET['title']);
  1711. $group_id = intval($_GET['group_id']);
  1712. echo '<div id="wikititle">';
  1713. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.Security::remove_XSS($KeyTitle);
  1714. echo '</div>';
  1715. echo '<div id="wikicontent">';
  1716. echo '<form id="differences" method="POST" action="index.php?cidReq='.$_course['id'].'&action=history&title='.$title.'&session_id='.$session_id.'&group_id='.$group_id.'">';
  1717. echo '<ul style="list-style-type: none;">';
  1718. echo '<br/>';
  1719. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1720. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1721. echo '<br/><br/>';
  1722. $counter=0;
  1723. $total_versions=Database::num_rows($result);
  1724. while ($row=Database::fetch_array($result)) {
  1725. $userinfo = api_get_user_info($row['user_id']);
  1726. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
  1727. echo '<li style="margin-bottom: 5px;">';
  1728. ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle='';
  1729. ($counter==0) ? $newchecked=' checked':$newchecked='';
  1730. ($counter==$total_versions-1) ? $newstyle='style="visibility: hidden;"':$newstyle='';
  1731. ($counter==1) ? $oldchecked=' checked':$oldchecked='';
  1732. echo '<input name="old" value="'.$row['id'].'" type="radio" '.$oldstyle.' '.$oldchecked.'/> ';
  1733. echo '<input name="new" value="'.$row['id'].'" type="radio" '.$newstyle.' '.$newchecked.'/> ';
  1734. echo '<a href="'.api_get_self().'?action=showpage&amp;title='.api_htmlentities(urlencode($page)).'&amp;view='.$row['id'].'">';
  1735. echo '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&amp;title='.api_htmlentities(urlencode($page)).'&amp;view='.$row['id'].'&session_id='.$session_id.'&group_id='.$group_id.'">';
  1736. echo api_get_local_time($row['dtime'], null, date_default_timezone_get());
  1737. echo '</a>';
  1738. echo ' ('.get_lang('Version').' '.$row['version'].')';
  1739. echo ' '.get_lang('By').' ';
  1740. if ($row['user_id']<>0) {
  1741. echo '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  1742. Display::tag('span', api_htmlentities($userinfo['complete_name_login_as'])).
  1743. '</a>';
  1744. } else {
  1745. echo get_lang('Anonymous').' ('.api_htmlentities($row[user_ip]).')';
  1746. }
  1747. echo ' ( '.get_lang('Progress').': '.api_htmlentities($row['progress']).'%, ';
  1748. $comment=$row['comment'];
  1749. if (!empty($comment)) {
  1750. echo get_lang('Comments').': '.api_htmlentities(api_substr($row['comment'],0,100));
  1751. if (api_strlen($row['comment'])>100) {
  1752. echo '... ';
  1753. }
  1754. } else {
  1755. echo get_lang('Comments').': ---';
  1756. }
  1757. echo ' ) </li>';
  1758. $counter++;
  1759. } //end while
  1760. echo '<br/>';
  1761. echo '<button class="search" type="submit" name="HistoryDifferences" value="HistoryDifferences">'.get_lang('ShowDifferences').' '.get_lang('LinesDiff').'</button>';
  1762. echo '<button class="search" type="submit" name="HistoryDifferences2" value="HistoryDifferences2">'.get_lang('ShowDifferences').' '.get_lang('WordsDiff').'</button>';
  1763. echo '</ul></form></div>';
  1764. } else { // We show the differences between two versions
  1765. $sql_old="SELECT * FROM $tbl_wiki WHERE c_id = $course_id AND id='".Database::escape_string($_POST['old'])."'";
  1766. $result_old=Database::query($sql_old);
  1767. $version_old=Database::fetch_array($result_old);
  1768. $sql_new="SELECT * FROM $tbl_wiki WHERE c_id = $course_id AND id='".Database::escape_string($_POST['new'])."'";
  1769. $result_new=Database::query($sql_new);
  1770. $version_new=Database::fetch_array($result_new);
  1771. if (isset($_POST['HistoryDifferences'])) {
  1772. include('diff.inc.php');
  1773. //title
  1774. echo '<div id="wikititle">'.api_htmlentities($version_new['title']).' <font size="-2"><i>('.get_lang('DifferencesNew').'</i> <font style="background-color:#aaaaaa">'.$version_new['dtime'].'</font> <i>'.get_lang('DifferencesOld').'</i> <font style="background-color:#aaaaaa">'.$version_old['dtime'].'</font>) '.get_lang('Legend').': <span class="diffAdded" >'.get_lang(WikiDiffAddedLine).'</span> <span class="diffDeleted" >'.get_lang(WikiDiffDeletedLine).'</span> <span class="diffMoved" >'.get_lang(WikiDiffMovedLine).'</span></font></div>';
  1775. }
  1776. if (isset($_POST['HistoryDifferences2'])) {
  1777. // including global PEAR diff libraries
  1778. require_once 'Text/Diff.php';
  1779. require_once 'Text/Diff/Renderer/inline.php';
  1780. //title
  1781. echo '<div id="wikititle">'.api_htmlentities($version_new['title']).' <font size="-2"><i>('.get_lang('DifferencesNew').'</i> <font style="background-color:#aaaaaa">'.$version_new['dtime'].'</font> <i>'.get_lang('DifferencesOld').'</i> <font style="background-color:#aaaaaa">'.$version_old['dtime'].'</font>) '.get_lang('Legend').': <span class="diffAddedTex" >'.get_lang(WikiDiffAddedTex).'</span> <span class="diffDeletedTex" >'.get_lang(WikiDiffDeletedTex).'</span></font></div>';
  1782. }
  1783. echo '<div class="diff"><br /><br />';
  1784. if (isset($_POST['HistoryDifferences'])) {
  1785. echo '<table>'.diff( $version_old['content'], $version_new['content'], true, 'format_table_line' ).'</table>'; // format_line mode is better for words
  1786. echo '</div>';
  1787. echo '<br />';
  1788. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1789. echo '<table><tr>';
  1790. echo '<td>';
  1791. echo '</td><td>';
  1792. echo '<span class="diffEqual" >'.get_lang('WikiDiffUnchangedLine').'</span><br />';
  1793. echo '<span class="diffAdded" >'.get_lang('WikiDiffAddedLine').'</span><br />';
  1794. echo '<span class="diffDeleted" >'.get_lang('WikiDiffDeletedLine').'</span><br />';
  1795. echo '<span class="diffMoved" >'.get_lang('WikiDiffMovedLine').'</span><br />';
  1796. echo '</td>';
  1797. echo '</tr></table>';
  1798. echo '</div>';
  1799. }
  1800. if (isset($_POST['HistoryDifferences2'])) {
  1801. $lines1 = array(strip_tags($version_old['content'])); //without <> tags
  1802. $lines2 = array(strip_tags($version_new['content'])); //without <> tags
  1803. $diff = new Text_Diff($lines1, $lines2);
  1804. $renderer = new Text_Diff_Renderer_inline();
  1805. echo '<style>del{background:#fcc}ins{background:#cfc}</style>'.$renderer->render($diff); // Code inline
  1806. //echo '<div class="diffEqual">'.html_entity_decode($renderer->render($diff)).'</div>'; // Html inline. By now, turned off by problems in comparing pages separated by more than one version
  1807. echo '</div>';
  1808. echo '<br />';
  1809. echo '<strong>'.get_lang('Legend').'</strong><div class="diff">' . "\n";
  1810. echo '<table><tr>';
  1811. echo '<td>';
  1812. echo '</td><td>';
  1813. echo '<span class="diffAddedTex" >'.get_lang('WikiDiffAddedTex').'</span><br />';
  1814. echo '<span class="diffDeletedTex" >'.get_lang('WikiDiffDeletedTex').'</span><br />';
  1815. echo '</td>';
  1816. echo '</tr></table>';
  1817. echo '</div>';
  1818. }
  1819. }
  1820. }
  1821. echo '</div>';
  1822. }
  1823. // Recent changes
  1824. // @todo rss feed
  1825. if ($_GET['action']=='recentchanges') {
  1826. $_clean['group_id']=(int)$_SESSION['_gid'];
  1827. if ( api_is_allowed_to_session_edit(false,true) ) {
  1828. if (check_notify_all()==1) {
  1829. $notify_all= Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotNotifyChanges');
  1830. $lock_unlock_notify_all='unlocknotifyall';
  1831. } else {
  1832. $notify_all=Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'),'',ICON_SIZE_SMALL).' '.get_lang('NotifyChanges');
  1833. $lock_unlock_notify_all='locknotifyall';
  1834. }
  1835. }
  1836. echo '<div class="actions"><span style="float: right;">';
  1837. echo '<a href="index.php?action=recentchanges&amp;actionpage='.$lock_unlock_notify_all.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$notify_all.'</a>';
  1838. echo '</span>'.get_lang('RecentChanges').'</div>';
  1839. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  1840. $sql = 'SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
  1841. WHERE '.$tbl_wiki_conf.'.c_id= '.$course_id.' AND
  1842. '.$tbl_wiki.'.c_id= '.$course_id.' AND
  1843. '.$tbl_wiki_conf.'.page_id='.$tbl_wiki.'.page_id AND
  1844. '.$tbl_wiki.'.'.$groupfilter.$condition_session.'
  1845. ORDER BY dtime DESC'; // new version
  1846. } else {
  1847. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND '.$groupfilter.$condition_session.' AND visibility=1 ORDER BY dtime DESC'; // old version TODO: Replace by the bottom line
  1848. }
  1849. $allpages=Database::query($sql);
  1850. //show table
  1851. if (Database::num_rows($allpages) > 0) {
  1852. $row = array ();
  1853. while ($obj = Database::fetch_object($allpages)) {
  1854. //get author
  1855. $userinfo = api_get_user_info($obj->user_id);
  1856. $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
  1857. //get type assignment icon
  1858. if ($obj->assignment==1) {
  1859. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  1860. } elseif ($obj->assignment==2) {
  1861. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  1862. } elseif ($obj->assignment==0) {
  1863. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1864. }
  1865. //get icon task
  1866. if (!empty($obj->task)) {
  1867. $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
  1868. } else {
  1869. $icon_task='<img src="../img/px_transparent.gif" />';
  1870. }
  1871. $row = array ();
  1872. $row[] = api_get_local_time($obj->dtime, null, date_default_timezone_get());
  1873. $row[] = $ShowAssignment.$icon_task;
  1874. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&amp;view='.$obj->id.'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($obj->title).'</a>';
  1875. $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
  1876. if ($obj->user_id <> 0 ) {
  1877. $row[] = '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  1878. Display::tag('span', api_htmlentities($userinfo['complete_name_login_as'])).
  1879. '</a>';
  1880. }
  1881. else {
  1882. $row[] = get_lang('Anonymous').' ('.api_htmlentities($obj->user_ip).')';
  1883. }
  1884. $rows[] = $row;
  1885. }
  1886. $table = new SortableTableFromArrayConfig($rows,0,10,'RecentPages_table','','','DESC');
  1887. $table->set_additional_parameters(array('cidReq' =>Security::remove_XSS($_GET['cidReq']),'action'=>Security::remove_XSS($_GET['action']),'session_id'=>Security::remove_XSS($_GET['session_id']),'group_id'=>Security::remove_XSS($_GET['group_id'])));
  1888. $table->set_header(0,get_lang('Date'), true, array ('style' => 'width:200px;'));
  1889. $table->set_header(1,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1890. $table->set_header(2,get_lang('Title'), true);
  1891. $table->set_header(3,get_lang('Actions'), true, array ('style' => 'width:80px;'));
  1892. $table->set_header(4,get_lang('Author'), true);
  1893. $table->display();
  1894. }
  1895. }
  1896. // All pages
  1897. if ($_GET['action']=='allpages') {
  1898. echo '<div class="actions">'.get_lang('AllPages').'</div>';
  1899. $_clean['group_id']=(int)$_SESSION['_gid'];
  1900. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //only by professors if page is hidden
  1901. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  1902. WHERE s1.c_id = '.$course_id.' AND id=(
  1903. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2
  1904. WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')'; // warning don't use group by reflink because does not return the last version
  1905. } else {
  1906. $sql = 'SELECT * FROM '.$tbl_wiki.' s1
  1907. WHERE visibility=1 AND s1.c_id = '.$course_id.' AND id=(
  1908. SELECT MAX(s2.id) FROM '.$tbl_wiki.' s2 WHERE s2.c_id = '.$course_id.' AND s1.reflink = s2.reflink AND '.$groupfilter.' AND session_id='.$session_id.')'; // warning don't use group by reflink because does not return the last version
  1909. }
  1910. $allpages=Database::query($sql);
  1911. //show table
  1912. if (Database::num_rows($allpages) > 0) {
  1913. $row = array ();
  1914. while ($obj = Database::fetch_object($allpages)) {
  1915. //get author
  1916. $userinfo = api_get_user_info($obj->user_id);
  1917. //get type assignment icon
  1918. if ($obj->assignment==1) {
  1919. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
  1920. } elseif ($obj->assignment==2) {
  1921. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
  1922. } elseif ($obj->assignment==0) {
  1923. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1924. }
  1925. //get icon task
  1926. if (!empty($obj->task)) {
  1927. $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
  1928. } else {
  1929. $icon_task='<img src="../img/px_transparent.gif" />';
  1930. }
  1931. $row = array ();
  1932. $row[] =$ShowAssignment.$icon_task;
  1933. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.Security::remove_XSS($obj->reflink).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Security::remove_XSS($obj->title).'</a>';
  1934. if ($obj->user_id <>0) {
  1935. $row[] = '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  1936. Display::tag('span', api_htmlentities($userinfo['complete_name_login_as'])).
  1937. '</a>';
  1938. }
  1939. else {
  1940. $row[] = get_lang('Anonymous').' ('.api_htmlentities($obj->user_ip).')';
  1941. }
  1942. $row[] = api_get_local_time($obj->dtime, null, date_default_timezone_get());
  1943. if (api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) {
  1944. $showdelete=' <a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=delete&title='.Security::remove_XSS($obj->reflink).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL);
  1945. }
  1946. if (api_is_allowed_to_session_edit(false,true) ) {
  1947. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=edit&title='.Security::remove_XSS($obj->reflink).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Display::return_icon('edit.png', get_lang('EditPage'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=discuss&title='.Security::remove_XSS($obj->reflink).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Display::return_icon('discuss.png', get_lang('Discuss'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=history&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Display::return_icon('history.png', get_lang('History'),'',ICON_SIZE_SMALL).'</a> <a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=links&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.Security::remove_XSS($_GET['session_id']).'&group_id='.Security::remove_XSS($_GET['group_id']).'">'.Display::return_icon('what_link_here.png', get_lang('LinksPages'),'',ICON_SIZE_SMALL).'</a>'.$showdelete;
  1948. }
  1949. $rows[] = $row;
  1950. }
  1951. $table = new SortableTableFromArrayConfig($rows,1,10,'AllPages_table','','','ASC');
  1952. $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'])));
  1953. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1954. $table->set_header(1,get_lang('Title'), true);
  1955. $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true);
  1956. $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
  1957. if (api_is_allowed_to_session_edit(false,true) ) {
  1958. $table->set_header(4,get_lang('Actions'), true, array ('style' => 'width:130px;'));
  1959. }
  1960. $table->display();
  1961. }
  1962. }
  1963. // Discuss pages
  1964. if ($_GET['action']=='discuss') {
  1965. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  1966. api_not_allowed();
  1967. }
  1968. if (!$_GET['title']) {
  1969. Display::display_error_message(get_lang("MustSelectPage"));
  1970. exit;
  1971. }
  1972. //first extract the date of last version
  1973. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC';
  1974. $result=Database::query($sql);
  1975. $row=Database::fetch_array($result);
  1976. $lastversiondate=api_get_local_time($row['dtime'], null, date_default_timezone_get());
  1977. $lastuserinfo = api_get_user_info($row['user_id']);
  1978. //select page to discuss
  1979. $sql='SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1980. $result=Database::query($sql);
  1981. $row=Database::fetch_array($result);
  1982. $id=$row['id'];
  1983. $firstuserid=$row['user_id'];
  1984. //mode assignment: previous to show page type
  1985. if ($row['assignment']==1) {
  1986. $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',ICON_SIZE_SMALL);
  1987. } elseif($row['assignment']==2) {
  1988. $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWorkExtra'),'',ICON_SIZE_SMALL);
  1989. }
  1990. //Show title and form to discuss if page exist
  1991. if ($id!='') {
  1992. //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
  1993. if ($row['visibility_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin() || ($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))) {
  1994. echo '<div id="wikititle">';
  1995. // discussion action: protecting (locking) the discussion
  1996. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  1997. if (check_addlock_discuss()==1) {
  1998. $addlock_disc= Display::return_icon('unlock.png', get_lang('UnlockDiscussExtra'),'',ICON_SIZE_SMALL);
  1999. $lock_unlock_disc='unlockdisc';
  2000. } else {
  2001. $addlock_disc= Display::return_icon('lock.png', get_lang('LockDiscussExtra'),'',ICON_SIZE_SMALL);
  2002. $lock_unlock_disc='lockdisc';
  2003. }
  2004. }
  2005. echo '<span style="float:right">';
  2006. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_disc.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$addlock_disc.'</a>';
  2007. echo '</span>';
  2008. // discussion action: visibility. Show discussion to students if isn't hidden. Show page to all teachers if is hidden.
  2009. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  2010. if (check_visibility_discuss()==1) {
  2011. /// TODO: Fix Mode assignments: If is hidden, show discussion to student only if student is the author
  2012. //if(($row['assignment']==2 && $row['visibility_disc']==0 && (api_get_user_id()==$row['user_id']))==false)
  2013. //{
  2014. //$visibility_disc= '<img src="../img/wiki/invisible.gif" title="'.get_lang('HideDiscussExtra').'" alt="'.get_lang('HideDiscussExtra').'" />';
  2015. //}
  2016. $visibility_disc= Display::return_icon('visible.png', get_lang('ShowDiscussExtra'),'',ICON_SIZE_SMALL);
  2017. $hide_show_disc='hidedisc';
  2018. } else {
  2019. $visibility_disc= Display::return_icon('invisible.png', get_lang('HideDiscussExtra'),'',ICON_SIZE_SMALL);
  2020. $hide_show_disc='showdisc';
  2021. }
  2022. }
  2023. echo '<span style="float:right">';
  2024. echo '<a href="index.php?action=discuss&amp;actionpage='.$hide_show_disc.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$visibility_disc.'</a>';
  2025. echo '</span>';
  2026. //discussion action: check add rating lock. Show/Hide list to rating for all student
  2027. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  2028. if (check_ratinglock_discuss()==1) {
  2029. $ratinglock_disc= Display::return_icon('star.png', get_lang('UnlockRatingDiscussExtra'),'',ICON_SIZE_SMALL);
  2030. $lock_unlock_rating_disc='unlockrating';
  2031. } else {
  2032. $ratinglock_disc= Display::return_icon('star_na.png', get_lang('LockRatingDiscussExtra'),'',ICON_SIZE_SMALL);
  2033. $lock_unlock_rating_disc='lockrating';
  2034. }
  2035. }
  2036. echo '<span style="float:right">';
  2037. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_rating_disc.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$ratinglock_disc.'</a>';
  2038. echo '</span>';
  2039. //discussion action: email notification
  2040. if (check_notify_discuss($page)==1) {
  2041. $notify_disc= Display::return_icon('messagebox_info.png', get_lang('NotifyDiscussByEmail'),'',ICON_SIZE_SMALL);
  2042. $lock_unlock_notify_disc='unlocknotifydisc';
  2043. } else {
  2044. $notify_disc= Display::return_icon('mail.png', get_lang('CancelNotifyDiscussByEmail'),'',ICON_SIZE_SMALL);
  2045. $lock_unlock_notify_disc='locknotifydisc';
  2046. }
  2047. echo '<span style="float:right">';
  2048. echo '<a href="index.php?action=discuss&amp;actionpage='.$lock_unlock_notify_disc.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$notify_disc.'</a>';
  2049. echo '</span>';
  2050. echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.api_htmlentities($row['title']);
  2051. echo ' ('.get_lang('MostRecentVersionBy').' <a href="../user/userInfo.php?uInfo='.$lastuserinfo['user_id'].'">'.
  2052. Display::tag('span', api_htmlentities($lastuserinfo['complete_name_login_as'])).
  2053. '</a> '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read average score
  2054. echo '</div>';
  2055. if ($row['addlock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) { //show comments but students can't add theirs
  2056. ?>
  2057. <form name="form1" method="post" action="">
  2058. <table>
  2059. <tr>
  2060. <td valign="top" ><?php echo get_lang('Comments');?>:</td>
  2061. <?php echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post ?>
  2062. <td><textarea name="comment" cols="80" rows="5" id="comment"></textarea></td>
  2063. </tr>
  2064. <tr>
  2065. <?php
  2066. //check if rating is allowed
  2067. if ($row['ratinglock_disc']==1 || api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  2068. ?>
  2069. <td><?php echo get_lang('Rating');?>: </td>
  2070. <td valign="top"><select name="rating" id="rating">
  2071. <option value="-" selected>-</option>
  2072. <option value="0">0</option>
  2073. <option value="1">1</option>
  2074. <option value="2">2</option>
  2075. <option value="3">3</option>
  2076. <option value="4">4</option>
  2077. <option value="5">5</option>
  2078. <option value="6">6</option>
  2079. <option value="7">7</option>
  2080. <option value="8">8</option>
  2081. <option value="9">9</option>
  2082. <option value="10">10</option>
  2083. </select></td>
  2084. <?php
  2085. } else {
  2086. echo '<input type=hidden name="rating" value="-">';// must pass a default value to avoid rate automatically
  2087. }
  2088. ?>
  2089. </tr>
  2090. <tr>
  2091. <td>&nbsp;</td>
  2092. <td> <?php echo '<button class="save" type="submit" name="Submit"> '.get_lang('Send').'</button>'; ?></td>
  2093. </tr>
  2094. </table>
  2095. </form>
  2096. <?php
  2097. if (isset($_POST['Submit']) && double_post($_POST['wpost_id'])) {
  2098. $dtime = date( "Y-m-d H:i:s" );
  2099. $message_author=api_get_user_id();
  2100. $sql="INSERT INTO $tbl_wiki_discuss (c_id, publication_id, userc_id, comment, p_score, dtime) VALUES
  2101. ($course_id, '".$id."','".$message_author."','".Database::escape_string($_POST['comment'])."','".Database::escape_string($_POST['rating'])."','".$dtime."')";
  2102. $result=Database::query($sql) or die(Database::error());
  2103. check_emailcue($id, 'D', $dtime, $message_author);
  2104. }
  2105. }//end discuss lock
  2106. echo '<hr noshade size="1">';
  2107. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  2108. $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user
  2109. WHERE reviews.c_id = $course_id AND reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' ORDER BY id DESC";
  2110. $result=Database::query($sql) or die(Database::error());
  2111. $countWPost = Database::num_rows($result);
  2112. echo get_lang('NumComments').": ".$countWPost; //comment's numbers
  2113. $sql="SELECT SUM(p_score) as sumWPost FROM $tbl_wiki_discuss WHERE c_id = $course_id AND publication_id = '".$id."' AND NOT p_score='-' ORDER BY id DESC";
  2114. $result2=Database::query($sql) or die(Database::error());
  2115. $row2=Database::fetch_array($result2);
  2116. $sql="SELECT * FROM $tbl_wiki_discuss WHERE c_id = $course_id AND publication_id='".$id."' AND NOT p_score='-'";
  2117. $result3=Database::query($sql) or die(Database::error());
  2118. $countWPost_score= Database::num_rows($result3);
  2119. echo ' - '.get_lang('NumCommentsScore').': '.$countWPost_score;//
  2120. if ($countWPost_score!=0) {
  2121. $avg_WPost_score = round($row2['sumWPost'] / $countWPost_score,2).' / 10';
  2122. } else {
  2123. $avg_WPost_score = $countWPost_score;
  2124. }
  2125. echo ' - '.get_lang('RatingMedia').': '.$avg_WPost_score; // average rating
  2126. $sql = 'UPDATE '.$tbl_wiki.' SET score="'.Database::escape_string($avg_WPost_score).'"
  2127. WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session;
  2128. // check if work ok. TODO:
  2129. Database::query($sql);
  2130. echo '<hr noshade size="1">';
  2131. while ($row = Database::fetch_array($result)) {
  2132. $userinfo = api_get_user_info($row['userc_id']);
  2133. if (($userinfo['status'])=="5") {
  2134. $author_status=get_lang('Student');
  2135. } else {
  2136. $author_status=get_lang('Teacher');
  2137. }
  2138. $user_id=$row['userc_id'];
  2139. $name = $userinfo['complete_name'];
  2140. $attrb=array();
  2141. if ($user_id<>0) {
  2142. $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true);
  2143. $image_repository = $image_path['dir'];
  2144. $existing_image = $image_path['file'];
  2145. $author_photo= '<img src="'.$image_repository.$existing_image.'" alt="'.api_htmlentities($name).'" width="40" height="50" align="top" title="'.api_htmlentities($name).'" />';
  2146. } else {
  2147. $author_photo= '<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.api_htmlentities($name).'" width="40" height="50" align="top" title="'.api_htmlentities($name).'" />';
  2148. }
  2149. //stars
  2150. $p_score=$row['p_score'];
  2151. switch ($p_score) {
  2152. case 0:
  2153. $imagerating='<img src="../img/rating/stars_0.gif"/>';
  2154. break;
  2155. case 1:
  2156. $imagerating='<img src="../img/rating/stars_5.gif"/>';
  2157. break;
  2158. case 2:
  2159. $imagerating='<img src="../img/rating/stars_10.gif"/>';
  2160. break;
  2161. case 3:
  2162. $imagerating='<img src="../img/rating/stars_15.gif"/>';
  2163. break;
  2164. case 4:
  2165. $imagerating='<img src="../img/rating/stars_20.gif"/>';
  2166. break;
  2167. case 5:
  2168. $imagerating='<img src="../img/rating/stars_25.gif"/>';
  2169. break;
  2170. case 6:
  2171. $imagerating='<img src="../img/rating/stars_30.gif"/>';
  2172. break;
  2173. case 7:
  2174. $imagerating='<img src="../img/rating/stars_35.gif"/>';
  2175. break;
  2176. case 8:
  2177. $imagerating='<img src="../img/rating/stars_40.gif"/>';
  2178. break;
  2179. case 9:
  2180. $imagerating='<img src="../img/rating/stars_45.gif"/>';
  2181. break;
  2182. case 10:
  2183. $imagerating='<img src="../img/rating/stars_50.gif"/>';
  2184. break;
  2185. }
  2186. echo '<p><table>';
  2187. echo '<tr>';
  2188. echo '<td rowspan="2">'.$author_photo.'</td>';
  2189. echo '<td style=" color:#999999"><a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.
  2190. Display::tag('span', api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])), array('title'=>$username)).
  2191. '</a> ('.$author_status.') '.api_get_local_time($row['dtime'], null, date_default_timezone_get()).' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' </td>';
  2192. echo '</tr>';
  2193. echo '<tr>';
  2194. echo '<td>'.api_htmlentities($row['comment']).'</td>';
  2195. echo '</tr>';
  2196. echo "</table>";
  2197. echo '<hr noshade size="1">';
  2198. }
  2199. } else {
  2200. Display::display_warning_message(get_lang('LockByTeacher'),false);
  2201. }
  2202. } else {
  2203. Display::display_normal_message(get_lang('DiscussNotAvailable'));
  2204. }
  2205. }
  2206. echo '</div>'; // echo "<div style="overflow:hidden">";
  2207. echo "</div>"; // echo "<div id='mainwiki'>";
  2208. echo "</div>"; // echo "<div id='wikiwrapper'>";
  2209. /*
  2210. FOOTER
  2211. */
  2212. Display::display_footer();