wiki.inc.php 73 KB

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