wiki.inc.php 74 KB

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