35b8a36400239dc86dca33f0dbe8a15c0b05e54d
[atutor.git] / docs / mods / _core / editor / remove_alternative.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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 /****************************************************************/
13
14 /**
15  * This script handles the ajax post submit from "content editor" =? "adpated content"
16  * to remove selected alternative from database
17  * @see mods/_core/editor/editor_tabs/alternatives.inc.php
18  * @var $_POST values: 
19  *      pid: primary resource id
20  *      a_type: alternative type, must be one of the values in resource_types.type_id
21  */
22
23 define('AT_INCLUDE_PATH', '../../../include/');
24 require (AT_INCLUDE_PATH.'vitals.inc.php');
25
26 $pid = intval($_POST['pid']);
27 $type_id = intval($_POST['a_type']);
28
29 // check post vars
30 if ($pid == 0 || $type_id == 0) exit;
31
32 global $db;
33 // delete the existing alternative for this (pid, a_type)
34 $sql = "SELECT sr.secondary_resource_id 
35           FROM ".TABLE_PREFIX."secondary_resources sr, ".TABLE_PREFIX."secondary_resources_types srt
36          WHERE sr.secondary_resource_id = srt.secondary_resource_id
37            AND sr.primary_resource_id = ".$pid."
38            AND sr.language_code = '".$_SESSION['lang']."'
39            AND srt.type_id=".$type_id;
40 $existing_secondary_result = mysql_query($sql, $db);
41
42 while ($existing_secondary = mysql_fetch_assoc($existing_secondary_result))
43 {
44         $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources 
45                  WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id'];
46         $result = mysql_query($sql, $db);
47
48         $sql = "DELETE FROM ".TABLE_PREFIX."secondary_resources_types 
49                  WHERE secondary_resource_id = ".$existing_secondary['secondary_resource_id']."
50                    AND type_id=".$type_id;
51         $result = mysql_query($sql, $db);
52 }
53
54 exit;
55
56 ?>