index.php 95 KB

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