wiki.inc.php 75 KB

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