2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 * This script handles the ajax post submit from "content editor" =? "adpated content"
16 * to save the selected alternative into database
17 * @see mods/_core/file_manager/filemanager_display.inc.php
19 * pid: primary resource id
20 * a_type: alternative type, must be one of the values in resource_types.type_id
21 * alternative: the location and name of the selected alternative
24 define('AT_INCLUDE_PATH', '../../../include/');
25 require (AT_INCLUDE_PATH.'vitals.inc.php');
27 $pid = intval($_POST['pid']);
28 $type_id = intval($_POST['a_type']);
29 $secondary_resource = trim($_POST['alternative']);
32 if ($pid == 0 || $type_id == 0 || $secondary_resource == '') exit;
35 // delete the existing alternative for this (pid, a_type)
36 $sql = "SELECT sr.secondary_resource_id
37 FROM ".TABLE_PREFIX."secondary_resources sr, ".TABLE_PREFIX."secondary_resources_types srt
38 WHERE sr.secondary_resource_id = srt.secondary_resource_id
39 AND sr.primary_resource_id = ".$pid."
40 AND sr.language_code = '".$_SESSION['lang']."'
41 AND srt.type_id=".$type_id;
42 $existing_secondary_result = mysql_query($sql, $db);
44 while ($existing_secondary = mysql_fetch_assoc($existing_secondary_result))
46 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources
47 WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id'];
48 $result = mysql_query($sql, $db);
50 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources_types
51 WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id']."
52 AND type_id=".$type_id;
53 $result = mysql_query($sql, $db);
56 // insert new alternative
57 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources (primary_resource_id, secondary_resource, language_code)
58 VALUES (".$pid.", '".mysql_real_escape_string($secondary_resource)."', '".$_SESSION['lang']."')";
59 $result = mysql_query($sql, $db);
60 $secondary_resource_id = mysql_insert_id();
62 $sql = "INSERT INTO ".TABLE_PREFIX."secondary_resources_types (secondary_resource_id, type_id)
63 VALUES (".$secondary_resource_id.", ".$type_id.")";
64 $result = mysql_query($sql, $db);