2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
14 * This script handles the ajax post submit from "content editor" =? "adpated content"
15 * to save the selected alternative into database
16 * @see file_manager/filemanager_display.inc.php
18 * pid: primary resource id
19 * a_type: alternative type, must be one of the values in resource_types.type_id
20 * alternative: the location and name of the selected alternative
23 define('TR_INCLUDE_PATH', '../../include/');
24 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
26 $pid = intval($_POST['pid']);
27 $type_id = intval($_POST['a_type']);
28 $secondary_resource = trim($_POST['alternative']);
31 if ($pid == 0 || $type_id == 0 || $secondary_resource == '') exit;
33 require_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
36 // delete the existing alternative for this (pid, a_type)
37 $sql = "SELECT sr.secondary_resource_id
38 FROM ".TABLE_PREFIX."secondary_resources sr, ".TABLE_PREFIX."secondary_resources_types srt
39 WHERE sr.secondary_resource_id = srt.secondary_resource_id
40 AND sr.primary_resource_id = ".$pid."
41 AND sr.language_code = '".$_SESSION['lang']."'
42 AND srt.type_id=".$type_id;
43 //$existing_secondary_result = mysql_query($sql, $db);
44 $existing_secondary_rows = $dao->execute($sql);
46 if (is_array($existing_secondary_rows)) {
47 foreach ($existing_secondary_rows as $existing_secondary)
49 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources
50 WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id'];
53 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources_types
54 WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id']."
55 AND type_id=".$type_id;
60 // insert new alternative
61 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources (primary_resource_id, secondary_resource, language_code)
62 VALUES (".$pid.", '".mysql_real_escape_string($secondary_resource)."', '".$_SESSION['lang']."')";
64 $secondary_resource_id = mysql_insert_id();
66 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources_types (secondary_resource_id, type_id)
67 VALUES (".$secondary_resource_id.", ".$type_id.")";