wiki.inc.php 90 KB

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