wiki.inc.php 77 KB

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