wiki.inc.php 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Functions library for the wiki tool
  5. * @author Juan Carlos Raña <herodoto@telefonica.net>
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  7. * @author Julio Montoya <gugli100@gmail.com> using the pdf.lib.php library
  8. * @package chamilo.wiki
  9. */
  10. /* FUNCTIONS FOR WIKI */
  11. /**
  12. * Create a reference link for a given new page title (adds incremental number
  13. * to the title). It is a recursive function because every newly created
  14. * reflink suggestion has to be checked also
  15. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  16. * @param
  17. */
  18. function createreflink($testvalue) {
  19. $counter='';
  20. while (!checktitle($testvalue.$counter))
  21. {
  22. $counter++;
  23. echo $counter."-".$testvalue.$counter."<br />";
  24. }
  25. // the reflink has not been found yet, so it is OK
  26. return $testvalue.$counter;
  27. }
  28. /**
  29. * Check whether this title is already used
  30. * @param string title
  31. * @return bool False if title is already taken
  32. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  33. **/
  34. function checktitle($paramwk) {
  35. global $tbl_wiki;
  36. global $groupfilter;
  37. global $condition_session;
  38. $course_id = api_get_course_int_id();
  39. $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE c_id = '.$course_id.' AND reflink="'.Database::escape_string($paramwk).'" AND '.$groupfilter.$condition_session.'';
  40. $result=Database::query($sql);
  41. $numberofresults=Database::num_rows($result);
  42. if ($numberofresults==0) // the value has not been found and is this available
  43. {
  44. return true;
  45. }
  46. else // the value has been found
  47. {
  48. return false;
  49. }
  50. }
  51. /**
  52. * check wikilinks that has a page
  53. * @author Juan Carlos Raña <herodoto@telefonica.net>
  54. **/
  55. function links_to($input) {
  56. $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE);
  57. $all_links = array();
  58. foreach ($input_array as $key=>$value)
  59. {
  60. if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]')
  61. {
  62. if (api_strpos($value, "|") !== false)
  63. {
  64. $full_link_array=explode("|", $value);
  65. $link=trim($full_link_array[0]);
  66. $title=trim($full_link_array[1]);
  67. }
  68. else
  69. {
  70. $link=trim($value);
  71. $title=trim($value);
  72. }
  73. unset($input_array[$key-1]);
  74. unset($input_array[$key+1]);
  75. $all_links[]= Database::escape_string(str_replace(' ','_',$link)).' '; //replace blank spaces by _ within the links. But to remove links at the end add a blank space
  76. }
  77. }
  78. $output=implode($all_links);
  79. return $output;
  80. }
  81. /**
  82. * detect and add style to external links
  83. * @author Juan Carlos Raña Trabado
  84. **/
  85. function detect_external_link($input) {
  86. $exlink='href=';
  87. $exlinkStyle='class="wiki_link_ext" href=';
  88. $output=str_replace($exlink, $exlinkStyle, $input);
  89. return $output;
  90. }
  91. /**
  92. * detect and add style to anchor links
  93. * @author Juan Carlos Raña Trabado
  94. **/
  95. function detect_anchor_link($input) {
  96. $anchorlink='href="#';
  97. $anchorlinkStyle='class="wiki_anchor_link" href="#';
  98. $output=str_replace($anchorlink, $anchorlinkStyle, $input);
  99. return $output;
  100. }
  101. /**
  102. * detect and add style to mail links
  103. * author Juan Carlos Raña Trabado
  104. **/
  105. function detect_mail_link($input) {
  106. $maillink='href="mailto';
  107. $maillinkStyle='class="wiki_mail_link" href="mailto';
  108. $output=str_replace($maillink, $maillinkStyle, $input);
  109. return $output;
  110. }
  111. /**
  112. * detect and add style to ftp links
  113. * @author Juan Carlos Raña Trabado
  114. **/
  115. function detect_ftp_link($input) {
  116. $ftplink='href="ftp';
  117. $ftplinkStyle='class="wiki_ftp_link" href="ftp';
  118. $output=str_replace($ftplink, $ftplinkStyle, $input);
  119. return $output;
  120. }
  121. /**
  122. * detect and add style to news links
  123. * @author Juan Carlos Raña Trabado
  124. **/
  125. function detect_news_link($input) {
  126. $newslink='href="news';
  127. $newslinkStyle='class="wiki_news_link" href="news';
  128. $output=str_replace($newslink, $newslinkStyle, $input);
  129. return $output;
  130. }
  131. /**
  132. * detect and add style to irc links
  133. * @author Juan Carlos Raña Trabado
  134. **/
  135. function detect_irc_link($input) {
  136. $irclink='href="irc';
  137. $irclinkStyle='class="wiki_irc_link" href="irc';
  138. $output=str_replace($irclink, $irclinkStyle, $input);
  139. return $output;
  140. }
  141. /**
  142. * This function allows users to have [link to a title]-style links like in most regular wikis.
  143. * It is true that the adding of links is probably the most anoying part of Wiki for the people
  144. * who know something about the wiki syntax.
  145. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  146. * Improvements [[]] and [[ | ]]by Juan Carlos Raña
  147. * Improvements internal wiki style and mark group by Juan Carlos Raña
  148. **/
  149. function make_wiki_link_clickable($input) {
  150. global $_course;
  151. if (isset($_SESSION['_gid'])) {
  152. $_clean['group_id']=intval($_SESSION['_gid']);
  153. }
  154. if (isset($_GET['group_id'])) {
  155. $_clean['group_id']=intval($_GET['group_id']);
  156. }
  157. $session_id=api_get_session_id(); // TODO: check
  158. $input_array=preg_split("/(\[\[|\]\])/",$input,-1, PREG_SPLIT_DELIM_CAPTURE); //now doubles brackets
  159. foreach ($input_array as $key=>$value)
  160. {
  161. if ($input_array[$key-1]=='[[' AND $input_array[$key+1]==']]') //now doubles brackets
  162. {
  163. /////////// TODO: metawiki
  164. /*
  165. if ($session_id==0)
  166. {
  167. if ($_clean['group_id']==0)
  168. {
  169. $titleg_ex='';
  170. }
  171. else
  172. {
  173. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  174. $group_name= $group_properties['name'];
  175. $titleg_ex='<sup><img src="css/wgroup.gif" alt="('.$group_name.')" title="Link to Wikigroup:'.$group_name.'"/></sup>';
  176. }
  177. }
  178. else
  179. {
  180. TODO:logic for sessions
  181. }
  182. */
  183. /////////
  184. //now full wikilink
  185. if (api_strpos($value, "|") !== false){
  186. $full_link_array=explode("|", $value);
  187. $link=trim(strip_tags($full_link_array[0]));
  188. $title=trim($full_link_array[1]);
  189. }
  190. else{
  191. $link=trim(strip_tags($value));
  192. $title=trim($value);
  193. }
  194. //if wikilink is homepage
  195. if($link=='index'){
  196. $title=get_lang('DefaultTitle');
  197. }
  198. if ($link==get_lang('DefaultTitle')){
  199. $link='index';
  200. }
  201. // note: checkreflink checks if the link is still free. If it is not used then it returns true, if it is used, then it returns false. Now the title may be different
  202. if (checktitle(strtolower(str_replace(' ','_',$link))))
  203. {
  204. $link = api_html_entity_decode($link);
  205. $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=addnew&amp;title='.api_htmlentities(urlencode($link)).'&group_id='.$_clean['group_id'].'" class="new_wiki_link">'.$title.'</a>';
  206. }
  207. else
  208. {
  209. $input_array[$key]='<a href="'.api_get_path(WEB_PATH).'main/wiki/index.php?'.api_get_cidreq().'&action=showpage&amp;title='.urlencode(strtolower(str_replace(' ','_',$link))).'&group_id='.$_clean['group_id'].'" class="wiki_link">'.$title.'</a>';
  210. }
  211. unset($input_array[$key-1]);
  212. unset($input_array[$key+1]);
  213. }
  214. }
  215. $output=implode('',$input_array);
  216. return $output;
  217. }
  218. /**
  219. * This function saves a change in a wiki page
  220. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  221. * @return language string saying that the changes are stored
  222. **/
  223. function save_wiki() {
  224. global $charset, $tbl_wiki, $_course, $tbl_wiki_conf;
  225. // NOTE: visibility, visibility_disc and ratinglock_disc changes are not made here, but through the interce buttons
  226. // cleaning the variables
  227. $_clean['page_id'] = Database::escape_string($_POST['page_id']);
  228. $_clean['reflink'] = Database::escape_string(trim($_POST['reflink']));
  229. $_clean['title'] = Database::escape_string(trim($_POST['title']));
  230. $_clean['content'] = Database::escape_string($_POST['content']);
  231. if (api_get_setting('htmlpurifier_wiki') == 'true'){
  232. $purifier = new HTMLPurifier();
  233. $_clean['content'] = $purifier->purify($_clean['content']);
  234. }
  235. $_clean['user_id'] = api_get_user_id();
  236. $_clean['assignment'] = Database::escape_string($_POST['assignment']);
  237. $_clean['comment'] = Database::escape_string($_POST['comment']);
  238. $_clean['progress'] = Database::escape_string($_POST['progress']);
  239. $_clean['version'] = intval($_POST['version']) + 1 ;
  240. $_clean['linksto'] = links_to($_clean['content']); //and check links content
  241. $dtime = date( "Y-m-d H:i:s" );
  242. $session_id = api_get_session_id();
  243. if (isset($_SESSION['_gid']))
  244. {
  245. $_clean['group_id']=Database::escape_string($_SESSION['_gid']);
  246. }
  247. if (isset($_GET['group_id']))
  248. {
  249. $_clean['group_id']=Database::escape_string($_GET['group_id']);
  250. }
  251. //cleaning config variables
  252. if(!empty($_POST['task']))
  253. {
  254. $_clean['task']= Database::escape_string($_POST['task']);
  255. }
  256. if(!empty($_POST['feedback1']) || !empty($_POST['feedback2']) || !empty($_POST['feedback3'])) {
  257. $_clean['feedback1']=Database::escape_string($_POST['feedback1']);
  258. $_clean['feedback2']=Database::escape_string($_POST['feedback2']);
  259. $_clean['feedback3']=Database::escape_string($_POST['feedback3']);
  260. $_clean['fprogress1']=Database::escape_string($_POST['fprogress1']);
  261. $_clean['fprogress2']=Database::escape_string($_POST['fprogress2']);
  262. $_clean['fprogress3']=Database::escape_string($_POST['fprogress3']);
  263. }
  264. if(Security::remove_XSS($_POST['initstartdate']==1))
  265. {
  266. $_clean['startdate_assig']=Database::escape_string(get_date_from_select('startdate_assig'));
  267. }
  268. else
  269. {
  270. $_clean['startdate_assig']=Database::escape_string($_POST['startdate_assig']);
  271. }
  272. if(Security::remove_XSS($_POST['initenddate']==1))
  273. {
  274. $_clean['enddate_assig']=Database::escape_string(get_date_from_select('enddate_assig'));
  275. }
  276. else
  277. {
  278. $_clean['enddate_assig']=Database::escape_string($_POST['enddate_assig']);
  279. }
  280. $_clean['delayedsubmit']=Database::escape_string($_POST['delayedsubmit']);
  281. if(!empty($_POST['max_text']) || !empty($_POST['max_version']))
  282. {
  283. $_clean['max_text'] =Database::escape_string($_POST['max_text']);
  284. $_clean['max_version']=Database::escape_string($_POST['max_version']);
  285. }
  286. $course_id = api_get_course_int_id();
  287. $sql = "INSERT INTO ".$tbl_wiki." (c_id, page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip, session_id)
  288. VALUES ($course_id, '".$_clean['page_id']."','".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$dtime."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')";
  289. $result = Database::query($sql);
  290. $Id = Database::insert_id();
  291. if ($Id > 0) {
  292. //insert into item_property
  293. api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']);
  294. }
  295. if ($_clean['page_id'] ==0) {
  296. $sql='UPDATE '.$tbl_wiki.' SET page_id="'.$Id.'" WHERE id="'.$Id.'"';
  297. Database::query($sql);
  298. }
  299. //update wiki config
  300. if ($_clean['reflink']=='index' && $_clean['version']==1) {
  301. $sql="INSERT INTO ".$tbl_wiki_conf." (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit)
  302. VALUES ($course_id, '".$Id."','".$_clean['task']."','".$_clean['feedback1']."','".$_clean['feedback2']."','".$_clean['feedback3']."','".$_clean['fprogress1']."','".$_clean['fprogress2']."','".$_clean['fprogress3']."','".$_clean['max_text']."','".$_clean['max_version']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['delayedsubmit']."')";
  303. } else {
  304. $sql='UPDATE'.$tbl_wiki_conf.' SET task="'.$_clean['task'].'", feedback1="'.$_clean['feedback1'].'", feedback2="'.$_clean['feedback2'].'", feedback3="'.$_clean['feedback3'].'", fprogress1="'.$_clean['fprogress1'].'", fprogress2="'.$_clean['fprogress2'].'", fprogress3="'.$_clean['fprogress3'].'", max_text="'.$_clean['max_text'].'", max_version="'.$_clean['max_version'].'", startdate_assig="'.$_clean['startdate_assig'].'", enddate_assig="'.$_clean['enddate_assig'].'", delayedsubmit="'.$_clean['delayedsubmit'].'"
  305. WHERE page_id="'.$_clean['page_id'].'" AND c_id = '.$course_id;
  306. }
  307. Database::query($sql);
  308. api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']);
  309. check_emailcue($_clean['reflink'], 'P', $dtime, $_clean['user_id']);
  310. return get_lang('ChangesStored');
  311. }
  312. /**
  313. * This function restore a wikipage
  314. * @author Juan Carlos Raña <herodoto@telefonica.net>
  315. * @return string Message of success (to be printed on screen)
  316. **/
  317. function restore_wikipage($r_page_id, $r_reflink, $r_title, $r_content, $r_group_id, $r_assignment, $r_progress, $c_version, $r_version, $r_linksto) {
  318. global $tbl_wiki, $_course;
  319. $r_user_id= api_get_user_id();
  320. $r_dtime = date( "Y-m-d H:i:s" );
  321. $r_version = $r_version+1;
  322. $r_comment = get_lang('RestoredFromVersion').': '.$c_version;
  323. $session_id = api_get_session_id();
  324. $course_id = api_get_course_int_id();
  325. $sql="INSERT INTO ".$tbl_wiki." (c_id, page_id, reflink, title, content, user_id, group_id, dtime, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES
  326. ($course_id, '".$r_page_id."','".$r_reflink."','".$r_title."','".$r_content."','".$r_user_id."','".$r_group_id."','".$r_dtime."','".$r_assignment."','".$r_comment."','".$r_progress."','".$r_version."','".$r_linksto."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."','".Database::escape_string($session_id)."')";
  327. $result=Database::query($sql);
  328. $Id = Database::insert_id();
  329. api_item_property_update($_course, 'wiki', $Id, 'WikiAdded', api_get_user_id(), $r_group_id);
  330. check_emailcue($r_reflink, 'P', $r_dtime, $r_user_id);
  331. return get_lang('PageRestored');
  332. }
  333. /**
  334. * This function delete a wiki
  335. * @author Juan Carlos Raña <herodoto@telefonica.net>
  336. * @return string Message of success (to be printed)
  337. **/
  338. function delete_wiki() {
  339. global $tbl_wiki, $tbl_wiki_conf, $tbl_wiki_discuss, $tbl_wiki_mailcue, $groupfilter, $condition_session;
  340. //identify the first id by group = identify wiki
  341. $sql = 'SELECT * FROM '.$tbl_wiki.' WHERE '.$groupfilter.$condition_session.' ORDER BY id DESC';
  342. $allpages = Database::query($sql);
  343. $course_id = api_get_course_int_id();
  344. while ($row=Database::fetch_array($allpages)) {
  345. $id = $row['id'];
  346. $group_id = $row['group_id'];
  347. $session_id = $row['session_id'];
  348. $page_id = $row['page_id'];
  349. Database::query('DELETE FROM '.$tbl_wiki_conf.' WHERE page_id="'.$id.'" AND c_id = '.$course_id);
  350. Database::query('DELETE FROM '.$tbl_wiki_discuss.' WHERE publication_id="'.$id.'" AND c_id = '.$course_id);
  351. }
  352. Database::query('DELETE FROM '.$tbl_wiki_mailcue.' WHERE session_id="'.$session_id.'" AND group_id="'.$group_id.'" AND c_id = '.$course_id);
  353. Database::query('DELETE FROM '.$tbl_wiki.' WHERE session_id="'.$session_id.'" AND group_id="'.$group_id.'" AND c_id = '.$course_id);
  354. return get_lang('WikiDeleted');
  355. }
  356. /**
  357. * This function saves a new wiki page.
  358. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  359. * @todo consider merging this with the function save_wiki into one single function.
  360. * @return string Message of success
  361. **/
  362. function save_new_wiki() {
  363. global $charset;
  364. global $tbl_wiki;
  365. global $assig_user_id; //need for assignments mode
  366. global $tbl_wiki_conf;
  367. global $page;
  368. // cleaning the variables
  369. $_clean['assignment']=Database::escape_string($_POST['assignment']);
  370. // session_id
  371. $session_id = api_get_session_id();
  372. if($_clean['assignment']==2 || $_clean['assignment']==1) {// Unlike ordinary pages of pages of assignments. Allow create a ordinary page although there is a assignment with the same name
  373. $page = str_replace(' ','_',$_POST['title']."_uass".$assig_user_id);
  374. } else {
  375. $page = str_replace(' ','_',$_POST['title']);
  376. }
  377. $_clean['reflink'] = Database::escape_string(strip_tags(api_htmlentities($page)));
  378. $_clean['title'] = Database::escape_string(strip_tags(trim($_POST['title'])));
  379. $_clean['content'] = Database::escape_string($_POST['content']);
  380. if (api_get_setting('htmlpurifier_wiki') == 'true'){
  381. $purifier = new HTMLPurifier();
  382. $_clean['content'] = $purifier->purify($_clean['content']);
  383. }
  384. //re-check after strip_tags if the title is empty
  385. if(empty($_clean['title']) || empty($_clean['reflink'])){
  386. return false;
  387. }
  388. if($_clean['assignment']==2) {//config by default for individual assignment (students)
  389. $_clean['user_id']=(int)Database::escape_string($assig_user_id);//Identifies the user as a creator, not the teacher who created
  390. $_clean['visibility']=0;
  391. $_clean['visibility_disc']=0;
  392. $_clean['ratinglock_disc']=0;
  393. } else {
  394. $_clean['user_id']=api_get_user_id();
  395. $_clean['visibility']=1;
  396. $_clean['visibility_disc']=1;
  397. $_clean['ratinglock_disc']=1;
  398. }
  399. $_clean['comment']=Database::escape_string($_POST['comment']);
  400. $_clean['progress']=Database::escape_string($_POST['progress']);
  401. $_clean['version']=1;
  402. if (isset($_SESSION['_gid']))
  403. {
  404. $_clean['group_id']=(int)$_SESSION['_gid'];
  405. }
  406. if (isset($_GET['group_id']))
  407. {
  408. $_clean['group_id']=(int)Database::escape_string($_GET['group_id']);
  409. }
  410. $_clean['linksto'] = links_to($_clean['content']); //check wikilinks
  411. //cleaning config variables
  412. $_clean['task']= Database::escape_string($_POST['task']);
  413. $_clean['feedback1']=Database::escape_string($_POST['feedback1']);
  414. $_clean['feedback2']=Database::escape_string($_POST['feedback2']);
  415. $_clean['feedback3']=Database::escape_string($_POST['feedback3']);
  416. $_clean['fprogress1']=Database::escape_string($_POST['fprogress1']);
  417. $_clean['fprogress2']=Database::escape_string($_POST['fprogress2']);
  418. $_clean['fprogress3']=Database::escape_string($_POST['fprogress3']);
  419. if($_POST['initstartdate']==1) {
  420. $_clean['startdate_assig']=Database::escape_string(get_date_from_select('startdate_assig'));
  421. } else {
  422. $_clean['startdate_assig']=Database::escape_string($_POST['startdate_assig']);
  423. }
  424. if($_POST['initenddate']==1) {
  425. $_clean['enddate_assig']=Database::escape_string(get_date_from_select('enddate_assig'));
  426. } else {
  427. $_clean['enddate_assig']=Database::escape_string($_POST['enddate_assig']);
  428. }
  429. $_clean['delayedsubmit']=Database::escape_string($_POST['delayedsubmit']);
  430. $_clean['max_text']=Database::escape_string($_POST['max_text']);
  431. $_clean['max_version']=Database::escape_string($_POST['max_version']);
  432. $course_id = api_get_course_int_id();
  433. //filter no _uass
  434. if (api_eregi('_uass', $_POST['title']) || (api_strtoupper(trim($_POST['title'])) == 'INDEX' || api_strtoupper(trim(api_htmlentities($_POST['title'], ENT_QUOTES, $charset))) == api_strtoupper(api_htmlentities(get_lang('DefaultTitle'), ENT_QUOTES, $charset)))) {
  435. $message= get_lang('GoAndEditMainPage');
  436. Display::display_warning_message($message,false);
  437. } else {
  438. $var=$_clean['reflink'];
  439. $group_id=Security::remove_XSS($_GET['group_id']);
  440. if(!checktitle($var)) {
  441. return get_lang('WikiPageTitleExist').'<a href="index.php?action=edit&amp;title='.$var.'&group_id='.$group_id.'">'.$_POST['title'].'</a>';
  442. } else {
  443. $dtime = date( "Y-m-d H:i:s" );
  444. $sql = "INSERT INTO ".$tbl_wiki." (c_id, reflink, title, content, user_id, group_id, dtime, visibility, visibility_disc, ratinglock_disc, assignment, comment, progress, version, linksto, user_ip, session_id) VALUES
  445. ($course_id, '".$_clean['reflink']."','".$_clean['title']."','".$_clean['content']."','".$_clean['user_id']."','".$_clean['group_id']."','".$dtime."','".$_clean['visibility']."','".$_clean['visibility_disc']."','".$_clean['ratinglock_disc']."','".$_clean['assignment']."','".$_clean['comment']."','".$_clean['progress']."','".$_clean['version']."','".$_clean['linksto']."','".Database::escape_string($_SERVER['REMOTE_ADDR'])."', '".Database::escape_string($session_id)."')";
  446. $result = Database::query($sql);
  447. $Id = Database::insert_id();
  448. if ($Id > 0) {
  449. //insert into item_property
  450. api_item_property_update(api_get_course_info(), TOOL_WIKI, $Id, 'WikiAdded', api_get_user_id(), $_clean['group_id']);
  451. }
  452. $sql='UPDATE '.$tbl_wiki.' SET page_id="'.$Id.'" WHERE id="'.$Id.'"';
  453. Database::query($sql);
  454. //insert wiki config
  455. $sql="INSERT INTO ".$tbl_wiki_conf." (c_id, page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) VALUES
  456. ($course_id, '".$Id."','".$_clean['task']."','".$_clean['feedback1']."','".$_clean['feedback2']."','".$_clean['feedback3']."','".$_clean['fprogress1']."','".$_clean['fprogress2']."','".$_clean['fprogress3']."','".$_clean['max_text']."','".$_clean['max_version']."','".$_clean['startdate_assig']."','".$_clean['enddate_assig']."','".$_clean['delayedsubmit']."')";
  457. Database::query($sql);
  458. check_emailcue(0, 'A');
  459. return get_lang('NewWikiSaved');
  460. }
  461. }//end filter no _uass
  462. }
  463. /**
  464. * This function displays the form for adding a new wiki page.
  465. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  466. * @return html code
  467. **/
  468. function display_new_wiki_form() {
  469. global $_course, $page;
  470. ?>
  471. <script type="text/javascript">
  472. function CheckSend()
  473. {
  474. if(document.form1.title.value == "")
  475. {
  476. alert("<?php echo get_lang('NoWikiPageTitle');?>");
  477. document.form1.title.focus();
  478. return false;
  479. }
  480. return true;
  481. }
  482. function setFocus(){
  483. $("#wiki_title").focus();
  484. }
  485. $(document).ready(function () {
  486. setFocus();
  487. });
  488. </script>
  489. <?php
  490. //form
  491. echo '<form name="form1" method="post" onsubmit="return CheckSend()" action="'.api_get_self().'?'.api_get_cidreq().'&action=showpage&amp;title='.api_htmlentities(urlencode(strtolower(str_replace(' ','_',$page)))).'&group_id='.api_htmlentities($_GET['group_id']).'">';
  492. echo '<div id="wikititle" style="min-height:30px;">';
  493. echo '<div style="width:70%;float:left;"><span class="form_required">*</span> '.get_lang(Title).': <input type="text" id="wiki_title" name="title" value="'.api_htmlentities($_GET['title']).'" size="40"></div>';
  494. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  495. {
  496. $_clean['group_id']=(int)$_SESSION['_gid']; // TODO: check if delete ?
  497. 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>';
  498. echo '<div id="options" style="display:none; margin: 20px;" >';
  499. //task
  500. echo '<div>&nbsp;</div>';
  501. echo '<div style= "border : 1px dotted; padding:4px; margin-top:20px;">';
  502. echo '<input type="checkbox" value="1" name="checktask" onclick="javascript: if(this.checked){document.getElementById(\'option4\').style.display=\'block\';}else{document.getElementById(\'option4\').style.display=\'none\';}"/>&nbsp;
  503. '.Display::return_icon('wiki_task.png', get_lang('DefineTask'),'',22).' '.get_lang('DescriptionOfTheTask').'';
  504. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error4" style="display:none;color:red"></span>';
  505. echo '<div id="option4" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  506. echo '<table border="0" style="font-weight:normal">';
  507. echo '<tr>';
  508. echo '<td>'.get_lang('DescriptionOfTheTask').'</td>';
  509. echo '</tr>';
  510. echo '<tr>';
  511. //echo '<td><textarea name="task" cols="60" rows="4" >'.stripslashes($row['task']).'</textarea></td>'; // TODO: ¿delete?
  512. echo '<td>'.api_disp_html_area('task', '', '', '', null, array('ToolbarSet' => 'wiki_task', 'Width' => '580', 'Height' => '200')).'</td>';
  513. echo '</tr>';
  514. echo '</table>';
  515. echo '</div>';
  516. //feedback
  517. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkfeedback" onclick="javascript: if(this.checked){document.getElementById(\'option2\').style.display=\'block\';}else{document.getElementById(\'option2\').style.display=\'none\';}"/>&nbsp;'.get_lang('AddFeedback').'';
  518. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error2" style="display:none;color:red"></span>';
  519. echo '<div id="option2" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  520. echo '<table border="0" style="font-weight:normal" align="center">';
  521. echo '<tr>';
  522. echo '<td colspan="2">'.get_lang('Feedback1').'</td>';
  523. echo '<td colspan="2">'.get_lang('Feedback2').'</td>';
  524. echo '<td colspan="2">'.get_lang('Feedback3').'</td>';
  525. echo '</tr>';
  526. echo '<tr>';
  527. echo '<td colspan="2"><textarea name="feedback1" cols="21" rows="4"></textarea></td>';
  528. echo '<td colspan="2"><textarea name="feedback2" cols="21" rows="4"></textarea></td>';
  529. echo '<td colspan="2"><textarea name="feedback3" cols="21" rows="4"></textarea></td>';
  530. echo '</tr>';
  531. echo '<tr>';
  532. echo '<td>'.get_lang('FProgress').':</td>';
  533. echo '<td><select name="fprogress1">
  534. <option value="0" selected>0</option>
  535. <option value="10">10</option>
  536. <option value="20">20</option>
  537. <option value="30">30</option>
  538. <option value="40">40</option>
  539. <option value="50">50</option>
  540. <option value="60">60</option>
  541. <option value="70">70</option>
  542. <option value="80">80</option>
  543. <option value="90">90</option>
  544. <option value="100">100</option>
  545. </select> %</td>';
  546. echo '<td>'.get_lang('FProgress').':</td>';
  547. echo '<td><select name="fprogress2">
  548. <option value="0" selected>0</option>
  549. <option value="10">10</option>
  550. <option value="20">20</option>
  551. <option value="30">30</option>
  552. <option value="40">40</option>
  553. <option value="50">50</option>
  554. <option value="60">60</option>
  555. <option value="70">70</option>
  556. <option value="80">80</option>
  557. <option value="90">90</option>
  558. <option value="100">100</option>
  559. </select> %</td>';
  560. echo '<td>'.get_lang('FProgress').':</td>';
  561. echo '<td><select name="fprogress3">
  562. <option value="0" selected>0</option>
  563. <option value="10">10</option>
  564. <option value="20">20</option>
  565. <option value="30">30</option>
  566. <option value="40">40</option>
  567. <option value="50">50</option>
  568. <option value="60">60</option>
  569. <option value="70">70</option>
  570. <option value="80">80</option>
  571. <option value="90">90</option>
  572. <option value="100">100</option>
  573. </select> %</td>';
  574. echo '</tr>';
  575. echo '</table>';
  576. echo '</div>';
  577. //time limit
  578. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checktimelimit" onclick="javascript: if(this.checked){document.getElementById(\'option1\').style.display=\'block\';}else{document.getElementById(\'option1\').style.display=\'none\';}"/>&nbsp;'.get_lang('PutATimeLimit').'';
  579. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error1" style="display:none;color:red"></span>';
  580. echo '<div id="option1" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  581. echo '<table width="100%" border="0" style="font-weight:normal">';
  582. echo '<tr>';
  583. echo '<td align="right">'.get_lang("StartDate").':</td>';
  584. echo '<td>';
  585. echo draw_date_picker('startdate_assig').' <input type="checkbox" name="initstartdate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  586. echo '</td>';
  587. echo '</tr>';
  588. echo '<tr>';
  589. echo '<td align="right">'.get_lang("EndDate").':</td>';
  590. echo '<td>';
  591. echo draw_date_picker('enddate_assig').' <input type="checkbox" name="initenddate" value="1"> '.get_lang('Yes').'/'.get_lang('No').'';
  592. echo '</td>';
  593. echo '</tr>';
  594. echo '<tr>';
  595. echo '<td align="right">'.get_lang('AllowLaterSends').':</td>';
  596. echo '<td><input type="checkbox" name="delayedsubmit" value="1"></td>';
  597. echo '</tr>';
  598. echo'</table>';
  599. echo '</div>';
  600. //other limit
  601. echo '<div>&nbsp;</div><input type="checkbox" value="1" name="checkotherlimit" onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display=\'block\';}else{document.getElementById(\'option3\').style.display=\'none\';}"/>&nbsp;'.get_lang('OtherSettings').'';
  602. echo '&nbsp;&nbsp;&nbsp;<span id="msg_error3" style="display:none;color:red"></span>';
  603. echo '<div id="option3" style="padding:4px; margin:5px; border:1px dotted; display:none;">';
  604. echo '<div style="font-weight:normal"; align="center">'.get_lang('NMaxWords').':&nbsp;<input type="text" name="max_text" size="3">&nbsp;&nbsp;'.get_lang('NMaxVersion').':&nbsp;<input type="text" name="max_version" size="3"></div>';
  605. echo '</div>';
  606. echo '</div>';
  607. //to define as an individual assignment
  608. echo '<div style= "border : 1px dotted; padding:4px; margin-top:20px;"><img src="../img/icons/22/wiki_assignment.png" title="'.get_lang('CreateAssignmentPage').'" alt="'.get_lang('CreateAssignmentPage').'"/>&nbsp;'.get_lang('DefineAssignmentPage').': <input type="checkbox" name="assignment" value="1"></div>'; // 1= teacher 2 =student
  609. //
  610. echo'</div>';
  611. }
  612. echo '</div>';
  613. echo '<div id="wikicontent">';
  614. api_disp_html_area('content', '', '', '', null, api_is_allowed_to_edit(null,true)
  615. ? array('ToolbarSet' => 'Wiki', 'Width' => '100%', 'Height' => '400')
  616. : array('ToolbarSet' => 'WikiStudent', 'Width' => '100%', 'Height' => '400', 'UserStatus' => 'student')
  617. );
  618. echo '<br/>';
  619. echo '<br/>';
  620. echo get_lang('Comments').':&nbsp;&nbsp;<input type="text" name="comment" size="40"><br /><br />';
  621. echo get_lang('Progress').':&nbsp;&nbsp;<select name="progress" id="progress">
  622. <option value="0" selected>0</option>
  623. <option value="10">10</option>
  624. <option value="20">20</option>
  625. <option value="30">30</option>
  626. <option value="40">40</option>
  627. <option value="50">50</option>
  628. <option value="60">60</option>
  629. <option value="70">70</option>
  630. <option value="80">80</option>
  631. <option value="90">90</option>
  632. <option value="100">100</option>
  633. </select> %';
  634. echo '<br/><br/>';
  635. echo '<input type="hidden" name="wpost_id" value="'.md5(uniqid(rand(), true)).'">';//prevent double post
  636. echo '<button class="save" type="submit" name="SaveWikiNew">'.get_lang('langSave').'</button>';//for button icon. Don't change name (see fckeditor/editor/plugins/customizations/fckplugin_compressed.js and fckplugin.js
  637. echo '</div>';
  638. echo '</form>';
  639. }
  640. /**
  641. * This function displays a wiki entry
  642. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  643. * @author Juan Carlos Raña Trabado
  644. * @return html code
  645. **/
  646. function display_wiki_entry($newtitle) {
  647. global $charset, $tbl_wiki, $tbl_wiki_conf, $groupfilter, $condition_session, $page;
  648. if($newtitle) {
  649. $pageMIX=$newtitle; //display the page after it is created
  650. } else {
  651. $pageMIX=$page;//display current page
  652. }
  653. $_clean['group_id']=(int)$_SESSION['_gid'];
  654. $session_id=api_get_session_id();
  655. if ($_GET['view']) {
  656. $_clean['view']=(int)Database::escape_string($_GET['view']);
  657. $filter=' AND '.$tbl_wiki.'.id="'.$_clean['view'].'"';
  658. }
  659. //first, check page visibility in the first page version
  660. $sql='SELECT * FROM '.$tbl_wiki.' WHERE reflink="'.Database::escape_string($pageMIX).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  661. $result=Database::query($sql);
  662. $row=Database::fetch_array($result);
  663. $KeyVisibility=$row['visibility'];
  664. $course_id = api_get_course_int_id();
  665. // second, show the last version
  666. $sql='SELECT * FROM '.$tbl_wiki.', '.$tbl_wiki_conf.'
  667. WHERE '.$tbl_wiki_conf.'.c_id = '.$course_id.' AND
  668. '.$tbl_wiki.'.c_id = '.$course_id.' AND
  669. '.$tbl_wiki_conf.'.page_id = '.$tbl_wiki.'.page_id AND
  670. '.$tbl_wiki.'.reflink = "'.Database::escape_string($pageMIX).'" AND
  671. '.$tbl_wiki.'.session_id = '.$session_id.' AND
  672. '.$tbl_wiki.'.'.$groupfilter.' '.$filter.'
  673. ORDER BY id DESC';
  674. $result=Database::query($sql);
  675. $row=Database::fetch_array($result); // we do not need a while loop since we are always displaying the last version
  676. //update visits
  677. if ($row['id']) {
  678. $sql='UPDATE '.$tbl_wiki.' SET hits=(hits+1) WHERE id='.$row['id'].'';
  679. Database::query($sql);
  680. }
  681. // if both are empty and we are displaying the index page then we display the default text.
  682. if ($row['content']=='' AND $row['title']=='' AND $page=='index') {
  683. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin() || GroupManager :: is_user_in_group(api_get_user_id(),$_SESSION['_gid'])) {
  684. //Table structure for better export to pdf
  685. $default_table_for_content_Start='<table align="center" border="0"><tr><td align="center">';
  686. $default_table_for_content_End='</td></tr></table>';
  687. $content=$default_table_for_content_Start.sprintf(get_lang('DefaultContent'),api_get_path(WEB_IMG_PATH)).$default_table_for_content_End;
  688. $title=get_lang('DefaultTitle');
  689. } else {
  690. return Display::display_normal_message(get_lang('WikiStandBy'));
  691. }
  692. } else {
  693. $content=Security::remove_XSS($row['content'],COURSEMANAGERLOWSECURITY);
  694. $title= $row['title'];
  695. }
  696. //assignment mode: identify page type
  697. if ($row['assignment']==1) {
  698. $icon_assignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDescExtra'),'',22);
  699. } elseif($row['assignment']==2) {
  700. $icon_assignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',22);
  701. }
  702. //task mode
  703. if (!empty($row['task'])) {
  704. $icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',22);
  705. }
  706. //Show page. Show page to all users if isn't hide page. Mode assignments: if student is the author, can view
  707. if ($KeyVisibility=="1" || api_is_allowed_to_edit(false,true) || api_is_platform_admin() || ($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))) {
  708. echo '<div id="wikititle">';
  709. // page action: protecting (locking) the page
  710. if(api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  711. if (check_protect_page()==1) {
  712. $protect_page= Display::return_icon('lock.png', get_lang('PageLockedExtra'),'',22);
  713. $lock_unlock_protect='unlock';
  714. } else {
  715. $protect_page= Display::return_icon('unlock.png', get_lang('PageUnlockedExtra'),'',22);
  716. $lock_unlock_protect='lock';
  717. }
  718. }
  719. echo '<span style="float:right;">';
  720. echo '<a href="index.php?action=showpage&amp;actionpage='.$lock_unlock_protect.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$protect_page.'</a>';
  721. echo '</span>';
  722. //page action: visibility
  723. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  724. if (check_visibility_page()==1) {
  725. // TODO: FIX This hides the icon eye closed to users of work they can see yours
  726. //if(($row['assignment']==2 && $KeyVisibility=="0" && (api_get_user_id()==$row['user_id']))==false)
  727. //{
  728. //
  729. // }
  730. $visibility_page= Display::return_icon('visible.png', get_lang('ShowPageExtra'),'',22);
  731. $lock_unlock_visibility='invisible';
  732. } else {
  733. $visibility_page= Display::return_icon('invisible.png', get_lang('HidePageExtra'),'',22);
  734. $lock_unlock_visibility='visible';
  735. }
  736. }
  737. echo '<span style="float:right;">';
  738. echo '<a href="index.php?action=showpage&amp;actionpage='.$lock_unlock_visibility.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$visibility_page.'</a>';
  739. echo '</span>';
  740. //page action: notification
  741. if (api_is_allowed_to_session_edit()) {
  742. if (check_notify_page($page)==1) {
  743. $notify_page= Display::return_icon('messagebox_info.png', get_lang('NotifyByEmail'),'',22);
  744. $lock_unlock_notify_page='unlocknotify';
  745. } else {
  746. $notify_page= Display::return_icon('mail.png', get_lang('CancelNotifyByEmail'),'',22);
  747. $lock_unlock_notify_page='locknotify';
  748. }
  749. }
  750. echo '<span style="float:right;">';
  751. echo '<a href="index.php?action=showpage&amp;actionpage='.$lock_unlock_notify_page.'&amp;title='.api_htmlentities(urlencode($page)).'">'.$notify_page.'</a>';
  752. echo '</span>';
  753. //page action: export to pdf
  754. echo '<span style="float:right;padding-top:5px;">';
  755. echo '<form name="form_export2PDF" method="post" action="index.php">';
  756. echo '<input type="hidden" name="action" value="export_to_pdf">';
  757. echo '<input type="hidden" name="wiki_id" value="'.$row['id'].'">';
  758. echo '<input type="image" src="../img/icons/22/pdf.png" border ="0" title="'.get_lang('ExportToPDF').'" alt="'.get_lang('ExportToPDF').'" style=" border:none; margin-top: -9px">';
  759. echo '</form>';
  760. echo '</span>';
  761. //page action: copy last version to doc area
  762. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  763. echo '<span style="float:right;">';
  764. echo '<form name="form_export2DOC" method="post" action="index.php" >';
  765. echo '<input type=hidden name="export2DOC" value="export2doc">';
  766. echo '<input type=hidden name="doc_id" value="'.$row['id'].'">';
  767. echo '<input type="image" src="../img/icons/22/export_to_documents.png" border ="0" title="'.get_lang('ExportToDocArea').'" alt="'.get_lang('ExportToDocArea').'" style=" border:none; margin-top: -6px">';
  768. echo '</form>';
  769. echo '</span>';
  770. }
  771. //export to print
  772. ?>
  773. <script>
  774. function goprint() {
  775. var a = window.open('','','width=800,height=600');
  776. a.document.open("text/html");
  777. a.document.write(document.getElementById('wikicontent').innerHTML);
  778. a.document.close();
  779. a.print();
  780. }
  781. </script>
  782. <?php
  783. echo '<span style="float:right; cursor: pointer;">';
  784. echo Display::return_icon('printer.png', get_lang('Print'),array('onclick' => "javascript: goprint();"),'22');
  785. echo '</span>';
  786. if (empty($title)) {
  787. $title=get_lang('DefaultTitle');
  788. }
  789. if (wiki_exist($title)) {
  790. echo $icon_assignment.'&nbsp;'.$icon_task.'&nbsp;'.api_htmlentities($title);
  791. } else {
  792. echo api_htmlentities($title);
  793. }
  794. echo '</div>';
  795. echo '<div id="wikicontent">'. make_wiki_link_clickable(detect_external_link(detect_anchor_link(detect_mail_link(detect_ftp_link(detect_irc_link(detect_news_link($content))))))).'</div>';
  796. echo '<div id="wikifooter">'.get_lang('Progress').': '.$row['progress'].'%&nbsp;&nbsp;&nbsp;'.get_lang('Rating').': '.$row['score'].'&nbsp;&nbsp;&nbsp;'.get_lang('Words').': '.word_count($content).'</div>';
  797. }//end filter visibility
  798. } // end function display_wiki_entry
  799. /**
  800. * This function counted the words in a document. Thanks Adeel Khan
  801. * @param string Document's text
  802. * @return int Number of words
  803. */
  804. function word_count($document) {
  805. $search = array(
  806. '@<script[^>]*?>.*?</script>@si',
  807. '@<style[^>]*?>.*?</style>@siU',
  808. '@<div id="player.[^>]*?>.*?</div>@',
  809. '@<![\s\S]*?--[ \t\n\r]*>@'
  810. );
  811. $document = preg_replace($search, '', $document);
  812. # strip all html tags
  813. $wc = strip_tags($document);
  814. $wc = html_entity_decode(utf8_encode($wc)); //html_entity_decode($wc,ENT_NOQUOTES, 'UTF-8') does not work ok
  815. # remove 'words' that don't consist of alphanumerical characters or punctuation
  816. $pattern = "#[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]+#";
  817. $wc = trim(preg_replace($pattern, " ", $wc));
  818. # remove one-letter 'words' that consist only of punctuation
  819. $wc = trim(preg_replace("#\s*[(\'|\"|\.|\!|\?|;|,|\\|\/|\-|:|\&|@)]\s*#", " ", $wc));
  820. # remove superfluous whitespace
  821. $wc = preg_replace("/\s\s+/", " ", $wc);
  822. # split string into an array of words
  823. $wc = explode(" ", $wc);
  824. # remove empty elements
  825. $wc = array_filter($wc);
  826. # return the number of words
  827. return count($wc);
  828. }
  829. /**
  830. * This function checks if wiki title exist
  831. */
  832. function wiki_exist($title) {
  833. global $tbl_wiki;
  834. global $groupfilter;
  835. global $condition_session;
  836. $sql='SELECT id FROM '.$tbl_wiki.'WHERE title="'.Database::escape_string($title).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  837. $result=Database::query($sql);
  838. $cant=Database::num_rows($result);
  839. if ($cant>0) {
  840. return true;
  841. } else {
  842. return false;
  843. }
  844. }
  845. /**
  846. * This function a wiki warning
  847. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  848. * @return html code
  849. **/
  850. function display_wiki_warning($variable) {
  851. echo '<div class="wiki_warning">'.$variable.'</div>';
  852. }
  853. /**
  854. * Checks if this navigation tab has to be set to active
  855. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University
  856. * @return html code
  857. */
  858. function is_active_navigation_tab($paramwk) {
  859. if ($_GET['action']==$paramwk) {
  860. return ' class="active"';
  861. }
  862. }
  863. /**
  864. * Lock add pages
  865. * @author Juan Carlos Raña <herodoto@telefonica.net>
  866. * return current database status of protect page and change it if get action
  867. */
  868. function check_addnewpagelock() {
  869. global $tbl_wiki;
  870. global $groupfilter;
  871. global $condition_session;
  872. $_clean['group_id']=(int)$_SESSION['_gid'];
  873. $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.$condition_session.' ORDER BY id ASC';
  874. $result=Database::query($sql);
  875. $row=Database::fetch_array($result);
  876. $status_addlock=$row['addlock'];
  877. //change status
  878. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  879. {
  880. if ($_GET['actionpage']=='lockaddnew' && $status_addlock==1)
  881. {
  882. $status_addlock=0;
  883. }
  884. if ($_GET['actionpage']=='unlockaddnew' && $status_addlock==0)
  885. {
  886. $status_addlock=1;
  887. }
  888. Database::query('UPDATE '.$tbl_wiki.' SET addlock="'.Database::escape_string($status_addlock).'" WHERE '.$groupfilter.$condition_session.'');
  889. $sql='SELECT * FROM '.$tbl_wiki.'WHERE '.$groupfilter.$condition_session.' ORDER BY id ASC';
  890. $result=Database::query($sql);
  891. $row=Database::fetch_array($result);
  892. }
  893. //show status
  894. return $row['addlock'];
  895. }
  896. /**
  897. * Protect page
  898. * @author Juan Carlos Raña <herodoto@telefonica.net>
  899. * return current database status of protect page and change it if get action
  900. */
  901. function check_protect_page() {
  902. global $tbl_wiki;
  903. global $page;
  904. global $groupfilter;
  905. global $condition_session;
  906. $_clean['group_id']=(int)$_SESSION['_gid'];
  907. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  908. $result=Database::query($sql);
  909. $row=Database::fetch_array($result);
  910. $status_editlock=$row['editlock'];
  911. $id=$row['id'];
  912. ///change status
  913. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  914. if ($_GET['actionpage']=='lock' && $status_editlock==0) {
  915. $status_editlock=1;
  916. }
  917. if ($_GET['actionpage']=='unlock' && $status_editlock==1) {
  918. $status_editlock=0;
  919. }
  920. $sql='UPDATE '.$tbl_wiki.' SET editlock="'.Database::escape_string($status_editlock).'" WHERE id="'.$id.'"';
  921. Database::query($sql);
  922. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  923. $result=Database::query($sql);
  924. $row=Database::fetch_array($result);
  925. }
  926. //show status
  927. return $row['editlock'];
  928. }
  929. /**
  930. * Visibility page
  931. * @author Juan Carlos Raña <herodoto@telefonica.net>
  932. * return current database status of visibility and change it if get action
  933. */
  934. function check_visibility_page() {
  935. global $tbl_wiki;
  936. global $page;
  937. global $groupfilter;
  938. global $condition_session;
  939. $_clean['group_id']=(int)$_SESSION['_gid'];
  940. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  941. $result=Database::query($sql);
  942. $row=Database::fetch_array($result);
  943. $status_visibility=$row['visibility'];
  944. //change status
  945. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  946. if ($_GET['actionpage']=='visible' && $status_visibility==0) {
  947. $status_visibility=1;
  948. }
  949. if ($_GET['actionpage']=='invisible' && $status_visibility==1) {
  950. $status_visibility=0;
  951. }
  952. $sql='UPDATE '.$tbl_wiki.' SET visibility="'.Database::escape_string($status_visibility).'" WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session;
  953. Database::query($sql);
  954. //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page
  955. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  956. $result=Database::query($sql);
  957. $row=Database::fetch_array($result);
  958. }
  959. if (empty($row['id'])) {
  960. $row['visibility']= 1;
  961. }
  962. //show status
  963. return $row['visibility'];
  964. }
  965. /**
  966. * Visibility discussion
  967. * @author Juan Carlos Raña <herodoto@telefonica.net>
  968. * @return int current database status of discuss visibility and change it if get action page
  969. */
  970. function check_visibility_discuss() {
  971. global $tbl_wiki;
  972. global $page;
  973. global $groupfilter;
  974. global $condition_session;
  975. $_clean['group_id']=(int)$_SESSION['_gid'];
  976. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  977. $result=Database::query($sql);
  978. $row=Database::fetch_array($result);
  979. $status_visibility_disc=$row['visibility_disc'];
  980. //change status
  981. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  982. {
  983. if ($_GET['actionpage']=='showdisc' && $status_visibility_disc==0)
  984. {
  985. $status_visibility_disc=1;
  986. }
  987. if ($_GET['actionpage']=='hidedisc' && $status_visibility_disc==1)
  988. {
  989. $status_visibility_disc=0;
  990. }
  991. $sql='UPDATE '.$tbl_wiki.' SET visibility_disc="'.Database::escape_string($status_visibility_disc).'" WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session;
  992. Database::query($sql);
  993. //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page
  994. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  995. $result=Database::query($sql);
  996. $row=Database::fetch_array($result);
  997. }
  998. //show status
  999. return $row['visibility_disc'];
  1000. }
  1001. /**
  1002. * Lock add discussion
  1003. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1004. * @return int current database status of lock dicuss and change if get action
  1005. */
  1006. function check_addlock_discuss() {
  1007. global $tbl_wiki;
  1008. global $page;
  1009. global $groupfilter;
  1010. global $condition_session;
  1011. $_clean['group_id']=(int)$_SESSION['_gid'];
  1012. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1013. $result=Database::query($sql);
  1014. $row=Database::fetch_array($result);
  1015. $status_addlock_disc=$row['addlock_disc'];
  1016. //change status
  1017. if (api_is_allowed_to_edit() || api_is_platform_admin())
  1018. {
  1019. if ($_GET['actionpage']=='lockdisc' && $status_addlock_disc==0)
  1020. {
  1021. $status_addlock_disc=1;
  1022. }
  1023. if ($_GET['actionpage']=='unlockdisc' && $status_addlock_disc==1)
  1024. {
  1025. $status_addlock_disc=0;
  1026. }
  1027. $sql='UPDATE '.$tbl_wiki.' SET addlock_disc="'.Database::escape_string($status_addlock_disc).'" WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session;
  1028. Database::query($sql);
  1029. //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page
  1030. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1031. $result=Database::query($sql);
  1032. $row=Database::fetch_array($result);
  1033. }
  1034. //show status
  1035. return $row['addlock_disc'];
  1036. }
  1037. /**
  1038. * Lock rating discussion
  1039. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1040. * @return int current database status of rating discuss and change it if get action
  1041. */
  1042. function check_ratinglock_discuss() {
  1043. global $tbl_wiki;
  1044. global $page;
  1045. global $groupfilter;
  1046. global $condition_session;
  1047. $_clean['group_id']=(int)$_SESSION['_gid'];
  1048. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1049. $result=Database::query($sql);
  1050. $row=Database::fetch_array($result);
  1051. $status_ratinglock_disc=$row['ratinglock_disc'];
  1052. //change status
  1053. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin())
  1054. {
  1055. if ($_GET['actionpage']=='lockrating' && $status_ratinglock_disc==0)
  1056. {
  1057. $status_ratinglock_disc=1;
  1058. }
  1059. if ($_GET['actionpage']=='unlockrating' && $status_ratinglock_disc==1)
  1060. {
  1061. $status_ratinglock_disc=0;
  1062. }
  1063. $sql='UPDATE '.$tbl_wiki.' SET ratinglock_disc="'.Database::escape_string($status_ratinglock_disc).'" WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session; //Visibility. Value to all,not only for the first
  1064. Database::query($sql);
  1065. //Although the value now is assigned to all (not only the first), these three lines remain necessary. They do that by changing the page state is made when you press the button and not have to wait to change his page
  1066. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.Database::escape_string($page).'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1067. $result=Database::query($sql);
  1068. $row=Database::fetch_array($result);
  1069. }
  1070. //show status
  1071. return $row['ratinglock_disc'];
  1072. }
  1073. /**
  1074. * Notify page changes
  1075. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1076. * @return int the current notification status
  1077. */
  1078. function check_notify_page($reflink) {
  1079. global $tbl_wiki;
  1080. global $groupfilter;
  1081. global $tbl_wiki_mailcue;
  1082. global $condition_session;
  1083. $_clean['group_id']=(int)$_SESSION['_gid'];
  1084. $session_id=api_get_session_id();
  1085. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1086. $result=Database::query($sql);
  1087. $row=Database::fetch_array($result);
  1088. $id=$row['id'];
  1089. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P"';
  1090. $result=Database::query($sql);
  1091. $row=Database::fetch_array($result);
  1092. $idm=$row['id'];
  1093. if (empty($idm))
  1094. {
  1095. $status_notify=0;
  1096. }
  1097. else
  1098. {
  1099. $status_notify=1;
  1100. }
  1101. $course_id = api_get_course_int_id();
  1102. //change status
  1103. if ($_GET['actionpage']=='locknotify' && $status_notify==0) {
  1104. $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
  1105. ($course_id, '".$id."','".api_get_user_id()."','P','".$_clean['group_id']."','".$session_id."')";
  1106. Database::query($sql);
  1107. $status_notify=1;
  1108. }
  1109. if ($_GET['actionpage']=='unlocknotify' && $status_notify==1) {
  1110. $sql = 'DELETE FROM '.$tbl_wiki_mailcue.'
  1111. WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="P" AND c_id = '.$course_id; //$_clean['group_id'] not necessary. CHECK FOR SESSIONS
  1112. Database::query($sql);
  1113. $status_notify=0;
  1114. }
  1115. //show status
  1116. return $status_notify;
  1117. }
  1118. /**
  1119. * Notify discussion changes
  1120. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1121. * @return int current database status of rating discuss and change it if get action
  1122. */
  1123. function check_notify_discuss($reflink) {
  1124. global $tbl_wiki;
  1125. global $groupfilter;
  1126. global $tbl_wiki_mailcue;
  1127. global $condition_session;
  1128. $_clean['group_id']=(int)$_SESSION['_gid'];
  1129. $session_id=api_get_session_id();
  1130. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$reflink.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC';
  1131. $result=Database::query($sql);
  1132. $row=Database::fetch_array($result);
  1133. $id=$row['id'];
  1134. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D"';
  1135. $result=Database::query($sql);
  1136. $row=Database::fetch_array($result);
  1137. $idm=$row['id'];
  1138. if (empty($idm))
  1139. {
  1140. $status_notify_disc=0;
  1141. }
  1142. else
  1143. {
  1144. $status_notify_disc=1;
  1145. }
  1146. $course_id = api_get_course_int_id();
  1147. //change status
  1148. if ($_GET['actionpage']=='locknotifydisc' && $status_notify_disc==0) {
  1149. $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, id, user_id, type, group_id, session_id) VALUES
  1150. ($course_id, '".$id."','".api_get_user_id()."','D','".$_clean['group_id']."','".$session_id."')";
  1151. Database::query($sql);
  1152. $status_notify_disc=1;
  1153. }
  1154. if ($_GET['actionpage']=='unlocknotifydisc' && $status_notify_disc==1)
  1155. {
  1156. $sql='DELETE FROM '.$tbl_wiki_mailcue.' WHERE id="'.$id.'" AND user_id="'.api_get_user_id().'" AND type="D" AND c_id = '.$course_id; //$_clean['group_id'] not necessary TODO:CHECK FOR SESSIONS
  1157. Database::query($sql);
  1158. $status_notify_disc=0;
  1159. }
  1160. //show status
  1161. return $status_notify_disc;
  1162. }
  1163. /**
  1164. * Notify all changes
  1165. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1166. */
  1167. function check_notify_all() {
  1168. global $tbl_wiki_mailcue;
  1169. $_clean['group_id']=(int)$_SESSION['_gid'];
  1170. $session_id=api_get_session_id();
  1171. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"';
  1172. $result=Database::query($sql);
  1173. $row=Database::fetch_array($result);
  1174. $idm=$row['user_id'];
  1175. if (empty($idm))
  1176. {
  1177. $status_notify_all=0;
  1178. }
  1179. else
  1180. {
  1181. $status_notify_all=1;
  1182. }
  1183. $course_id = api_get_course_int_id();
  1184. //change status
  1185. if ($_GET['actionpage']=='locknotifyall' && $status_notify_all==0)
  1186. {
  1187. $sql="INSERT INTO ".$tbl_wiki_mailcue." (c_id, user_id, type, group_id, session_id) VALUES
  1188. ($course_id, '".api_get_user_id()."','F','".$_clean['group_id']."','".$session_id."')";
  1189. Database::query($sql);
  1190. $status_notify_all=1;
  1191. }
  1192. if ($_GET['actionpage']=='unlocknotifyall' && $status_notify_all==1) {
  1193. $sql ='DELETE FROM '.$tbl_wiki_mailcue.'
  1194. WHERE user_id="'.api_get_user_id().'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'" AND c_id = '.$course_id;
  1195. Database::query($sql);
  1196. $status_notify_all=0;
  1197. }
  1198. //show status
  1199. return $status_notify_all;
  1200. }
  1201. /**
  1202. * Sends pending e-mails
  1203. */
  1204. function check_emailcue($id_or_ref, $type, $lastime='', $lastuser='') {
  1205. global $tbl_wiki;
  1206. global $groupfilter;
  1207. global $tbl_wiki_mailcue;
  1208. global $_course;
  1209. global $condition_session;
  1210. $_clean['group_id']=(int)$_SESSION['_gid'];
  1211. $session_id=api_get_session_id();
  1212. $group_properties = GroupManager :: get_group_properties($_clean['group_id']);
  1213. $group_name= $group_properties['name'];
  1214. $allow_send_mail=false; //define the variable to below
  1215. if ($type=='P')
  1216. {
  1217. //if modifying a wiki page
  1218. //first, current author and time
  1219. //Who is the author?
  1220. $userinfo= Database::get_user_info_from_id($lastuser);
  1221. $email_user_author= get_lang('EditedBy').': '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1222. //When ?
  1223. $year = substr($lastime, 0, 4);
  1224. $month = substr($lastime, 5, 2);
  1225. $day = substr($lastime, 8, 2);
  1226. $hours=substr($lastime, 11,2);
  1227. $minutes=substr($lastime, 14,2);
  1228. $seconds=substr($lastime, 17,2);
  1229. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1230. //second, extract data from first reg
  1231. $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.$id_or_ref.'" AND '.$groupfilter.$condition_session.' ORDER BY id ASC'; //id_or_ref is reflink from tblwiki
  1232. $result=Database::query($sql);
  1233. $row=Database::fetch_array($result);
  1234. $id=$row['id'];
  1235. $email_page_name=$row['title'];
  1236. if ($row['visibility']==1)
  1237. {
  1238. $allow_send_mail=true; //if visibility off - notify off
  1239. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full.
  1240. $result=Database::query($sql);
  1241. $emailtext=get_lang('EmailWikipageModified').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
  1242. }
  1243. }
  1244. elseif ($type=='D')
  1245. {
  1246. //if added a post to discuss
  1247. //first, current author and time
  1248. //Who is the author of last message?
  1249. $userinfo= Database::get_user_info_from_id($lastuser);
  1250. $email_user_author= get_lang('AddedBy').': '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1251. //When ?
  1252. $year = substr($lastime, 0, 4);
  1253. $month = substr($lastime, 5, 2);
  1254. $day = substr($lastime, 8, 2);
  1255. $hours=substr($lastime, 11,2);
  1256. $minutes=substr($lastime, 14,2);
  1257. $seconds=substr($lastime, 17,2);
  1258. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1259. //second, extract data from first reg
  1260. $id=$id_or_ref; //$id_or_ref is id from tblwiki
  1261. $sql='SELECT * FROM '.$tbl_wiki.'WHERE id="'.$id.'" ORDER BY id ASC';
  1262. $result=Database::query($sql);
  1263. $row=Database::fetch_array($result);
  1264. $email_page_name=$row['title'];
  1265. if ($row['visibility_disc']==1)
  1266. {
  1267. $allow_send_mail=true; //if visibility off - notify off
  1268. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="'.$type.'" OR type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full
  1269. $result=Database::query($sql);
  1270. $emailtext=get_lang('EmailWikiPageDiscAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('Wiki');
  1271. }
  1272. }
  1273. elseif($type=='A')
  1274. {
  1275. //for added pages
  1276. $id=0; //for tbl_wiki_mailcue
  1277. $sql='SELECT * FROM '.$tbl_wiki.' ORDER BY id DESC'; //the added is always the last
  1278. $result=Database::query($sql);
  1279. $row=Database::fetch_array($result);
  1280. $email_page_name=$row['title'];
  1281. //Who is the author?
  1282. $userinfo= Database::get_user_info_from_id($row['user_id']);
  1283. $email_user_author= get_lang('AddedBy').': '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1284. //When ?
  1285. $year = substr($row['dtime'], 0, 4);
  1286. $month = substr($row['dtime'], 5, 2);
  1287. $day = substr($row['dtime'], 8, 2);
  1288. $hours=substr($row['dtime'], 11,2);
  1289. $minutes=substr($row['dtime'], 14,2);
  1290. $seconds=substr($row['dtime'], 17,2);
  1291. $email_date_changes=$day.' '.$month.' '.$year.' '.$hours.":".$minutes.":".$seconds;
  1292. if($row['assignment']==0)
  1293. {
  1294. $allow_send_mail=true;
  1295. }
  1296. elseif($row['assignment']==1)
  1297. {
  1298. $email_assignment=get_lang('AssignmentDescExtra').' ('.get_lang('AssignmentMode').')';
  1299. $allow_send_mail=true;
  1300. }
  1301. elseif($row['assignment']==2)
  1302. {
  1303. $allow_send_mail=false; //Mode tasks: avoids notifications to all users about all users
  1304. }
  1305. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=full
  1306. $result=Database::query($sql);
  1307. $emailtext=get_lang('EmailWikiPageAdded').' <strong>'.$email_page_name.'</strong> '.get_lang('In').' '. get_lang('Wiki');
  1308. }
  1309. elseif($type=='E')
  1310. {
  1311. $id=0;
  1312. $allow_send_mail=true;
  1313. //Who is the author?
  1314. $userinfo= Database::get_user_info_from_id(api_get_user_id()); //current user
  1315. $email_user_author= get_lang('DeletedBy').': '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1316. //When ?
  1317. $today = date('r'); //current time
  1318. $email_date_changes=$today;
  1319. $sql='SELECT * FROM '.$tbl_wiki_mailcue.'WHERE id="'.$id.'" AND type="F" AND group_id="'.$_clean['group_id'].'" AND session_id="'.$session_id.'"'; //type: P=page, D=discuss, F=wiki
  1320. $result=Database::query($sql);
  1321. $emailtext=get_lang('EmailWikipageDedeleted');
  1322. }
  1323. ///make and send email
  1324. if ($allow_send_mail)
  1325. {
  1326. while ($row=Database::fetch_array($result))
  1327. {
  1328. $userinfo = Database::get_user_info_from_id($row['user_id']); //$row['user_id'] obtained from tbl_wiki_mailcue
  1329. $name_to = api_get_person_name($userinfo['firstname'], $userinfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  1330. $email_to = $userinfo['email'];
  1331. $sender_name = api_get_setting('emailAdministrator');
  1332. $sender_email = api_get_setting('emailAdministrator');
  1333. $email_subject = get_lang('EmailWikiChanges').' - '.$_course['official_code'];
  1334. $email_body = get_lang('DearUser').' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).',<br /><br />';
  1335. if($session_id==0){
  1336. $email_body .= $emailtext.' <strong>'.$_course['name'].' - '.$group_name.'</strong><br /><br /><br />';
  1337. }else{
  1338. $email_body .= $emailtext.' <strong>'.$_course['name'].' ('.api_get_session_name(api_get_session_id()).') - '.$group_name.'</strong><br /><br /><br />';
  1339. }
  1340. $email_body .= $email_user_author.' ('.$email_date_changes.')<br /><br /><br />';
  1341. $email_body .= $email_assignment.'<br /><br /><br />';
  1342. $email_body .= '<font size="-2">'.get_lang('EmailWikiChangesExt_1').': <strong>'.get_lang('NotifyChanges').'</strong><br />';
  1343. $email_body .= get_lang('EmailWikiChangesExt_2').': <strong>'.get_lang('NotNotifyChanges').'</strong></font><br />';
  1344. @api_mail_html($name_to, $email_to, $email_subject, $email_body, $sender_name, $sender_email);
  1345. }
  1346. }
  1347. }
  1348. /**
  1349. * Function export last wiki page version to document area
  1350. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1351. */
  1352. function export2doc($doc_id) {
  1353. global $_course;
  1354. $groupId = api_get_group_id();
  1355. $session_id = api_get_session_id();
  1356. $data = get_wiki_data($doc_id);
  1357. if (empty($data)) {
  1358. return false;
  1359. }
  1360. $wikiTitle = $data['title'];
  1361. $wikiContents = $data['content'];
  1362. $template =
  1363. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1364. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{LANGUAGE}" lang="{LANGUAGE}">
  1365. <head>
  1366. <title>{TITLE}</title>
  1367. <meta http-equiv="Content-Type" content="text/html; charset={ENCODING}" />
  1368. <style type="text/css" media="screen, projection">
  1369. /*<![CDATA[*/
  1370. {CSS}
  1371. /*]]>*/
  1372. </style>
  1373. {ASCIIMATHML_SCRIPT}</head>
  1374. <body dir="{TEXT_DIRECTION}">
  1375. {CONTENT}
  1376. </body>
  1377. </html>';
  1378. $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/default.css';
  1379. if (file_exists($css_file)) {
  1380. $css = @file_get_contents($css_file);
  1381. } else {
  1382. $css = '';
  1383. }
  1384. // Fixing some bugs in css files.
  1385. $root_rel = api_get_path(REL_PATH);
  1386. $css_path = 'main/css/';
  1387. $theme = api_get_setting('stylesheets').'/';
  1388. $css = str_replace('behavior:url("/main/css/csshover3.htc");', '', $css);
  1389. $css = str_replace('main/', $root_rel.'main/', $css);
  1390. $css = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css);
  1391. $css = str_replace('../../img/', $root_rel.'main/img/', $css);
  1392. $asciimathmal_script = (api_contains_asciimathml($wikiContents) || api_contains_asciisvg($wikiContents))
  1393. ? '<script src="'.api_get_path(TO_REL, SCRIPT_ASCIIMATHML).'" type="text/javascript"></script>'."\n" : '';
  1394. $template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}'),
  1395. array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script),
  1396. $template);
  1397. if (0 != $groupId) {
  1398. $groupPart = '_group' . $groupId; // and add groupId to put the same document title in different groups
  1399. $group_properties = GroupManager :: get_group_properties($groupId);
  1400. $groupPath = $group_properties['directory'];
  1401. } else {
  1402. $groupPart = '';
  1403. $groupPath ='';
  1404. }
  1405. $exportDir = api_get_path(SYS_COURSE_PATH).api_get_course_path(). '/document'.$groupPath;
  1406. $exportFile = replace_dangerous_char($wikiTitle, 'strict') . $groupPart;
  1407. $clean_wikiContents = trim(preg_replace("/\[\[|\]\]/", " ", $wikiContents));
  1408. $array_clean_wikiContents= explode('|', $clean_wikiContents);
  1409. //$wikiContents= $array_clean_wikiContents[1];
  1410. $wikiContents = str_replace('{CONTENT}', $wikiContents, $template);
  1411. // replace relative path by absolute path for courses, so you can see items into this page wiki (images, mp3, etc..) exported in documents
  1412. if (api_strpos($wikiContents,'../../courses/') !== false) {
  1413. $web_course_path = api_get_path(WEB_COURSE_PATH);
  1414. $wikiContents = str_replace('../../courses/',$web_course_path,$wikiContents);
  1415. }
  1416. $doc_id = 0;
  1417. $i = 1;
  1418. while ( file_exists($exportDir . '/' .$exportFile.'_'.$i.'.html') ) $i++; //only export last version, but in new export new version in document area
  1419. $wikiFileName = $exportFile . '_' . $i . '.html';
  1420. $exportPath = $exportDir . '/' . $wikiFileName;
  1421. file_put_contents( $exportPath, $wikiContents );
  1422. $doc_id = add_document($_course, $groupPath.'/'.$wikiFileName, 'file', filesize($exportPath), $wikiTitle);
  1423. api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', api_get_user_id(), $groupId);
  1424. return $doc_id;
  1425. // TODO: link to go document area
  1426. }
  1427. /**
  1428. * Exports the wiki page to PDF
  1429. */
  1430. function export_to_pdf($id, $course_code) {
  1431. $data = get_wiki_data($id);
  1432. $content_pdf = api_html_entity_decode($data['content'], ENT_QUOTES, api_get_system_encoding());
  1433. //clean wiki links
  1434. $clean_pdf_content = trim(preg_replace("/\[\[|\]\]/", " ", $content_pdf));
  1435. //@todo this line breaks the pdf export. TODO:clean compound wiki names
  1436. //$array_clean_pdf_content= explode('|', $clean_pdf_content);//delete and reworking
  1437. //$clean_pdf_content = $array_clean_pdf_content[1];//delete and reworking
  1438. $content_pdf= $clean_pdf_content;
  1439. $title_pdf = api_html_entity_decode($data['title'], ENT_QUOTES, api_get_system_encoding());
  1440. $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
  1441. $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding());
  1442. $html='
  1443. <!-- defines the headers/footers - this must occur before the headers/footers are set -->
  1444. <!--mpdf
  1445. <pageheader name="odds" content-left="'.$title_pdf.'" header-style-left="color: #880000; font-style: italic;" line="1" />
  1446. <pagefooter name="odds" content-right="{PAGENO}/{nb}" line="1" />
  1447. <!-- set the headers/footers - they will occur from here on in the document -->
  1448. <!--mpdf
  1449. <setpageheader name="odds" page="odd" value="on" show-this-page="1" />
  1450. <setpagefooter name="odds" page="O" value="on" />
  1451. mpdf-->'.$content_pdf;
  1452. $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  1453. if (file_exists($css_file)) {
  1454. $css = @file_get_contents($css_file);
  1455. } else {
  1456. $css = '';
  1457. }
  1458. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  1459. $pdf = new PDF();
  1460. $pdf->content_to_pdf($html, $css, $title_pdf, $course_code);
  1461. exit;
  1462. }
  1463. /**
  1464. * Function prevent double post (reload or F5)
  1465. *
  1466. */
  1467. function double_post($wpost_id) {
  1468. if (isset($_SESSION['wpost_id'])) {
  1469. if ($wpost_id == $_SESSION['wpost_id']) {
  1470. return false;
  1471. } else {
  1472. $_SESSION['wpost_id'] = $wpost_id;
  1473. return true;
  1474. }
  1475. } else {
  1476. $_SESSION['wpost_id'] = $wpost_id;
  1477. return true;
  1478. }
  1479. }
  1480. /**
  1481. * Function wizard individual assignment
  1482. * @author Juan Carlos Raña <herodoto@telefonica.net>
  1483. */
  1484. function auto_add_page_users($assignment_type) {
  1485. global $assig_user_id, $session_id; //$assig_user_id is need to identify end reflinks
  1486. $_clean['group_id']=(int)$_SESSION['_gid'];
  1487. if($_clean['group_id']==0)
  1488. {
  1489. //extract course members
  1490. if(!empty($session_id)){
  1491. $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true, $session_id);
  1492. }
  1493. else
  1494. {
  1495. $a_users_to_add = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true);
  1496. }
  1497. }
  1498. else
  1499. {
  1500. //extract group members
  1501. $subscribed_users = GroupManager :: get_subscribed_users($_clean['group_id']);
  1502. $subscribed_tutors = GroupManager :: get_subscribed_tutors($_clean['group_id']);
  1503. $a_users_to_add_with_duplicates=array_merge($subscribed_users, $subscribed_tutors);
  1504. //remove duplicates
  1505. $a_users_to_add = $a_users_to_add_with_duplicates;
  1506. //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_encode($value);'));
  1507. $a_users_to_add = array_unique($a_users_to_add);
  1508. //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_decode($value, true);'));
  1509. }
  1510. //echo print_r($a_users_to_add);
  1511. $all_students_pages = array();
  1512. //data about teacher
  1513. $userinfo=Database::get_user_info_from_id(api_get_user_id());
  1514. $name = api_get_person_name($userinfo['firstname'], $userinfo['lastname']);
  1515. if (api_get_user_id()<>0) {
  1516. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',false, true);
  1517. $image_repository = $image_path['dir'];
  1518. $existing_image = $image_path['file'];
  1519. $photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1520. } else {
  1521. $photo= '<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" width="40" height="50" align="top" title="'.$name.'" />';
  1522. }
  1523. //teacher assignment title
  1524. $title_orig=$_POST['title'];
  1525. //teacher assignment reflink
  1526. $link2teacher=$_POST['title']= $title_orig."_uass".api_get_user_id();
  1527. //first: teacher name, photo, and assignment description (original content)
  1528. // $content_orig_A='<div align="center" style="background-color: #F5F8FB; border:double">'.$photo.'<br />'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'<br />('.get_lang('Teacher').')</div><br/><div>';
  1529. $content_orig_A='<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6"><table border="0"><tr><td style="font-size:24px">'.get_lang('AssignmentDesc').'</td></tr><tr><td>'.$photo.'<br />'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'</td></tr></table></div>';
  1530. $content_orig_B='<br/><div align="center" style="font-size:24px">'.get_lang('AssignmentDescription').': '.$title_orig.'</div><br/>'.$_POST['content'];
  1531. //Second: student list (names, photo and links to their works).
  1532. //Third: Create Students work pages.
  1533. foreach($a_users_to_add as $user_id=>$o_user_to_add)
  1534. {
  1535. if($o_user_to_add['user_id'] != api_get_user_id()) //except that puts the task
  1536. {
  1537. $assig_user_id= $o_user_to_add['user_id']; //identifies each page as created by the student, not by teacher
  1538. $image_path = UserManager::get_user_picture_path_by_id($assig_user_id,'web',false, true);
  1539. $image_repository = $image_path['dir'];
  1540. $existing_image = $image_path['file'];
  1541. $name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname']);
  1542. $photo= '<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />';
  1543. $is_tutor_of_group = GroupManager :: is_tutor_of_group($assig_user_id,$_clean['group_id']); //student is tutor
  1544. $is_tutor_and_member = (GroupManager :: is_tutor_of_group($assig_user_id,$_clean['group_id']) && GroupManager :: is_subscribed($assig_user_id, $_clean['group_id'])); //student is tutor and member
  1545. if($is_tutor_and_member)
  1546. {
  1547. $status_in_group=get_lang('GroupTutorAndMember');
  1548. }
  1549. else
  1550. {
  1551. if($is_tutor_of_group)
  1552. {
  1553. $status_in_group=get_lang('GroupTutor');
  1554. }
  1555. else
  1556. {
  1557. $status_in_group=" "; //get_lang('GroupStandardMember')
  1558. }
  1559. }
  1560. if($assignment_type==1)
  1561. {
  1562. $_POST['title']= $title_orig;
  1563. $_POST['comment']=get_lang('AssignmentFirstComToStudent');
  1564. $_POST['content']='<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6"><table border="0"><tr><td style="font-size:24px">'.get_lang('AssignmentWork').'</td></tr><tr><td>'.$photo.'<br />'.$name.'</td></tr></table></div>[['.$link2teacher.' | '.get_lang('AssignmentLinktoTeacherPage').']] '; //If $content_orig_B is added here, the task written by the professor was copied to the page of each student. TODO: config options
  1565. //AssignmentLinktoTeacherPage
  1566. $all_students_pages[] = '<li>'.strtoupper($o_user_to_add['lastname']).', '.$o_user_to_add['firstname'].' [['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</li>'; //don't change this line without guaranteeing that users will be ordered by last names in the following format (surname, name)
  1567. //$all_students_pages[] = '<li><table border="0"><tr><td width="200">'.api_get_person_name($o_user_to_add['lastname'], $o_user_to_add['firstname']).'</td><td>[['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</td></tr></table></li>';
  1568. $_POST['assignment']=2;
  1569. }
  1570. save_new_wiki();
  1571. }
  1572. }//end foreach for each user
  1573. foreach($a_users_to_add as $user_id=>$o_user_to_add)
  1574. {
  1575. if($o_user_to_add['user_id'] == api_get_user_id())
  1576. {
  1577. $assig_user_id=$o_user_to_add['user_id'];
  1578. if($assignment_type==1)
  1579. {
  1580. $_POST['title']= $title_orig;
  1581. $_POST['comment']=get_lang('AssignmentDesc');
  1582. sort($all_students_pages);
  1583. $_POST['content']=$content_orig_A.$content_orig_B.'<br/><div align="center" style="font-size:18px; background-color: #F5F8FB; border:solid; border-color:#E6E6E6">'.get_lang('AssignmentLinkstoStudentsPage').'</div><br/><div style="background-color: #F5F8FB; border:solid; border-color:#E6E6E6"><ol>'.implode($all_students_pages).'</ol></div><br/>';
  1584. $_POST['assignment']=1;
  1585. }
  1586. save_new_wiki();
  1587. }
  1588. } //end foreach to teacher
  1589. }
  1590. /**
  1591. * Displays the results of a wiki search
  1592. * @param string Search term
  1593. * @param int Whether to search the contents (1) or just the titles (0)
  1594. */
  1595. function display_wiki_search_results($search_term, $search_content=0, $all_vers=0)
  1596. {
  1597. global $tbl_wiki, $groupfilter, $MonthsLong, $condition_session;
  1598. echo '<div class="row"><div class="form_header">'.get_lang('WikiSearchResults').'</div></div>';
  1599. $_clean['group_id']=(int)$_SESSION['_gid'];
  1600. $session_id=api_get_session_id();
  1601. $course_id = api_get_course_int_id();
  1602. //only by professors when page is hidden
  1603. if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
  1604. if ($all_vers=='1') {
  1605. if ($search_content=='1') {
  1606. $sql="SELECT * FROM ".$tbl_wiki."
  1607. WHERE c_id = $course_id AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND ".$groupfilter.$condition_session."";//search all pages and all versions
  1608. } else {
  1609. $sql="SELECT * FROM ".$tbl_wiki."
  1610. WHERE c_id = $course_id AND title LIKE '%".Database::escape_string($search_term)."%' AND ".$groupfilter.$condition_session."";//search all pages and all versions
  1611. }
  1612. } else {
  1613. if ($search_content=='1') {
  1614. $sql = "SELECT * FROM ".$tbl_wiki." s1
  1615. WHERE s1.c_id = $course_id AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND
  1616. id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";// warning don't use group by reflink because don't return the last version
  1617. }
  1618. else {
  1619. $sql = " SELECT * FROM ".$tbl_wiki." s1
  1620. WHERE s1.c_id = $course_id AND title LIKE '%".Database::escape_string($search_term)."%' AND
  1621. id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";// warning don't use group by reflink because don't return the last version
  1622. }
  1623. }
  1624. } else {
  1625. if($all_vers=='1') {
  1626. if ($search_content=='1') {
  1627. $sql="SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND ".$groupfilter.$condition_session."";//search all pages and all versions
  1628. } else {
  1629. $sql="SELECT * FROM ".$tbl_wiki." WHERE c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' AND ".$groupfilter.$condition_session."";//search all pages and all versions
  1630. }
  1631. } else {
  1632. if($search_content=='1') {
  1633. $sql = " SELECT * FROM ".$tbl_wiki." s1
  1634. WHERE s1.c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' OR content LIKE '%".Database::escape_string($search_term)."%' AND
  1635. id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";// warning don't use group by reflink because don't return the last version
  1636. } else {
  1637. $sql = " SELECT * FROM ".$tbl_wiki." s1
  1638. WHERE s1.c_id = $course_id AND visibility=1 AND title LIKE '%".Database::escape_string($search_term)."%' AND
  1639. id=(SELECT MAX(s2.id) FROM ".$tbl_wiki." s2 WHERE s2.c_id = $course_id AND s1.reflink = s2.reflink AND ".$groupfilter.$condition_session.")";// warning don't use group by reflink because don't return the last version
  1640. }
  1641. }
  1642. }
  1643. $result = Database::query($sql);
  1644. //show table
  1645. if (Database::num_rows($result) > 0) {
  1646. $row = array ();
  1647. while ($obj = Database::fetch_object($result)) {
  1648. //get author
  1649. $userinfo=Database::get_user_info_from_id($obj->user_id);
  1650. //get time
  1651. $year = substr($obj->dtime, 0, 4);
  1652. $month = substr($obj->dtime, 5, 2);
  1653. $day = substr($obj->dtime, 8, 2);
  1654. $hours = substr($obj->dtime, 11,2);
  1655. $minutes = substr($obj->dtime, 14,2);
  1656. $seconds = substr($obj->dtime, 17,2);
  1657. //get type assignment icon
  1658. if($obj->assignment==1)
  1659. {
  1660. $ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',22);
  1661. }
  1662. elseif ($obj->assignment==2)
  1663. {
  1664. $ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',22);
  1665. }
  1666. elseif ($obj->assignment==0)
  1667. {
  1668. $ShowAssignment='<img src="../img/px_transparent.gif" />';
  1669. }
  1670. $row = array ();
  1671. $row[] =$ShowAssignment;
  1672. if($all_vers=='1') {
  1673. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course['id'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&view='.$obj->id.'&session_id='.api_htmlentities(urlencode($_GET['$session_id'])).'&group_id='.api_htmlentities(urlencode($_GET['group_id'])).'">'.api_htmlentities($obj->title).'</a>';
  1674. }
  1675. else {
  1676. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.$obj->title.'</a>';
  1677. }
  1678. $row[] = $obj->user_id <>0 ? '<a href="../user/userInfo.php?uInfo='.$userinfo['user_id'].'">'.api_htmlentities(api_get_person_name($userinfo['firstname'], $userinfo['lastname'])).'</a>' : get_lang('Anonymous').' ('.$obj->user_ip.')';
  1679. $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;
  1680. if($all_vers=='1') {
  1681. $row[] = $obj->version;
  1682. }
  1683. else {
  1684. if(api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) {
  1685. $showdelete=' <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=delete&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.Display::return_icon('delete.png', get_lang('Delete'),'',22);
  1686. }
  1687. $row[] = '<a href="'.api_get_self().'?cidReq='.$_course[id].'&action=edit&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.Display::return_icon('edit.png', get_lang('EditPage'),'',22).'</a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=discuss&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.Display::return_icon('discuss.png', get_lang('Discuss'),'',22).'</a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=history&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.Display::return_icon('history.png', get_lang('History'),'',22).'</a> <a href="'.api_get_self().'?cidReq='.$_course[id].'&action=links&title='.api_htmlentities(urlencode($obj->reflink)).'&group_id='.api_htmlentities($_GET['group_id']).'">'.Display::return_icon('what_link_here.png', get_lang('LinksPages'),'',22).'</a>'.$showdelete;
  1688. }
  1689. $rows[] = $row;
  1690. }
  1691. $table = new SortableTableFromArrayConfig($rows,1,10,'SearchPages_table','','','ASC');
  1692. $table->set_additional_parameters(array('cidReq' =>$_GET['cidReq'],'action'=>$_GET['action'],'group_id'=>Security::remove_XSS($_GET['group_id']),'mode_table'=>'yes2','search_term'=>$search_term, 'search_content'=>$search_content, 'all_vers'=>$all_vers));
  1693. $table->set_header(0,get_lang('Type'), true, array ('style' => 'width:30px;'));
  1694. $table->set_header(1,get_lang('Title'), true);
  1695. if($all_vers=='1') {
  1696. $table->set_header(2,get_lang('Author'), true);
  1697. $table->set_header(3,get_lang('Date'), true);
  1698. $table->set_header(4,get_lang('Version'), true);
  1699. }
  1700. else {
  1701. $table->set_header(2,get_lang('Author').' ('.get_lang('LastVersion').')', true);
  1702. $table->set_header(3,get_lang('Date').' ('.get_lang('LastVersion').')', true);
  1703. $table->set_header(4,get_lang('Actions'), false, array ('style' => 'width:130px;'));
  1704. }
  1705. $table->display();
  1706. }
  1707. else
  1708. {
  1709. echo get_lang('NoSearchResults');
  1710. }
  1711. }
  1712. /**
  1713. * Returns a date picker
  1714. * @todo replace this function with the formvalidator datepicker
  1715. *
  1716. */
  1717. function draw_date_picker($prefix,$default='') {
  1718. if(empty($default)) {
  1719. $default = date('Y-m-d H:i:s');
  1720. }
  1721. $parts = split(' ',$default);
  1722. list($d_year,$d_month,$d_day) = split('-',$parts[0]);
  1723. list($d_hour,$d_minute) = split(':',$parts[1]);
  1724. $month_list = array(
  1725. 1=>get_lang('JanuaryLong'),
  1726. 2=>get_lang('FebruaryLong'),
  1727. 3=>get_lang('MarchLong'),
  1728. 4=>get_lang('AprilLong'),
  1729. 5=>get_lang('MayLong'),
  1730. 6=>get_lang('JuneLong'),
  1731. 7=>get_lang('JulyLong'),
  1732. 8=>get_lang('AugustLong'),
  1733. 9=>get_lang('SeptemberLong'),
  1734. 10=>get_lang('OctoberLong'),
  1735. 11=>get_lang('NovemberLong'),
  1736. 12=>get_lang('DecemberLong')
  1737. );
  1738. $minute = range(10,59);
  1739. array_unshift($minute,'00','01','02','03','04','05','06','07','08','09');
  1740. $date_form = make_select($prefix.'_day', array_combine(range(1,31),range(1,31)), $d_day);
  1741. $date_form .= make_select($prefix.'_month', $month_list, $d_month);
  1742. $date_form .= make_select($prefix.'_year', array($d_year-2=>$d_year-2, $d_year-1=>$d_year-1, $d_year=> $d_year, $d_year+1=>$d_year+1, $d_year+2=>$d_year+2), $d_year).'&nbsp;&nbsp;&nbsp;&nbsp;';
  1743. $date_form .= make_select($prefix.'_hour', array_combine(range(0,23),range(0,23)), $d_hour).' : ';
  1744. $date_form .= make_select($prefix.'_minute', $minute, $d_minute);
  1745. return $date_form;
  1746. }
  1747. /**
  1748. * Draws an HTML form select with the given options
  1749. *
  1750. */
  1751. function make_select($name,$values,$checked='') {
  1752. $output = '<select name="'.$name.'" id="'.$name.'">';
  1753. foreach($values as $key => $value) {
  1754. $output .= '<option value="'.$key.'" '.(($checked==$key)?'selected="selected"':'').'>'.$value.'</option>';
  1755. }
  1756. $output .= '</select>';
  1757. return $output;
  1758. }
  1759. /**
  1760. * Translates a form date into a more usable format
  1761. *
  1762. */
  1763. function get_date_from_select($prefix) {
  1764. return $_POST[$prefix.'_year'].'-'.two_digits($_POST[$prefix.'_month']).'-'.two_digits($_POST[$prefix.'_day']).' '.two_digits($_POST[$prefix.'_hour']).':'.two_digits($_POST[$prefix.'_minute']).':00';
  1765. }
  1766. /**
  1767. * Converts 1-9 to 01-09
  1768. */
  1769. function two_digits($number) {
  1770. $number = (int)$number;
  1771. return ($number < 10) ? '0'.$number : $number;
  1772. }
  1773. /**
  1774. * Get wiki information
  1775. * @param int wiki id
  1776. * @return array wiki data
  1777. */
  1778. function get_wiki_data($id) {
  1779. global $tbl_wiki;
  1780. $id = intval($id);
  1781. $sql='SELECT * FROM '.$tbl_wiki.' WHERE id = '.$id.' ';
  1782. $result=Database::query($sql);
  1783. $data = array();
  1784. while ($row=Database::fetch_array($result,'ASSOC')) {
  1785. $data = $row;
  1786. }
  1787. return $data;
  1788. }