moved code up one level to eliminate the docs subdirectory
[acontent.git] / home / editor / remove_alternative.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
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
13 /**
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
17  * @var $_POST values: 
18  *      pid: primary resource id
19  *      a_type: alternative type, must be one of the values in resource_types.type_id
20  */
21
22 define('TR_INCLUDE_PATH', '../../include/');
23 require (TR_INCLUDE_PATH.'vitals.inc.php');
24
25 $pid = intval($_POST['pid']);
26 $type_id = intval($_POST['a_type']);
27
28 // check post vars
29 if ($pid == 0 || $type_id == 0) exit;
30
31 require_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
32 $dao = new DAO();
33
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);
42
43 if (is_array($existing_secondary_rows)) {
44         foreach ($existing_secondary_rows as $existing_secondary)
45         {
46                 $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources 
47                          WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id'];
48                 $dao->execute($sql);
49         
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                 $dao->execute($sql);
54         }
55 }
56
57 exit;
58
59 ?>