wiki.inc.php 77 KB

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