wiki.inc.php 75 KB

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