e5d47c66d5ca62f030054445e465840833f22522
[atutor.git] / mods / tle / import.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18 if (!authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN)) {
19         require (AT_INCLUDE_PATH.'html/frameset/header.inc.php'); 
20         $msg->printErrors('TLE_ACCESS_DENIED');
21         require (AT_INCLUDE_PATH.'html/frameset/footer.inc.php'); 
22         exit;
23 }
24
25 if (isset($_POST['submit'])) {
26         $cid = intval($_POST['cid']);
27         $_POST['name'] = stripslashes($addslashes($_POST['name']));
28         $_POST['summary'] = stripslashes($addslashes($_POST['summary']));
29         $_POST['reference'] = stripslashes($addslashes($_POST['reference']));
30
31         $body = '<p>'.nl2br($_POST['summary']).'</p>';
32         $body .= '<p><a href="'.$_POST['reference'].'" target="_new">Open in New Window</a></p>';
33
34         $title = addslashes($_POST['name']);
35         $body = addslashes($body);
36
37         $sql    = "SELECT MAX(ordering) AS ordering FROM ".TABLE_PREFIX."content WHERE course_id=$_SESSION[course_id] AND content_parent_id=$cid";
38         $result = mysql_query($sql, $db);
39         $row    = mysql_fetch_assoc($result);
40         $order  = intval($row['ordering']) + 1;
41
42         $sql= 'INSERT INTO '.TABLE_PREFIX.'content VALUES 
43                                 (0,     '
44                                 .$_SESSION['course_id'].','                                                                                                                     
45                                 .$cid.','               
46                                 .$order.', NOW(),0,1,NOW(),"","", "'.$title.'", "'.$body.'")';
47
48         $result = mysql_query($sql, $db);
49         header('Location: '.$_base_href.'index.php');
50         exit;
51 }
52
53
54 $_REQUEST['framed'] = TRUE;
55 require(AT_INCLUDE_PATH.'header.inc.php');
56
57 if (!isset($_main_menu)) {
58         $_main_menu = $contentManager->getContent();
59 }
60
61 function print_menu_sections(&$menu, $parent_content_id = 0, $depth = 0, $ordering = '') {
62         $my_children = $menu[$parent_content_id];
63         $cid = $_GET['cid'];
64
65         if (!is_array($my_children)) {
66                 return;
67         }
68         foreach ($my_children as $children) {
69                 echo '<option value="'.$children['content_id'].'"';
70                 if ($cid == $children['content_id']) {
71                         echo ' selected="selected"';
72                 }
73                 echo '>';
74                 echo str_pad('', $depth, '-') . ' ';
75                 if ($parent_content_id == 0) {
76                         $new_ordering = $children['ordering'];
77                         echo $children['ordering'];
78                 } else {
79                         $new_ordering = $ordering.'.'.$children['ordering'];
80                         echo $ordering . '.'. $children['ordering'];
81                 }
82                 echo ' '.$children['title'].'</option>';
83
84                 print_menu_sections($menu, $children['content_id'], $depth+1, $new_ordering);
85         }
86 }
87
88
89 ?>
90
91 <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" target="_top">
92         <input type="hidden" name="name" value="<?php echo htmlentities(stripslashes($addslashes($_GET['tlename']))); ?>" />
93         <input type="hidden" name="summary" value="<?php echo htmlentities(stripslashes($addslashes($_GET['tledescription']))); ?>" />
94         <input type="hidden" name="reference" value="<?php echo htmlentities(stripslashes($addslashes($_GET['tleurl']))); ?>?preview=true" />
95
96         <div class="input-form">
97                 <div class="row">
98                         <?php echo _AT('tile_import_content_package_about'); ?>
99                 </div>
100
101                 <div class="row">
102                 <strong><?php echo _AT('import_content_package_where'); ?>:</strong> <select name="cid">
103                                                                 <option value="0"><?php echo _AT('import_content_package_bottom_subcontent'); ?></option>
104                                                                 <option>--------------------------</option>
105                                                                 <?php
106                                                                         print_menu_sections($_main_menu);
107                                                                 ?>
108                                                                 </select>
109                 </div>
110
111                 <div class="row">
112                         <strong><?php echo _AT('import_content_package'); ?>:</strong> <?php echo htmlentities(stripslashes($addslashes($_GET['tlename']))); ?>
113                 </div>
114
115                 <div class="row buttons">
116                         <input type="submit" name="submit" value="<?php echo _AT('import'); ?>" />
117                 </div>
118         </div>
119 </form>
120
121 </body>
122 </html>