PageRenderTime 63ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/home/editor/editor_tab_functions.inc.php

https://github.com/supungs/AContent
PHP | 845 lines | 365 code | 97 blank | 383 comment | 119 complexity | 5d04e7e48aa385294ef65f138ed2eea6 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, MIT, AGPL-1.0
  1. <?php
  2. /************************************************************************/
  3. /* AContent */
  4. /************************************************************************/
  5. /* Copyright (c) 2013 */
  6. /* Inclusive Design Institute */
  7. /* */
  8. /* This program is free software. You can redistribute it and/or */
  9. /* modify it under the terms of the GNU General Public License */
  10. /* as published by the Free Software Foundation. */
  11. /************************************************************************/
  12. if (!defined('TR_INCLUDE_PATH')) { exit; }
  13. function in_array_cin($strItem, $arItems)
  14. {
  15. foreach ($arItems as $key => $strValue)
  16. {
  17. if (strtoupper($strItem) == strtoupper($strValue))
  18. {
  19. return $key;
  20. }
  21. }
  22. return false;
  23. }
  24. function get_tabs() {
  25. //these are the _AT(x) variable names and their include file
  26. /* tabs[tab_id] = array(tab_name, file_name, accesskey) */
  27. /* Check if the page template_layout and are enabled or disabled */
  28. include_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
  29. $dao = new DAO();
  30. $inc=0;
  31. $tabs[$inc] = array('content', 'edit.inc.php', 'n');
  32. $sql="SELECT value FROM ".TABLE_PREFIX."config WHERE name='enable_template_layout'";
  33. $result=$dao->execute($sql);
  34. if(is_array($result))
  35. {
  36. foreach ($result as $support) {
  37. if($support['value']==TR_STATUS_ENABLED)
  38. $tabs[++$inc] = array('layout', 'layout.inc.php', 'l');
  39. }
  40. }
  41. $sql="SELECT value FROM ".TABLE_PREFIX."config WHERE name='enable_template_page'";
  42. $result=$dao->execute($sql);
  43. if(is_array($result))
  44. {
  45. foreach ($result as $support) {
  46. if($support['value']==TR_STATUS_ENABLED)
  47. $tabs[++$inc] = array('page_template', 'page_template.inc.php', 'g');
  48. }
  49. }
  50. $tabs[++$inc] = array('metadata', 'properties.inc.php', 'p');
  51. $tabs[++$inc] = array('alternative_content', 'alternatives.inc.php', 'a');
  52. $tabs[++$inc] = array('tests', 'tests.inc.php', 't');
  53. /* DEFAULT IS TO PROF
  54. $tabs[0] = array('content', 'edit.inc.php', 'n');
  55. $tabs[1] = array('layout', 'layout.inc.php', 'l');
  56. $tabs[2] = array('page_template', 'page_template.inc.php', 'g');
  57. $tabs[3] = array('metadata', 'properties.inc.php', 'p');
  58. $tabs[4] = array('alternative_content', 'alternatives.inc.php', 'a');
  59. $tabs[5] = array('tests', 'tests.inc.php', 't');
  60. //catia
  61. //$tabs[4] = array('forums', '');
  62. *
  63. * END DEFAULT
  64. */
  65. return $tabs;
  66. }
  67. function output_tabs($current_tab, $changes) {
  68. global $_base_path;
  69. $tabs = get_tabs();
  70. $num_tabs = count($tabs);
  71. ?>
  72. <table class="etabbed-table" border="0" cellpadding="0" cellspacing="0" width="95%">
  73. <tr>
  74. <?php
  75. for ($i=0; $i < $num_tabs; $i++):
  76. if ($current_tab == $i):?>
  77. <td class="editor_tab_selected">
  78. <?php if ($changes[$i]): ?>
  79. <img src="<?php echo $_base_path; ?>images/changes_bullet.gif" alt="<?php echo _AT('usaved_changes_made'); ?>" height="12" width="15" />
  80. <?php endif; ?>
  81. <?php echo _AT($tabs[$i][0]); ?>
  82. </td>
  83. <td class="tab-spacer">&nbsp;</td>
  84. <?php else: ?>
  85. <td class="editor_tab">
  86. <?php if ($changes[$i]): ?>
  87. <img src="<?php echo $_base_path; ?>images/changes_bullet.gif" alt="<?php echo _AT('usaved_changes_made'); ?>" height="12" width="15" />
  88. <?php endif; ?>
  89. <?php echo '<input type="submit" name="button_'.$i.'" value="'._AT($tabs[$i][0]).'" title="'._AT($tabs[$i][0]).' - alt '.$tabs[$i][2].'" class="editor_buttontab" accesskey="'.$tabs[$i][2].'" onmouseover="this.style.cursor=\'pointer\';" '.$clickEvent.' />'; ?>
  90. </td>
  91. <td class="tab-spacer">&nbsp;</td>
  92. <?php endif; ?>
  93. <?php endfor; ?>
  94. <td >&nbsp;</td>
  95. </tr>
  96. </table>
  97. <?php }
  98. /**
  99. * Strips all tags and encodes special characters in the URL
  100. * Returns false if the URL is invalid
  101. *
  102. * @param string $url
  103. * @return mixed - returns a stripped and encoded URL or false if URL is invalid
  104. */
  105. function isValidURL($url) {
  106. if (substr($url,0,4) === 'http') {
  107. return filter_var(filter_var($url, FILTER_SANITIZE_STRING), FILTER_VALIDATE_URL);
  108. }
  109. return false;
  110. }
  111. /*
  112. * Parse the primary resources out of the content and save into db.
  113. * Clean up the removed primary resources from db.
  114. * @param: $cid: content id
  115. * @param: $content
  116. * @return: none
  117. */
  118. function populate_a4a($cid, $content, $formatting){
  119. global $my_files, $content_base_href, $contentManager;
  120. // Defining alternatives is only available for content type "html".
  121. // But don't clean up the a4a tables at other content types in case the user needs them back at html.
  122. if ($formatting <> 1) return;
  123. include_once(TR_INCLUDE_PATH.'classes/A4a/A4a.class.php');
  124. include_once(TR_INCLUDE_PATH.'classes/XML/XML_HTMLSax/XML_HTMLSax.php'); /* for XML_HTMLSax */
  125. include_once(TR_INCLUDE_PATH.'classes/ContentOutputParser.class.php'); /* for parser */
  126. // initialize content_base_href; used in format_content
  127. if (!isset($content_base_href)) {
  128. $content_row = $contentManager->getContentPage($cid);
  129. // return if the cid is not found
  130. if (!is_array($content_row)) {
  131. return;
  132. }
  133. $content_base_href = $content_row["content_path"].'/';
  134. }
  135. $body = ContentUtility::formatContent($content, $formatting);
  136. $handler = new ContentOutputParser();
  137. $parser = new XML_HTMLSax();
  138. $parser->set_object($handler);
  139. $parser->set_element_handler('openHandler','closeHandler');
  140. $my_files = array();
  141. $parser->parse($body);
  142. $my_files = array_unique($my_files);
  143. foreach ($my_files as $file) {
  144. /* filter out full urls */
  145. $url_parts = @parse_url($file);
  146. // file should be relative to content
  147. if ((substr($file, 0, 1) == '/')) {
  148. continue;
  149. }
  150. // The URL of the movie from youtube.com has been converted above in embed_media().
  151. // For example: http://www.youtube.com/watch?v=a0ryB0m0MiM is converted to
  152. // http://www.youtube.com/v/a0ryB0m0MiM to make it playable. This creates the problem
  153. // that the parsed-out url (http://www.youtube.com/v/a0ryB0m0MiM) does not match with
  154. // the URL saved in content table (http://www.youtube.com/watch?v=a0ryB0m0MiM).
  155. // The code below is to convert the URL back to original.
  156. $file = ContentUtility::convertYoutubePlayURLToWatchURL($file);
  157. $resources[] = convertAmp($file); // converts & to &amp;
  158. }
  159. $a4a = new A4a($cid);
  160. $db_primary_resources = $a4a->getPrimaryResources();
  161. // clean up the removed resources
  162. foreach ($db_primary_resources as $primary_rid=>$db_resource){
  163. //if this file from our table is not found in the $resource, then it's not used.
  164. if(count($resources) == 0 || !in_array($db_resource['resource'], $resources)){
  165. $a4a->deletePrimaryResource($primary_rid);
  166. }
  167. }
  168. if (count($resources) == 0) return;
  169. // insert the new resources
  170. foreach($resources as $primary_resource)
  171. {
  172. if (!$a4a->getPrimaryResourceByName($primary_resource)){
  173. $a4a->setPrimaryResource($cid, $primary_resource, $_SESSION['lang']);
  174. }
  175. }
  176. }
  177. // save all changes to the DB
  178. function save_changes($redir, $current_tab) {
  179. global $contentManager, $addslashes, $msg, $_course_id, $_content_id, $stripslashes;
  180. $_POST['pid'] = intval($_POST['pid']);
  181. $_POST['_cid'] = intval($_POST['_cid']);
  182. $_POST['alternatives'] = intval($_POST['alternatives']);
  183. $_POST['title'] = trim($_POST['title']);
  184. $_POST['head'] = trim($_POST['head']);
  185. $_POST['use_customized_head'] = isset($_POST['use_customized_head'])?$_POST['use_customized_head']:0;
  186. $_POST['body_text'] = $stripslashes(trim($_POST['body_text']));
  187. $_POST['weblink_text'] = trim($_POST['weblink_text']);
  188. $_POST['formatting'] = intval($_POST['formatting']);
  189. $_POST['keywords'] = $stripslashes(trim($_POST['keywords']));
  190. $_POST['test_message'] = trim($_POST['test_message']);
  191. //if weblink is selected, use it
  192. if ($_POST['formatting']==CONTENT_TYPE_WEBLINK) {
  193. $url = $_POST['weblink_text'];
  194. $validated_url = isValidURL($url);
  195. if (!validated_url || $validated_url !== $url) {
  196. $msg->addError(array('INVALID_INPUT', _AT('weblink')));
  197. } else {
  198. $_POST['body_text'] = $url;
  199. $content_type_pref = CONTENT_TYPE_WEBLINK;
  200. }
  201. } else {
  202. $content_type_pref = CONTENT_TYPE_CONTENT;
  203. }
  204. /*if (!($release_date = generate_release_date())) {
  205. $msg->addError('BAD_DATE');
  206. }*/
  207. // if ($_POST['title'] == '') {
  208. // $msg->addError(array('EMPTY_FIELDS', _AT('title')));
  209. // }
  210. // if (!$msg->containsErrors()) {
  211. $orig_body_text = $_POST['body_text']; // used to populate a4a tables
  212. // $_POST['title'] = $addslashes($_POST['title']);
  213. // $_POST['body_text'] = $addslashes($_POST['body_text']);
  214. // $_POST['head'] = $addslashes($_POST['head']);
  215. // $_POST['keywords'] = $addslashes($_POST['keywords']);
  216. // $_POST['test_message'] = $addslashes($_POST['test_message']);
  217. // add or edit content
  218. if ($_POST['_cid']) {
  219. /* editing an existing page */
  220. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $_POST['body_text'],
  221. $_POST['keywords'], $_POST['formatting'],
  222. $_POST['head'], $_POST['use_customized_head'],
  223. $_POST['test_message']);
  224. /*
  225. //ceppini matteo 09/11/2012
  226. // 13/11/2012
  227. // 14/11/2012
  228. $first_part='<table style="width: 100%; display: table;" class="page_template linee_guida">
  229. <tbody>
  230. <tr>
  231. <td>
  232. <div class="removePageTemplateTopBar" style="display: none;">
  233. <div class="removePageTemplate">X</div>
  234. </div>
  235. </td>
  236. </tr><tr><td class="pageTemplateContent" style="border: medium none;">';
  237. $second_part='</tr></td>
  238. <tr>
  239. <td>
  240. <div style="visibility: hidden;" class="sortTools">
  241. <img src="'.TR_BASE_HREF.'/templates/system/top.png" class="movePageTemplateTop" alt="move top">
  242. <img src="'.TR_BASE_HREF.'/templates/system/up.png" class="movePageTemplateUp" alt="move up">
  243. <img src="'.TR_BASE_HREF.'/templates/system/down.png" class="movePageTemplateDown" alt="move down">
  244. <img src="'.TR_BASE_HREF.'/templates/system/bottom.png" class="movePageTemplateBottom" alt="move bottom">
  245. </div>
  246. </td>
  247. </tr>
  248. </tbody>
  249. </table>';
  250. if(strstr($orig_body_text,'removePageTemplateTopBar')===false){
  251. //$control_string="non trovata";
  252. $first_part= $first_part. $_POST['body_text'];
  253. $control_string= $first_part. $second_part;
  254. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $control_string,
  255. $_POST['keywords'], $_POST['formatting'],
  256. $_POST['head'], $_POST['use_customized_head'],
  257. $_POST['test_message']);
  258. }else{
  259. $first_part= $first_part. $_POST['body_text'];
  260. $second_part='</tbody></table>';
  261. $control_string= $first_part. $second_part;
  262. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $control_string,
  263. $_POST['keywords'], $_POST['formatting'],
  264. $_POST['head'], $_POST['use_customized_head'],
  265. $_POST['test_message']);
  266. }
  267. // IDEA SOTTARRE AL NUOVO TESTO QUELLO PRECEDENTE E CONTROLLARE SE CONTIENE TESTO E POI RACCHIUDERLO
  268. define('TR_INCLUDE_PATH', '../../include/');
  269. global $associated_forum, $_course_id, $_content_id;
  270. include_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
  271. require_once(TR_INCLUDE_PATH.'lib/tinymce.inc.php');
  272. require_once(TR_INCLUDE_PATH.'classes/FileUtility.class.php');
  273. Utility::authenticate(TR_PRIV_ISAUTHOR);
  274. $dao = new DAO();
  275. $cid = $_POST['_cid'];
  276. $sql="SELECT text FROM ".TABLE_PREFIX."content WHERE content_id=".$cid."";
  277. $result=$dao->execute($sql);
  278. if(is_array($result))
  279. {
  280. foreach ($result as $support) {
  281. $text=$support['text'];
  282. break;
  283. }
  284. }
  285. //************************************************
  286. // In $text ho il vecchio contenuto
  287. // In $orig_body_text ho tutto il nuovo contenuto
  288. //************************************************
  289. //$appoggio=substr($orig_body_text, $text); NON VA
  290. //$appogio=substr_compare($orig_body_text, $text);
  291. $rr= strlen($text);
  292. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $rr,
  293. $_POST['keywords'], $_POST['formatting'],
  294. $_POST['head'], $_POST['use_customized_head'],
  295. $_POST['test_message']);
  296. if(!empty($text)){
  297. // $appoggio=str_replace($text,"",$orig_body_text);
  298. // $appoggio=str_ireplace($orig_body_text, "", $text);
  299. // appoggio-->contenuto vecchio
  300. // die($text);
  301. // $appoggio=substr($orig_body_text,strlen($appoggio));
  302. $a=(string)$text;
  303. $lunghezza=strlen($a);
  304. // die($lunghezza);
  305. $rrrr=str_replace($orig_body_text,"",$text);
  306. $appoggio=substr($orig_body_text,$lunghezza);
  307. $appoggio=strip_tags($appoggio);
  308. // die($appoggio);
  309. if(strstr($appoggio,'removePageTemplateTopBar')===false){
  310. //$control_string="non trovata";
  311. $first_part=$first_part. '<br>';
  312. $first_part= $first_part. $appoggio;
  313. $appoggio= $first_part. $second_part;
  314. $control_string=$rrrr. $appoggio;
  315. //die($rrrr);
  316. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $control_string,
  317. $_POST['keywords'], $_POST['formatting'],
  318. $_POST['head'], $_POST['use_customized_head'],
  319. $_POST['test_message']);
  320. }else{
  321. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $orig_body_text,
  322. $_POST['keywords'], $_POST['formatting'],
  323. $_POST['head'], $_POST['use_customized_head'],
  324. $_POST['test_message']);
  325. }
  326. }else{
  327. if(strstr($orig_body_text,'removePageTemplateTopBar')===false){
  328. $first_part= $first_part. $_POST['body_text'];
  329. $control_string= $first_part. $second_part;
  330. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $control_string,
  331. $_POST['keywords'], $_POST['formatting'],
  332. $_POST['head'], $_POST['use_customized_head'],
  333. $_POST['test_message']);
  334. }else{
  335. $err = $contentManager->editContent($_POST['_cid'], $_POST['title'], $_POST['body_text'],
  336. $_POST['keywords'], $_POST['formatting'],
  337. $_POST['head'], $_POST['use_customized_head'],
  338. $_POST['test_message']);
  339. }
  340. }*/
  341. $cid = $_POST['_cid'];
  342. } else {
  343. /* insert new */
  344. $cid = $contentManager->addContent($_course_id,
  345. $_POST['pid'],
  346. $_POST['ordering'],
  347. $_POST['title'],
  348. $_POST['body_text'],
  349. $_POST['keywords'],
  350. $_POST['related'],
  351. $_POST['formatting'],
  352. $_POST['head'],
  353. $_POST['use_customized_head'],
  354. $_POST['test_message'],
  355. $content_type_pref);
  356. $_POST['_cid'] = $cid;
  357. $_REQUEST['_cid'] = $cid;
  358. }
  359. if ($cid == 0) return;
  360. // re-populate a4a tables based on the new content
  361. populate_a4a($cid, $orig_body_text, $_POST['formatting']);
  362. // }
  363. /* insert glossary terms */
  364. /*
  365. if (is_array($_POST['glossary_defs']) && ($num_terms = count($_POST['glossary_defs']))) {
  366. global $glossary, $glossary_ids, $msg;
  367. foreach($_POST['glossary_defs'] as $w => $d) {
  368. $old_w = $w;
  369. $key = in_array_cin($w, $glossary_ids);
  370. $w = urldecode($w);
  371. $d = $addslashes($d);
  372. if (($key !== false) && (($glossary[$old_w] != $d) || isset($_POST['related_term'][$old_w])) ) {
  373. $w = addslashes($w);
  374. $related_id = intval($_POST['related_term'][$old_w]);
  375. $sql = "UPDATE ".TABLE_PREFIX."glossary SET definition='$d', related_word_id=$related_id WHERE word_id=$key AND course_id=$_SESSION[course_id]";
  376. $result = mysql_query($sql, $db);
  377. $glossary[$old_w] = $d;
  378. } else if ($key === false && ($d != '')) {
  379. $w = addslashes($w);
  380. $related_id = intval($_POST['related_term'][$old_w]);
  381. $sql = "INSERT INTO ".TABLE_PREFIX."glossary VALUES (NULL, $_SESSION[course_id], '$w', '$d', $related_id)";
  382. $result = mysql_query($sql, $db);
  383. $glossary[$old_w] = $d;
  384. }
  385. }
  386. }*/
  387. if (isset($_GET['tab'])) {
  388. $current_tab = intval($_GET['tab']);
  389. }
  390. if (isset($_POST['current_tab'])) {
  391. $current_tab = intval($_POST['current_tab']);
  392. }
  393. // adapted content: save primary content type
  394. if (isset($_POST['use_post_for_alt']))
  395. {
  396. include_once(TR_INCLUDE_PATH.'classes/DAO/PrimaryResourcesTypesDAO.class.php');
  397. $primaryResourcesTypesDAO = new PrimaryResourcesTypesDAO();
  398. // 1. delete old primary content type
  399. $sql = "DELETE FROM ".TABLE_PREFIX."primary_resources_types
  400. WHERE primary_resource_id in
  401. (SELECT DISTINCT primary_resource_id
  402. FROM ".TABLE_PREFIX."primary_resources
  403. WHERE content_id=".$cid."
  404. AND language_code='".$_SESSION['lang']."')";
  405. $primaryResourcesTypesDAO->execute($sql);
  406. // 2. insert the new primary content type
  407. $sql = "SELECT pr.primary_resource_id, rt.type_id
  408. FROM ".TABLE_PREFIX."primary_resources pr, ".
  409. TABLE_PREFIX."resource_types rt
  410. WHERE pr.content_id = ".$cid."
  411. AND pr.language_code = '".$_SESSION['lang']."'";
  412. $all_types_rows = $primaryResourcesTypesDAO->execute($sql);
  413. if (is_array($all_types_rows)) {
  414. foreach ($all_types_rows as $type) {
  415. if (isset($_POST['alt_'.$type['primary_resource_id'].'_'.$type['type_id']]))
  416. {
  417. $primaryResourcesTypesDAO->Create($type['primary_resource_id'], $type['type_id']);
  418. // $sql = "INSERT INTO ".TABLE_PREFIX."primary_resources_types (primary_resource_id, type_id)
  419. // VALUES (".$type['primary_resource_id'].", ".$type['type_id'].")";
  420. // $result = mysql_query($sql, $db);
  421. }
  422. }
  423. }
  424. }
  425. include_once(TR_INCLUDE_PATH.'classes/DAO/ContentTestsAssocDAO.class.php');
  426. $contentTestsAssocDAO = new ContentTestsAssocDAO();
  427. $test_rows = $contentTestsAssocDAO->getByContent($_POST['_cid']);
  428. // $sql = 'SELECT * FROM '.TABLE_PREFIX."content_tests_assoc WHERE content_id=$_POST[cid]";
  429. // $result = mysql_query($sql, $db);
  430. $db_test_array = array();
  431. if (is_array($test_rows)) {
  432. foreach ($test_rows as $row) {
  433. $db_test_array[] = $row['test_id'];
  434. }
  435. }
  436. if (is_array($_POST['tid']) && sizeof($_POST['tid']) > 0){
  437. $toBeDeleted = array_diff($db_test_array, $_POST['tid']);
  438. $toBeAdded = array_diff($_POST['tid'], $db_test_array);
  439. //Delete entries
  440. if (!empty($toBeDeleted)){
  441. $tids = implode(",", $toBeDeleted);
  442. $sql = 'DELETE FROM '. TABLE_PREFIX . "content_tests_assoc WHERE content_id=$_POST[cid] AND test_id IN ($tids)";
  443. $contentTestsAssocDAO->execute($sql);
  444. }
  445. //Add entries
  446. if (!empty($toBeAdded)){
  447. foreach ($toBeAdded as $i => $tid){
  448. $tid = intval($tid);
  449. // $sql = 'INSERT INTO '. TABLE_PREFIX . "content_tests_assoc SET content_id=$_POST[cid], test_id=$tid";
  450. // $result = mysql_query($sql, $db);
  451. if ($contentTestsAssocDAO->Create($_POST['_cid'], $tid) === false){
  452. $msg->addError('DB_NOT_UPDATED');
  453. }
  454. }
  455. }
  456. } else {
  457. //All tests has been removed.
  458. $contentTestsAssocDAO->DeleteByContentID($_POST['_cid']);
  459. // $sql = 'DELETE FROM '. TABLE_PREFIX . "content_tests_assoc WHERE content_id=$_POST[cid]";
  460. // $result = mysql_query($sql, $db);
  461. }
  462. //End Add test
  463. //TODO*******************BOLOGNA****************REMOVE ME**************/
  464. /*
  465. if(isset($_SESSION['associated_forum']) && !$msg->containsErrors()){
  466. if($_SESSION['associated_forum']=='none'){
  467. $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
  468. mysql_query($sql,$db);
  469. } else {
  470. $sql = "DELETE FROM ".TABLE_PREFIX."content_forums_assoc WHERE content_id='$_POST[cid]'";
  471. mysql_query($sql,$db);
  472. $associated_forum = $_SESSION['associated_forum'];
  473. for($i=0; $i<count($associated_forum); $i++){
  474. $sql="INSERT INTO ".TABLE_PREFIX."content_forums_assoc SET content_id='$_POST[cid]',forum_id='$associated_forum[$i]'";
  475. mysql_query($sql,$db);
  476. }
  477. }
  478. unset($_SESSION['associated_forum']);
  479. }
  480. */
  481. if (!$msg->containsErrors() && $redir) {
  482. $_SESSION['save_n_close'] = $_POST['save_n_close'];
  483. $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
  484. header('Location: '.basename($_SERVER['PHP_SELF']).'?_cid='.$cid.SEP.'close='.$addslashes($_POST['save_n_close']).SEP.'tab='.$addslashes($_POST['current_tab']).SEP.'displayhead='.$addslashes($_POST['displayhead']).SEP.'alternatives='.$addslashes($_POST['alternatives']));
  485. exit;
  486. } else {
  487. return;
  488. }
  489. }
  490. /*
  491. function generate_release_date($now = false) {
  492. if ($now) {
  493. $day = date('d');
  494. $month= date('m');
  495. $year = date('Y');
  496. $hour = date('H');
  497. $min = 0;
  498. } else {
  499. $day = intval($_POST['day']);
  500. $month = intval($_POST['month']);
  501. $year = intval($_POST['year']);
  502. $hour = intval($_POST['hour']);
  503. $min = intval($_POST['min']);
  504. }
  505. if (!checkdate($month, $day, $year)) {
  506. return false;
  507. }
  508. if (strlen($month) == 1){
  509. $month = "0$month";
  510. }
  511. if (strlen($day) == 1){
  512. $day = "0$day";
  513. }
  514. if (strlen($hour) == 1){
  515. $hour = "0$hour";
  516. }
  517. if (strlen($min) == 1){
  518. $min = "0$min";
  519. }
  520. $release_date = "$year-$month-$day $hour:$min:00";
  521. return $release_date;
  522. }
  523. */
  524. function check_for_changes($row, $row_alternatives) {
  525. global $contentManager, $cid, $glossary, $glossary_ids_related, $addslashes;
  526. $changes = array();
  527. if ($row && strcmp(trim($addslashes($_POST['title'])), addslashes($row['title']))) {
  528. $changes[0] = true;
  529. } else if (!$row && $_POST['title']) {
  530. $changes[0] = true;
  531. }
  532. if ($row && strcmp($addslashes(trim($_POST['head'])), trim(addslashes($row['head'])))) {
  533. $changes[0] = true;
  534. } else if (!$row && $_POST['head']) {
  535. $changes[0] = true;
  536. }
  537. if ($row && strcmp($addslashes(trim($_POST['body_text'])), trim(addslashes($row['text'])))) {
  538. $changes[0] = true;
  539. } else if (!$row && $_POST['body_text']) {
  540. $changes[0] = true;
  541. }
  542. if ($row && strcmp($addslashes(trim($_POST['weblink_text'])), trim(addslashes($row['text'])))) {
  543. $changes[0] = true;
  544. } else if (!$row && $_POST['weblink_text']) {
  545. $changes[0] = true;
  546. }
  547. /* use customized head: */
  548. if ($row && isset($_POST['use_customized_head']) && ($_POST['use_customized_head'] != $row['use_customized_head'])) {
  549. $changes[0] = true;
  550. }
  551. /* formatting: */
  552. if ($row && strcmp(trim($_POST['formatting']), $row['formatting'])) {
  553. $changes[0] = true;
  554. } else if (!$row && $_POST['formatting']) {
  555. $changes[0] = true;
  556. }
  557. /* release date: */
  558. // if ($row && strcmp(substr(generate_release_date(), 0, -2), substr($row['release_date'], 0, -2))) {
  559. // /* the substr was added because sometimes the release_date in the db has the seconds field set, which we dont use */
  560. // /* so it would show a difference, even though it should actually be the same, so we ignore the seconds with the -2 */
  561. // /* the seconds gets added if the course was created during the installation process. */
  562. // $changes[1] = true;
  563. // } else if (!$row && strcmp(generate_release_date(), generate_release_date(true))) {
  564. // $changes[1] = true;
  565. // }
  566. /* related content: */
  567. // $row_related = $contentManager->getRelatedContent($cid);
  568. //
  569. // if (is_array($_POST['related']) && is_array($row_related)) {
  570. // $sum = array_sum(array_diff($_POST['related'], $row_related));
  571. // $sum += array_sum(array_diff($row_related, $_POST['related']));
  572. // if ($sum > 0) {
  573. // $changes[1] = true;
  574. // }
  575. // } else if (!is_array($_POST['related']) && !empty($row_related)) {
  576. // $changes[1] = true;
  577. // }
  578. /* keywords */
  579. if ($row && strcmp(trim($_POST['keywords']), $row['keywords'])) {
  580. $changes[1] = true;
  581. } else if (!$row && $_POST['keywords']) {
  582. $changes[1] = true;
  583. }
  584. /* glossary */
  585. // if (is_array($_POST['glossary_defs'])) {
  586. // global $glossary_ids;
  587. // foreach ($_POST['glossary_defs'] as $w => $d) {
  588. //
  589. // $key = in_array_cin($w, $glossary_ids);
  590. // if ($key === false) {
  591. // /* new term */
  592. // $changes[2] = true;
  593. // break;
  594. // } else if ($cid && ($d &&($d != $glossary[$glossary_ids[$key]]))) {
  595. // /* changed term */
  596. // $changes[2] = true;
  597. // break;
  598. // }
  599. // }
  600. //
  601. // if (is_array($_POST['related_term'])) {
  602. // foreach($_POST['related_term'] as $term => $r_id) {
  603. // if ($glossary_ids_related[$term] != $r_id) {
  604. // $changes[2] = true;
  605. // break;
  606. // }
  607. // }
  608. // }
  609. // }
  610. /* adapted content */
  611. if (isset($_POST['use_post_for_alt']))
  612. {
  613. foreach ($_POST as $alt_id => $alt_value) {
  614. if (substr($alt_id, 0 ,4) == 'alt_' && $alt_value != $row_alternatives[$alt_id]){
  615. $changes[2] = true;
  616. break;
  617. }
  618. }
  619. }
  620. /* test & survey */
  621. if ($row && isset($_POST['test_message']) && $_POST['test_message'] != $row['test_message']){
  622. $changes[3] = true;
  623. }
  624. $content_tests = $contentManager->getContentTestsAssoc($cid);
  625. if (isset($_POST['visited_tests'])) {
  626. if (!is_array($content_tests) && is_array($_POST['tid'])) {
  627. $changes[3] = true;
  628. }
  629. if (is_array($content_tests)) {
  630. for ($i = 0; $i < count($content_tests); $i++) {
  631. if ($content_tests[$i]['test_id'] <> $_POST['tid'][$i]) {
  632. $changes[3] = true;
  633. break;
  634. }
  635. }
  636. }
  637. }
  638. return $changes;
  639. }
  640. function paste_from_file() {
  641. global $msg;
  642. include_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
  643. if ($_FILES['uploadedfile_paste']['name'] == '') {
  644. $msg->addError('FILE_NOT_SELECTED');
  645. return;
  646. }
  647. if ($_FILES['uploadedfile_paste']['name']
  648. && (($_FILES['uploadedfile_paste']['type'] == 'text/plain')
  649. || ($_FILES['uploadedfile_paste']['type'] == 'text/html')) )
  650. {
  651. $path_parts = pathinfo($_FILES['uploadedfile_paste']['name']);
  652. $ext = strtolower($path_parts['extension']);
  653. if (in_array($ext, array('html', 'htm'))) {
  654. $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
  655. /* get the <title></title> of this page */
  656. $start_pos = strpos(strtolower($_POST['body_text']), '<title>');
  657. $end_pos = strpos(strtolower($_POST['body_text']), '</title>');
  658. if (($start_pos !== false) && ($end_pos !== false)) {
  659. $start_pos += strlen('<title>');
  660. $_POST['title'] = trim(substr($_POST['body_text'], $start_pos, $end_pos-$start_pos));
  661. }
  662. unset($start_pos);
  663. unset($end_pos);
  664. $_POST['head'] = ContentUtility::getHtmlHeadByTag($_POST['body_text'], array("link", "style", "script"));
  665. if (strlen(trim($_POST['head'])) > 0)
  666. $_POST['use_customized_head'] = 1;
  667. else
  668. $_POST['use_customized_head'] = 0;
  669. $_POST['body_text'] = ContentUtility::getHtmlBody($_POST['body_text']);
  670. $msg->addFeedback('FILE_PASTED');
  671. } else if ($ext == 'txt') {
  672. $_POST['body_text'] = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
  673. //LAW
  674. $msg->addFeedback('FILE_PASTED');
  675. }
  676. } else {
  677. $msg->addError('BAD_FILE_TYPE');
  678. }
  679. return;
  680. }
  681. //for accessibility checker
  682. function write_temp_file() {
  683. global $_POST, $msg;
  684. if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
  685. $content_base = 'get.php/';
  686. } else {
  687. $content_base = 'content/' . $_SESSION['course_id'] . '/';
  688. }
  689. if ($_POST['content_path']) {
  690. $content_base .= $_POST['content_path'] . '/';
  691. }
  692. $file_name = $_POST['_cid'].'.html';
  693. if ($handle = fopen(TR_CONTENT_DIR . $file_name, 'wb+')) {
  694. // $temp_content = '<h2>'.TR_print(stripslashes($_POST['title']), 'content.title').'</h2>';
  695. //
  696. // if ($_POST['body_text'] != '') {
  697. // $temp_content .= format_content(stripslashes($_POST['body_text']), $_POST['formatting'], $_POST['glossary_defs']);
  698. // }
  699. // $temp_title = $_POST['title'];
  700. //
  701. // $html_template = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  702. // "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  703. // <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  704. // <head>
  705. // <base href="{BASE_HREF}" />
  706. // <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  707. // <title>{TITLE}</title>
  708. // <meta name="Generator" content="ATutor accessibility checker file - can be deleted">
  709. // </head>
  710. // <body>
  711. // {CONTENT}
  712. // </body>
  713. // </html>';
  714. //
  715. // $page_html = str_replace( array('{BASE_HREF}', '{TITLE}', '{CONTENT}'),
  716. // array($content_base, $temp_title, $temp_content),
  717. // $html_template);
  718. if (!@fwrite($handle, stripslashes($_POST['body_text']))) {
  719. $msg->addError('FILE_NOT_SAVED');
  720. }
  721. } else {
  722. $msg->addError('FILE_NOT_SAVED');
  723. }
  724. $msg->printErrors();
  725. }
  726. ?>