moved code up one level to eliminate the docs subdirectory
[acontent.git] / home / editor / edit_content_folder.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 define('TR_INCLUDE_PATH', '../../include/');
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'../home/editor/editor_tab_functions.inc.php');
16 require_once(TR_INCLUDE_PATH.'../home/classes/ContentUtility.class.php');
17
18 global $_content_id, $_content_id, $contentManager, $_course_id;
19 $cid = $_content_id;
20
21 Utility::authenticate(TR_PRIV_ISAUTHOR);
22
23 if (isset($_GET['pid'])) $pid = intval($_GET['pid']);
24
25 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
26         $course_base_href = 'get.php/';
27 } else {
28         $course_base_href = 'content/' . $_course_id . '/';
29 }
30
31 if ($cid > 0 && isset($contentManager)) {
32         $content_row = $contentManager->getContentPage($cid);
33 }
34
35 // save changes
36 if ($_POST['submit'])
37 {
38         if ($_POST['title'] == '') {
39                 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
40         }
41                 
42         if (!$msg->containsErrors()) 
43         {
44                 $_POST['title'] = $content_row['title'] = $_POST['title'];
45         
46                 if ($cid > 0)
47                 { // edit existing content
48                         $err = $contentManager->editContent($cid, 
49                                                             $_POST['title'], 
50                                                             '', 
51                                                             '', 
52                                                             $content_row['formatting'], 
53                                                             '', 
54                                                             $content_row['use_customized_head'], 
55                                                             '');
56                 }
57                 else
58                 { // add new content
59                         // find out ordering and content_parent_id
60                         if ($pid)
61                         { // insert sub content folder
62                                 $ordering = count($contentManager->getContent($pid))+1;
63                         }
64                         else
65                         { // insert a top content folder
66                                 $ordering = count($contentManager->getContent(0)) + 1;
67                                 $pid = 0;
68                         }
69                         
70                         $cid = $contentManager->addContent($_SESSION['course_id'],
71                                                            $pid,
72                                                            $ordering,
73                                                            $_POST['title'],
74                                                            '',
75                                                            '',
76                                                            '',
77                                                            0,
78                                                            '',
79                                                            0,
80                                                            '',
81                                                            1,
82                                                            CONTENT_TYPE_FOLDER);
83                 }
84                 
85                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
86                 header('Location: '.$_base_path.'home/editor/edit_content_folder.php?_cid='.$cid);
87                 exit;
88         }
89 }
90
91 if ($cid > 0)
92 { // edit existing content folder
93         if (!$content_row || !isset($contentManager)) {
94                 $_pages['home/editor/edit_content_folder.php']['title_var'] = 'missing_content';
95                 $_pages['home/editor/edit_content_folder.php']['parent']    = 'index.php';
96                 $_pages['home/editor/edit_content_folder.php']['ignore']        = true;
97
98                 require(TR_INCLUDE_PATH.'header.inc.php');
99         
100                 $msg->addError('MISSING_CONTENT');
101                 $msg->printAll();
102         
103                 require (TR_INCLUDE_PATH.'footer.inc.php');
104                 exit;
105         } /* else: */
106         
107         /* the "heading navigation": */
108         $path   = $contentManager->getContentPath($cid);
109         
110         if ($content_row['content_path']) {
111                 $content_base_href = $content_row['content_path'].'/';
112         }
113         
114         $parent_headings = '';
115         $num_in_path = count($path);
116         
117         /* the page title: */
118         $page_title = '';
119         $page_title .= $content_row['title'];
120         
121         for ($i=0; $i<$num_in_path; $i++) {
122                 $content_info = $path[$i];
123                 if ($_SESSION['prefs']['PREF_NUMBERING']) {
124                         if ($contentManager->_menu_info[$content_info['content_id']]['content_parent_id'] == 0) {
125                                 $top_num = $contentManager->_menu_info[$content_info['content_id']]['ordering'];
126                                 $parent_headings .= $top_num;
127                         } else {
128                                 $top_num = $top_num.'.'.$contentManager->_menu_info[$content_info['content_id']]['ordering'];
129                                 $parent_headings .= $top_num;
130                         }
131                         if ($_SESSION['prefs']['PREF_NUMBERING']) {
132                                 $path[$i]['content_number'] = $top_num . ' ';
133                         }
134                         $parent_headings .= ' ';
135                 }
136         }
137         
138         if ($_SESSION['prefs']['PREF_NUMBERING']) {
139                 if ($top_num != '') {
140                         $top_num = $top_num.'.'.$content_row['ordering'];
141                         $page_title .= $top_num.' ';
142                 } else {
143                         $top_num = $content_row['ordering'];
144                         $page_title .= $top_num.' ';
145                 }
146         }
147         
148         $parent = 0;
149 //      foreach ($path as $i=>$page) {
150 //              if (!$parent) {
151 //                      $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['title']    = $page['content_number'] . $page['title'];
152 //                      $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['parent']   = 'index.php';
153 //              } else {
154 //                      $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['title']    = $page['content_number'] . $page['title'];
155 //                      $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['parent']   = 'editor/edit_content_folder.php?cid='.$parent;
156 //              }
157 //      
158 //              $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['ignore'] = true;
159 //              $parent = $page['content_id'];
160 //      }
161 //      $last_page = array_pop($_pages);
162 //      $_pages['editor/edit_content_folder.php'] = $last_page;
163         
164         reset($path);
165         $first_page = current($path);
166         
167         ContentUtility::saveLastCid($cid);
168         
169         if (isset($top_num) && $top_num != (int) $top_num) {
170                 $top_num = substr($top_num, 0, strpos($top_num, '.'));
171         }
172         $_tool_shortcuts = ContentUtility::getToolShortcuts($content_row);  // used by header.tmpl.php
173         
174         // display pre-tests
175 //      $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$_REQUEST[cid] AND type='".CONTENT_PRE_TEST."'";
176 //      $result = mysql_query($sql, $db);
177 //      while ($row = mysql_fetch_assoc($result)) {
178 //              $_POST['pre_tid'][] = $row['item_id'];
179 //      }
180
181         $savant->assign('ftitle', $content_row['title']);
182 //      $savant->assign('shortcuts', $shortcuts);
183         $savant->assign('cid', $cid);
184 }
185
186 if ($pid > 0 || !isset($pid)) {
187         $savant->assign('pid', $pid);
188         $savant->assign('course_id', $_course_id);
189 }
190
191 $onload = "document.form.title.focus();";
192 require(TR_INCLUDE_PATH.'header.inc.php');
193 $savant->display('home/editor/edit_content_folder.tmpl.php');
194 require(TR_INCLUDE_PATH.'footer.inc.php');
195
196 //save last visit page.
197 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
198 ?>