2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'../mods/_core/editor/editor_tab_functions.inc.php');
18 if (isset($_GET['cid'])) $cid = intval($_GET['cid']);
19 if (isset($_GET['pid'])) $pid = intval($_GET['pid']);
23 $result = $contentManager->getContentPage($cid);
24 $content_row = mysql_fetch_assoc($result);
27 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
28 $course_base_href = 'get.php/';
30 $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
36 if ($_POST['title'] == '') {
37 $msg->addError(array('EMPTY_FIELDS', _AT('title')));
40 if (!($release_date = generate_release_date())) {
41 $msg->addError('BAD_DATE');
44 if (!$msg->containsErrors())
46 $_POST['title'] = $content_row['title'] = $addslashes($_POST['title']);
49 { // edit existing content
50 $err = $contentManager->editContent($cid,
55 $content_row['formatting'],
58 $content_row['use_customized_head'],
60 $content_row['allow_test_export'],
65 // find out ordering and content_parent_id
67 { // insert sub content folder
68 $ordering = count($contentManager->getContent($pid))+1;
71 { // insert a top content folder
72 $ordering = count($contentManager->getContent(0)) + 1;
76 $cid = $contentManager->addContent($_SESSION['course_id'],
93 $sql = "DELETE FROM ". TABLE_PREFIX . "content_prerequisites
94 WHERE content_id=".$cid." AND type='".CONTENT_PRE_TEST."'";
95 $result = mysql_query($sql, $db);
97 if (is_array($_POST['tid']) && sizeof($_POST['tid']) > 0)
99 foreach ($_POST['tid'] as $i => $tid){
101 $sql = "INSERT INTO ". TABLE_PREFIX . "content_prerequisites
102 SET content_id=".$cid.", type='".CONTENT_PRE_TEST."', item_id=$tid";
103 $result = mysql_query($sql, $db);
105 if ($result===false) $msg->addError('MYSQL_FAILED');
108 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
109 header('Location: '.$_base_path.'mods/_core/editor/edit_content_folder.php?cid='.$cid);
115 { // edit existing content folder
117 $_pages['mods/_core/editor/edit_content_folder.php']['title_var'] = 'missing_content';
118 $_pages['mods/_core/editor/edit_content_folder.php']['parent'] = 'index.php';
119 $_pages['mods/_core/editor/edit_content_folder.php']['ignore'] = true;
121 require(AT_INCLUDE_PATH.'header.inc.php');
123 $msg->addError('PAGE_NOT_FOUND');
126 require (AT_INCLUDE_PATH.'footer.inc.php');
130 /* the "heading navigation": */
131 $path = $contentManager->getContentPath($cid);
133 if ($content_row['content_path']) {
134 $content_base_href = $content_row['content_path'].'/';
137 $parent_headings = '';
138 $num_in_path = count($path);
140 /* the page title: */
142 $page_title .= $content_row['title'];
144 for ($i=0; $i<$num_in_path; $i++) {
145 $content_info = $path[$i];
146 if ($_SESSION['prefs']['PREF_NUMBERING']) {
147 if ($contentManager->_menu_info[$content_info['content_id']]['content_parent_id'] == 0) {
148 $top_num = $contentManager->_menu_info[$content_info['content_id']]['ordering'];
149 $parent_headings .= $top_num;
151 $top_num = $top_num.'.'.$contentManager->_menu_info[$content_info['content_id']]['ordering'];
152 $parent_headings .= $top_num;
154 if ($_SESSION['prefs']['PREF_NUMBERING']) {
155 $path[$i]['content_number'] = $top_num . ' ';
157 $parent_headings .= ' ';
161 if ($_SESSION['prefs']['PREF_NUMBERING']) {
162 if ($top_num != '') {
163 $top_num = $top_num.'.'.$content_row['ordering'];
164 $page_title .= $top_num.' ';
166 $top_num = $content_row['ordering'];
167 $page_title .= $top_num.' ';
172 // foreach ($path as $i=>$page) {
174 // $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['title'] = $page['content_number'] . $page['title'];
175 // $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['parent'] = 'index.php';
177 // $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['title'] = $page['content_number'] . $page['title'];
178 // $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['parent'] = 'editor/edit_content_folder.php?cid='.$parent;
181 // $_pages['editor/edit_content_folder.php?cid='.$page['content_id']]['ignore'] = true;
182 // $parent = $page['content_id'];
184 // $last_page = array_pop($_pages);
185 // $_pages['editor/edit_content_folder.php'] = $last_page;
188 $first_page = current($path);
192 if (isset($top_num) && $top_num != (int) $top_num) {
193 $top_num = substr($top_num, 0, strpos($top_num, '.'));
196 // used by header.inc.php
197 $_tool_shortcuts = $contentManager->getToolShortcuts($content_row);
198 $release_date = $content_row['release_date'];
201 $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$_REQUEST[cid] AND type='".CONTENT_PRE_TEST."'";
202 $result = mysql_query($sql, $db);
203 while ($row = mysql_fetch_assoc($result)) {
204 $_POST['pre_tid'][] = $row['item_id'];
207 $savant->assign('ftitle', $content_row['title']);
208 $savant->assign('shortcuts', $shortcuts);
209 $savant->assign('cid', $cid);
213 // get a list of all the tests we have, and links to create, edit, delete, preview
214 $sql = "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue
215 FROM ".TABLE_PREFIX."tests
216 WHERE course_id=$_SESSION[course_id]
217 ORDER BY start_date DESC";
218 $result = mysql_query($sql, $db);
219 $num_tests = mysql_num_rows($result);
222 while($row = mysql_fetch_assoc($result))
224 $results[$i]['test_id'] = $row['test_id'];
225 $results[$i]['title'] = $row['title'];
227 if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
228 $results[$i]['status'] = '<strong>'._AT('ongoing').'</strong>';
229 } else if ($row['ue'] < time() ) {
230 $results[$i]['status'] = '<strong>'._AT('expired').'</strong>';
231 } else if ($row['us'] > time() ) {
232 $results[$i]['status'] = '<strong>'._AT('pending').'</strong>';
235 $startend_date_format=_AT('startend_date_format');
237 $results[$i]['availability'] = AT_date($startend_date_format, $row['start_date'], AT_DATE_MYSQL_DATETIME). ' ' ._AT('to_2').' ';
238 $results[$i]['availability'] .= AT_date($startend_date_format, $row['end_date'], AT_DATE_MYSQL_DATETIME);
240 // get result release
241 if ($row['result_release'] == AT_RELEASE_IMMEDIATE)
242 $results[$i]['result_release'] = _AT('release_immediate');
243 else if ($row['result_release'] == AT_RELEASE_MARKED)
244 $results[$i]['result_release'] = _AT('release_marked');
245 else if ($row['result_release'] == AT_RELEASE_NEVER)
246 $results[$i]['result_release'] = _AT('release_never');
248 //get # marked submissions
249 $sql_sub = "SELECT COUNT(*) AS sub_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id'];
250 $result_sub = mysql_query($sql_sub, $db);
251 $row_sub = mysql_fetch_assoc($result_sub);
252 $results[$i]['submissions'] = $row_sub['sub_cnt'].' '._AT('submissions').', ';
255 $sql_sub = "SELECT COUNT(*) AS marked_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id']." AND final_score=''";
256 $result_sub = mysql_query($sql_sub, $db);
257 $row_sub = mysql_fetch_assoc($result_sub);
258 $results[$i]['submissions'] .= $row_sub['marked_cnt'].' '._AT('unmarked');
260 //get assigned groups
261 $sql_sub = "SELECT G.title FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."tests_groups T USING (group_id) WHERE T.test_id=".$row['test_id'];
262 $result_sub = mysql_query($sql_sub, $db);
263 if (mysql_num_rows($result_sub) == 0) {
264 $results[$i]['assign_to'] = _AT('everyone');
266 $row_sub = mysql_fetch_assoc($result_sub);
267 $results[$i]['assign_to'] = $row_sub['title'];
269 $results[$i]['assign_to'] .= ', '.$row_sub['title'];
270 } while ($row_sub = mysql_fetch_assoc($result_sub));
273 if ($row['passscore'] == 0 && $row['passpercent'] == 0)
274 $results[$i]['pass_score'] = _AT('no_pass_score');
275 else if ($row['passscore'] <> 0)
276 $results[$i]['pass_score'] = $row['passscore'];
277 else if ($row['passpercent'] <> 0)
278 $results[$i]['pass_score'] = $row['passpercent'].'%';
283 if (isset($results)) $savant->assign('pretests', $results);
286 if (!isset($release_date)) $release_date = date('Y-m-d H:i:s');
288 $_POST['day'] = substr($release_date, 8, 2);
289 $_POST['month'] = substr($release_date, 5, 2);
290 $_POST['year'] = substr($release_date, 0, 4);
291 $_POST['hour'] = substr($release_date, 11, 2);
292 $_POST['min']= substr($release_date, 14, 2);
294 if ($pid > 0) $savant->assign('pid', $pid);
296 require(AT_INCLUDE_PATH.'header.inc.php');
297 $savant->display('editor/edit_content_folder.tmpl.php');
298 require(AT_INCLUDE_PATH.'footer.inc.php');
300 //save last visit page.
301 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];