wiki.inc.php 72 KB

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