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 remove selected alternative from database
16 * @see home/editor/editor_tabs/alternatives.inc.php
18 * pid: primary resource id
19 * a_type: alternative type, must be one of the values in resource_types.type_id
22 define('TR_INCLUDE_PATH', '../../include/');
23 require (TR_INCLUDE_PATH.'vitals.inc.php');
25 $pid = intval($_POST['pid']);
26 $type_id = intval($_POST['a_type']);
29 if ($pid == 0 || $type_id == 0) exit;
31 require_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
34 // delete the existing alternative for this (pid, a_type)
35 $sql = "SELECT sr.secondary_resource_id
36 FROM ".TABLE_PREFIX."secondary_resources sr, ".TABLE_PREFIX."secondary_resources_types srt
37 WHERE sr.secondary_resource_id = srt.secondary_resource_id
38 AND sr.primary_resource_id = ".$pid."
39 AND sr.language_code = '".$_SESSION['lang']."'
40 AND srt.type_id=".$type_id;
41 $existing_secondary_rows = $dao->execute($sql);
43 if (is_array($existing_secondary_rows)) {
44 foreach ($existing_secondary_rows as $existing_secondary)
46 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources
47 WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id'];
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;