wiki.inc.php 77 KB

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