index.php 96 KB

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