diff --git a/home/classes/ContentManager.class.php b/home/classes/ContentManager.class.php index ca9a9b1d..8aae2933 100644 --- a/home/classes/ContentManager.class.php +++ b/home/classes/ContentManager.class.php @@ -457,7 +457,8 @@ function & getContentTestsAssoc($content_id){ WHERE content_id=$content_id) AS ct LEFT JOIN ".TABLE_PREFIX."tests t ON ct.test_id=t.test_id ORDER BY t.title"; - return $this->dao->execute($sql); + $result = $this->dao->execute($sql); + return $result; } function & cleanOutput($value) { @@ -574,7 +575,7 @@ function generateSequenceCrumbs($cid) { $first = $this->getNextContent(0); // get first - if ($_SESSION['prefs']['PREF_NUMBERING'] && $first) { + if (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING'] && $first) { $first['title'] = $this->getNumbering($first['content_id']).' '.$first['title']; } if ($first) { @@ -582,10 +583,10 @@ function generateSequenceCrumbs($cid) { $sequence_links['first'] = $first; } - if (!$cid && $_SESSION['s_cid']) { + if (!$cid && array_key_exists('s_cid', $_SESSION) && $_SESSION['s_cid']) { $resume['title'] = $this->_menu_info[$_SESSION['s_cid']]['title']; - if ($_SESSION['prefs']['PREF_NUMBERING']) { + if (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING']) { $resume['title'] = $this->getNumbering($_SESSION['s_cid']).' ' . $resume['title']; } @@ -598,7 +599,7 @@ function generateSequenceCrumbs($cid) { } $next = $this->getNextContent($cid ? $cid : 0); - if ($_SESSION['prefs']['PREF_NUMBERING']) { + if (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING']) { $previous['title'] = $this->getNumbering($previous['content_id']).' '.$previous['title']; $next['title'] = $this->getNumbering($next['content_id']).' '.$next['title']; } @@ -830,9 +831,10 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat if (!isset($temp_path)) { if ($cid) { $temp_path = $this->getContentPath($cid); - } else { + } elseif (array_key_exists('s_cid', $_SESSION)) { $temp_path = $this->getContentPath($_SESSION['s_cid']); - } + } else + $temp_path = array(); } $highlighted = array(); @@ -869,7 +871,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat $on = false; - if ( (($_SESSION['s_cid'] != $content['content_id']) || ($_SESSION['s_cid'] != $cid)) && ($content['content_type'] == CONTENT_TYPE_CONTENT || $content['content_type'] == CONTENT_TYPE_WEBLINK)) + if ( ((array_key_exists('s_cid', $_SESSION) && $_SESSION['s_cid'] != $content['content_id']) || (array_key_exists('s_cid', $_SESSION) && $_SESSION['s_cid'] != $cid)) && ($content['content_type'] == CONTENT_TYPE_CONTENT || $content['content_type'] == CONTENT_TYPE_WEBLINK)) { // non-current content nodes with content type "CONTENT_TYPE_CONTENT" if (isset($highlighted[$content['content_id']])) { $link .= ''; @@ -891,7 +893,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat // $link .= $img_link . ' '. - ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). + (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). $content['title'].''; $link .= ''; @@ -923,7 +925,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat else { // current content page & nodes with content type "CONTENT_TYPE_FOLDER" $base_title_length = 26; - if ($_SESSION['prefs']['PREF_NUMBERING']) { + if (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING']) { $base_title_length = 21; } @@ -936,7 +938,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat { // current content page $full_title = $content['title']; $link .= ''._AT('you_are_here').': '.
-						         ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter : '').
+						         (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter : '').
 						         $content['title'].''."\n"; if ($truncate && ($strlen($content['title']) > ($base_title_length-$depth*4)) ) { @@ -944,7 +946,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat } // $content['title'] = htmlspecialchars(rtrim($substr(htmlspecialchars_decode($content['title']), 0, $base_title_length-4))).'...'; $link .= ''. - ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). + (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). $content['title'].''; // instructors have privilege to delete content @@ -973,7 +975,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat $link .= $content['title']; else $link .= ''. - ($_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). + (array_key_exists('PREF_NUMBERING', $_SESSION['prefs']) && $_SESSION['prefs']['PREF_NUMBERING'] ? $path.$counter.' ' : ''). $content['title'].''; if (isset($_current_user) && $_current_user->isAuthor($this->course_id) && !Utility::isMobileTheme()) { @@ -1023,7 +1025,7 @@ function printMenu($parent_id, $depth, $path, $children, $truncate, $ignore_stat $children[$depth] = 1; } - if ($_SESSION['s_cid'] == $content['content_id']) { + if (array_key_exists('s_cid', $_SESSION) && $_SESSION['s_cid'] == $content['content_id']) { if (is_array($this->_menu[$content['content_id']])) { $_SESSION['menu'][$content['content_id']] = 1; } @@ -1289,4 +1291,4 @@ function printActionMenu($menu, $parent_id, $depth, $path, $children, $print_typ } } -?> \ No newline at end of file +?> diff --git a/home/ims/ims_import.php b/home/ims/ims_import.php index 57ba69c0..dbef6e9f 100644 --- a/home/ims/ims_import.php +++ b/home/ims/ims_import.php @@ -300,56 +300,58 @@ function rehash($items){ $temp_popped_items = array(); $rehashed_items = array(); //the reconstructed array foreach($items as $id => $content){ - $parent_obj = $items[$content['parent_content_id']]; - $rehashed_items[$id] = $content; //copy - if (isset($parent_page_maps[$content['parent_content_id']])){ - $rehashed_items [$id]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; - $rehashed_items [$id]['ordering']++; - } - //If its parent page is a top page and have an identiferref - elseif (isset($parent_obj) && isset($parent_obj['href'])){ - if (!isset($parent_obj['href'])){ - //check if this top page is already a folder, if so, next. - continue; - } - //else, make its parent page to a folder - $new_item['title'] = $parent_obj['title']; - //check if this parent has been modified, if so, chnage it - if (isset($parent_page_maps[$parent_obj['parent_content_id']])){ - $new_item['parent_content_id'] = $parent_page_maps[$parent_obj['parent_content_id']]; - } else { - $new_item['parent_content_id'] = $parent_obj['parent_content_id']; - } - //all ordering needs to be +1 because we are creating a new folder on top of - //everything, except the first page. - $new_item['ordering'] = $parent_obj['ordering']; - if ($new_item['parent_content_id']!='0'){ - $new_item['ordering']++; + if (isset($content['parent_content_id'])) { + $parent_obj = $items[$content['parent_content_id']]; + $rehashed_items[$id] = $content; //copy + if (isset($parent_page_maps[$content['parent_content_id']])){ + $rehashed_items [$id]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; + $rehashed_items [$id]['ordering']++; } + //If its parent page is a top page and have an identiferref + elseif (isset($parent_obj) && isset($parent_obj['href'])){ + if (!isset($parent_obj['href'])){ + //check if this top page is already a folder, if so, next. + continue; + } + //else, make its parent page to a folder + $new_item['title'] = $parent_obj['title']; + //check if this parent has been modified, if so, chnage it + if (isset($parent_page_maps[$parent_obj['parent_content_id']])){ + $new_item['parent_content_id'] = $parent_page_maps[$parent_obj['parent_content_id']]; + } else { + $new_item['parent_content_id'] = $parent_obj['parent_content_id']; + } + //all ordering needs to be +1 because we are creating a new folder on top of + //everything, except the first page. + $new_item['ordering'] = $parent_obj['ordering']; + if ($new_item['parent_content_id']!='0'){ + $new_item['ordering']++; + } + + //assign this new parent folder to the pending items array + $new_item_name = $content['parent_content_id'].'_FOLDER'; + //a not so brilliant way to append the folder in its appropriate position + $reordered_hashed_items = array(); //use to store the new rehashed item with the correct item order + foreach($rehashed_items as $rh_id=>$rh_content){ + if ($rh_id == $content['parent_content_id']){ + //add the folder in before the parent subpage. + $reordered_hashed_items[$new_item_name] = $new_item; + } + $reordered_hashed_items[$rh_id] = $rh_content; //clone + } + $rehashed_items = $reordered_hashed_items; //replace it back + unset($reordered_hashed_items); + $parent_page_maps[$content['parent_content_id']] = $new_item_name; //save this page on the hash map - //assign this new parent folder to the pending items array - $new_item_name = $content['parent_content_id'].'_FOLDER'; - //a not so brilliant way to append the folder in its appropriate position - $reordered_hashed_items = array(); //use to store the new rehashed item with the correct item order - foreach($rehashed_items as $rh_id=>$rh_content){ - if ($rh_id == $content['parent_content_id']){ - //add the folder in before the parent subpage. - $reordered_hashed_items[$new_item_name] = $new_item; - } - $reordered_hashed_items[$rh_id] = $rh_content; //clone - } - $rehashed_items = $reordered_hashed_items; //replace it back - unset($reordered_hashed_items); - $parent_page_maps[$content['parent_content_id']] = $new_item_name; //save this page on the hash map - - //reconstruct the parent - $rehashed_items[$content['parent_content_id']]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; - $rehashed_items[$content['parent_content_id']]['ordering'] = 0; //always the first one. + //reconstruct the parent + $rehashed_items[$content['parent_content_id']]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; + $rehashed_items[$content['parent_content_id']]['ordering'] = 0; //always the first one. - //reconstruct itself - $rehashed_items[$id]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; - $rehashed_items[$id]['ordering']++; + //reconstruct itself + $rehashed_items[$id]['parent_content_id'] = $parent_page_maps[$content['parent_content_id']]; + $rehashed_items[$id]['ordering']++; + } } } return $rehashed_items; @@ -361,7 +363,7 @@ function rehash($items){ * @param array contains the breakdown of all resources in the XML */ function removeCommonPath($items){ - $common_path; + $common_path = ''; $quit = false; //a flag that is set if it's not the first time being run. $filearray = array(); @@ -714,7 +716,7 @@ function characterData($parser, $data){ global $current_identifier; $str_trimmed_data = trim($data); - + if (!empty($str_trimmed_data)) { $size = count($path); if ($size > 0) { @@ -725,8 +727,7 @@ function characterData($parser, $data){ $parent_item_id = 0; } - if (isset($items[$current_item_id]['parent_content_id']) && is_array($items[$current_item_id])) { - + if (array_key_exists($current_item_id, $items) && is_array($items[$current_item_id]) && isset($items[$current_item_id]['parent_content_id'])) { /* this item already exists, append the title */ /* this fixes {\n, \t, `, &} characters in elements */ @@ -739,12 +740,16 @@ function characterData($parser, $data){ } } else { - $order[$parent_item_id] ++; + if (array_key_exists($parent_item_id, $order)) + $order[$parent_item_id] ++; + else + $order[$parent_item_id] = 1; + $item_tmpl = array( 'title' => $data, 'parent_content_id' => $parent_item_id, 'ordering' => $order[$parent_item_id]-1); //append other array values if it exists - if (is_array($items[$current_item_id])){ + if (array_key_exists($current_item_id, $items) && is_array($items[$current_item_id])){ $items[$current_item_id] = array_merge($items[$current_item_id], $item_tmpl); } else { $items[$current_item_id] = $item_tmpl; @@ -832,7 +837,7 @@ function glossaryCharacterData($parser, $data){ $package_base_name_url = md5(time()); } $ext = pathinfo($_FILES['file']['name']); -$ext = $ext['extension']; +$ext = array_key_exists('extension', $ext) ? $ext['extension'] : ''; if ($ext != 'zip') { $msg->addError('IMPORTDIR_IMS_NOTVALID'); @@ -853,7 +858,7 @@ function glossaryCharacterData($parser, $data){ } else { header('Location: '.$_SERVER['HTTP_REFERER']); } - if (file_exists($full_filename)) @unlink($full_filename); + if (isset($full_filename) && file_exists($full_filename)) @unlink($full_filename); exit; } @@ -992,6 +997,8 @@ function glossaryCharacterData($parser, $data){ } xml_parser_free($xml_parser); +$contains_glossary_terms = false; + // Check if all the files exists in the manifest, iff it's a IMS CC package. if ($content_type == 'IMS Common Cartridge') { checkResources($import_path); @@ -1044,9 +1051,9 @@ function glossaryCharacterData($parser, $data){ /* the package name will be the dir where the content for this package will be put, as a result */ /* the 'content_path' field in the content table will be set to this path. */ /* $package_base_name_url comes from the URL file name (NOT the file name of the actual file we open)*/ -if (!$package_base_name && $package_base_name_url) { +if (!isset($package_base_name) && isset($package_base_name_url)) { $package_base_name = substr($package_base_name_url, -6); -} else if (!$package_base_name) { +} else if (!isset($package_base_name)) { $package_base_name = substr($_FILES['file']['name'], 0, -4); } @@ -1082,17 +1089,18 @@ function glossaryCharacterData($parser, $data){ $items = rehash($items); //debug($items);exit; foreach ($items as $item_id => $content_info) -{ +{ //formatting field, default 1 $content_formatting = 1; //CONTENT_TYPE_CONTENT + $lti_offset[$content_info['parent_content_id']] = 0; //don't want to display glossary as a page - if ($content_info['href']== $glossary_path . 'glossary.xml'){ + if (isset($content_info['href']) && $content_info['href'] == 'glossary.xml'){ continue; } //if discussion tools, add it to the list of unhandled dts - if ($content_info['type']=='imsdt_xmlv1p0'){ + if (isset($content_info['type']) && $content_info['type'] == 'imsdt_xmlv1p0'){ //if it will be taken care after (has dependency), then move along. if (in_array($item_id, $avail_dt)){ $lti_offset[$content_info['parent_content_id']]++; @@ -1116,14 +1124,14 @@ function glossaryCharacterData($parser, $data){ //check dependency immediately, then handles it $head = ''; - if (is_array($content_info['dependency']) && !empty($content_info['dependency'])){ + if (isset($content_info['dependency']) && is_array($content_info['dependency']) && !empty($content_info['dependency'])){ foreach($content_info['dependency'] as $dependency_ref){ //check if this is a discussion tool dependency - if ($items[$dependency_ref]['type']=='imsdt_xmlv1p0'){ + if (array_key_exists($dependency_ref, $items) && $items[$dependency_ref]['type']=='imsdt_xmlv1p0'){ $items[$item_id]['forum'][$dependency_ref] = $items[$dependency_ref]['href']; } //check if this is a QTI dependency - if (strpos($items[$dependency_ref]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){ + if (array_key_exists($dependency_ref, $items) && strpos($items[$dependency_ref]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){ $items[$item_id]['tests'][$dependency_ref] = $items[$dependency_ref]['href']; } } @@ -1131,7 +1139,7 @@ function glossaryCharacterData($parser, $data){ // remote href - if (preg_match('/^http.*:\/\//', trim($content_info['href'])) ) + if (isset($content_info['href']) && preg_match('/^http.*:\/\//', trim($content_info['href'])) ) { $content = ''.$content_info['title'].''; } @@ -1140,7 +1148,7 @@ function glossaryCharacterData($parser, $data){ if ($content_type == 'IMS Common Cartridge'){ //to handle import with purely images but nothing else //don't need a content base path for it. - $content_new_path = $content_info['new_path']; + $content_new_path = isset($content_info['new_path']) ? $content_info['new_path'] : ''; $content_info['new_path'] = ''; } if (isset($content_info['href'], $xml_base_path)) { @@ -1252,7 +1260,7 @@ function glossaryCharacterData($parser, $data){ } $content_parent_id = $cid; if ($content_info['parent_content_id'] !== 0) { - $content_parent_id = $items[$content_info['parent_content_id']]['real_content_id']; + $content_parent_id = isset($items[$content_info['parent_content_id']]) ? $items[$content_info['parent_content_id']]['real_content_id'] : 0; //if it's not there, use $cid if (!$content_parent_id){ $content_parent_id = $cid; @@ -1282,20 +1290,21 @@ function glossaryCharacterData($parser, $data){ } //handles weblinks - if ($content_info['type']=='imswl_xmlv1p0'){ + if (isset($content_info['type']) && $content_info['type']=='imswl_xmlv1p0'){ $weblinks_parser = new WeblinksParser(); - $xml_content = @file_get_contents($import_path . $content_info['href']); - $weblinks_parser->parse($xml_content); - $content_info['title'] = $weblinks_parser->getTitle(); - $content = $weblinks_parser->getUrl(); - $content_folder_type = CONTENT_TYPE_WEBLINK; - $content_formatting = 2; + $xml_content = @file_get_contents($import_path . $content_info['file'][0]); + if ($weblinks_parser->parse($xml_content)) { + $content_info['title'] = $weblinks_parser->getTitle(); + $content = $weblinks_parser->getUrl(); + $content_folder_type = CONTENT_TYPE_WEBLINK; + $content_formatting = 2; + } } //if this file is a test_xml, create a blank page instead, for imscc. - if (preg_match('/((.*)\/)*tests\_[0-9]+\.xml$/', $content_info['href']) - || preg_match('/imsqti\_(.*)/', $content_info['type'])) { + if ((isset($content_info['href']) && preg_match('/((.*)\/)*tests\_[0-9]+\.xml$/', $content_info['href'])) + || (isset($content_info['type']) && preg_match('/imsqti\_(.*)/', $content_info['type']))) { $content = ' '; } @@ -1304,15 +1313,17 @@ function glossaryCharacterData($parser, $data){ if ($content_formatting!=CONTENT_TYPE_WEBLINK){ $content_folder_type = (!isset($content_info['type'])?CONTENT_TYPE_FOLDER:CONTENT_TYPE_CONTENT); } - - $items[$item_id]['real_content_id'] = $contentDAO->Create($_course_id, intval($content_parent_id), - ($content_info['ordering'] + $my_offset - $lti_offset[$content_info['parent_content_id']] + 1), - 0, $content_formatting, "", $content_info['new_path'], $content_info['title'], - $content, $head, 1, $content_info['test_message'], $content_folder_type); - - + $result = $contentDAO->Create($_course_id, intval($content_parent_id), + ($content_info['ordering'] + $my_offset - (array_key_exists($content_info['parent_content_id'], $lti_offset) ? $lti_offset[$content_info['parent_content_id']] : 0) + 1), + 0, $content_formatting, "", $content_info['new_path'], $content_info['title'], + $content, $head, 1, array_key_exists('test_message',$content_info) ? $content_info['test_message'] : '', $content_folder_type); + if ($result) + $items[$item_id]['real_content_id'] = $result; + else { + $msg->addError(array('IMPORT_CARTRIDGE_FAILED', 'course_id='.$_course_id.', $item_id='.$item_id.', $content_parent_id='.$content_parent_id.', title="'.$content_info['title'].'"'."\n")); + } /* get the tests associated with this content */ - if (!empty($items[$item_id]['tests']) || strpos($items[$item_id]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false){ + if (!empty($items[$item_id]['tests']) || (isset($items[$item_id]['type']) && strpos($items[$item_id]['type'], 'imsqti_xmlv1p2/imscc_xmlv1p0') !== false)){ $qti_import = new QTIImport($import_path); if (isset($items[$item_id]['tests'])){ $loop_var = $items[$item_id]['tests']; @@ -1380,7 +1391,7 @@ function glossaryCharacterData($parser, $data){ } } - } elseif ($items[$item_id]['type']=='imsdt_xmlv1p0'){ + } elseif (isset($items[$item_id]['type']) && $items[$item_id]['type']=='imsdt_xmlv1p0'){ //optimize this, repeated codes as above $dt_parser = new DiscussionToolsParser(); $dt_import = new DiscussionToolsImport(); @@ -1445,4 +1456,4 @@ function glossaryCharacterData($parser, $data){ } exit; -?> \ No newline at end of file +?> diff --git a/home/index.php b/home/index.php index 2918c649..33e1bd4c 100644 --- a/home/index.php +++ b/home/index.php @@ -43,6 +43,7 @@ // $is_my_courses = true; //} +$is_for_category = false; if (isset($catid)) { $courses = $coursesDAO->getByCategory($catid); $is_for_category = true; @@ -52,7 +53,7 @@ require(TR_INCLUDE_PATH.'header.inc.php'); -$curr_page_num = intval($_GET['p']); +$curr_page_num = intval(isset($_GET['p']) ? $_GET['p'] : 0); if (!$curr_page_num) { $curr_page_num = 1; } @@ -68,4 +69,4 @@ $savant->display('home/index_course.tmpl.php'); require(TR_INCLUDE_PATH.'footer.inc.php'); -?> \ No newline at end of file +?> diff --git a/include/classes/DAO/ContentDAO.class.php b/include/classes/DAO/ContentDAO.class.php index af77fe32..7112966e 100644 --- a/include/classes/DAO/ContentDAO.class.php +++ b/include/classes/DAO/ContentDAO.class.php @@ -269,6 +269,7 @@ public function getMaxOrdering($course_id, $content_parent_id) private function isFieldsValid($action_type, $row_id, $title) { global $msg; + $result = true; $missing_fields = array(); @@ -284,15 +285,12 @@ private function isFieldsValid($action_type, $row_id, $title) if ($missing_fields) { - $missing_fields = implode(', ', $missing_fields); - $msg->addError(array('EMPTY_FIELDS', $missing_fields)); + $msg->addError(array('EMPTY_FIELDS', implode(', ', $missing_fields))); + $result = false; } - if (!$msg->containsErrors()) - return true; - else - return false; + return $result; } } -?> \ No newline at end of file +?> diff --git a/include/classes/DAO/DAO.class.php b/include/classes/DAO/DAO.class.php index 905a4b32..32228f7d 100644 --- a/include/classes/DAO/DAO.class.php +++ b/include/classes/DAO/DAO.class.php @@ -25,13 +25,13 @@ class DAO { function DAO() { - if (!isset($this->db)) + if (!isset(DAO::$db)) { - $this->db = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD); - if (!$this->db) { + DAO::$db = @mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASSWORD); + if (!DAO::$db) { die('Unable to connect to db.'); } - if (!@mysql_select_db(DB_NAME, $this->db)) { + if (!@mysql_select_db(DB_NAME, DAO::$db)) { die('DB connection established, but database "'.DB_NAME.'" cannot be selected.'); } } @@ -49,7 +49,7 @@ function DAO() function execute($sql) { $sql = trim($sql); - $result = mysql_query($sql, $this->db) or die($sql . "
". mysql_error()); + $result = mysql_query($sql, DAO::$db) or die($sql . "
". mysql_error()); // for 'select' SQL, return retrieved rows if (strtolower(substr($sql, 0, 6)) == 'select') @@ -71,4 +71,4 @@ function execute($sql) } } -?> \ No newline at end of file +?> diff --git a/include/classes/Menu.class.php b/include/classes/Menu.class.php index 17f82732..aff6766f 100644 --- a/include/classes/Menu.class.php +++ b/include/classes/Menu.class.php @@ -122,7 +122,7 @@ private function setTopPages() // replace the required constants in link $row['link'] = Utility::replaceConstants($row['link']); list($url, $param) = Utility::separateURLAndParam($row['link']); - if (Utility::authenticate($row['user_requirement'], false)) { + if (Utility::authenticate(array_key_exists('user_requirement', $row) ? $row['user_requirement'] : NULL, false)) { $this->pages[TR_NAV_TOP][] = array('url' => $_base_path.$row['link'], 'title' => _AT($row['title_var']), 'param' => $param); @@ -483,4 +483,4 @@ private function getParam($page) return $this->getParam($this->pages[$page]['parent']); } } -?> \ No newline at end of file +?> diff --git a/include/classes/Utility.class.php b/include/classes/Utility.class.php index 5c451fb8..8de59ff9 100644 --- a/include/classes/Utility.class.php +++ b/include/classes/Utility.class.php @@ -303,7 +303,8 @@ public static function separateURLAndParam($str) public static function getRefererURLAndParams() { $caller_url_parts = explode('/', $_SERVER['PHP_SELF']); $caller_script = $caller_url_parts[count($caller_url_parts)-1]; - + $url_param = ''; + if (count($_GET) > 0) { foreach ($_GET as $param => $value) @@ -311,14 +312,13 @@ public static function getRefererURLAndParams() { if ($param == 'action' || $param == 'cid') continue; else - $url_param .= $param.'='.urlencode($value).'&'; + $url_param .= ($url_param != '' ? '&' : '').$param.'='.urlencode($value); } } - $caller_url = $caller_script. '?'.(isset($url_param) ? $url_param : ''); - $url_param = substr($url_param, 0, -1); + $caller_url = $caller_script. '?'.$url_param; return array($caller_url, $url_param); } } -?> \ No newline at end of file +?> diff --git a/include/classes/Weblinks/WeblinksParser.class.php b/include/classes/Weblinks/WeblinksParser.class.php index 8e0a0047..544f2359 100644 --- a/include/classes/Weblinks/WeblinksParser.class.php +++ b/include/classes/Weblinks/WeblinksParser.class.php @@ -40,9 +40,11 @@ function WeblinksParser() { // public // @return true if parsed successfully, false otherwise function parse($xml_data) { + $result = false; $this->element_path = array(); $this->character_data = ''; - xml_parse($this->parser, $xml_data, TRUE); + $result = xml_parse($this->parser, $xml_data, TRUE); + return $result; } // private @@ -62,7 +64,6 @@ function startElement($parser, $name, $attributes) { function endElement($parser, $name) { //check element path $current_pos = count($this->element_path) - 1; - $last_element = $this->element_path[$current_pos - 1]; switch($name) { case 'title': diff --git a/include/page_constants.inc.php b/include/page_constants.inc.php index 141fbbe4..5213a52e 100644 --- a/include/page_constants.inc.php +++ b/include/page_constants.inc.php @@ -60,9 +60,9 @@ $rows = $priviledgesDAO->getPublicPrivileges(); } -foreach ($rows as $row) - $privs[$row['privilege_id']] = $row['user_requirement']; - +foreach ($rows as $row) { + $privs[$row['privilege_id']] = array_key_exists('user_requirement', $row) ? $row['user_requirement'] : NULL; +} /* initialize pages accessed by public */ //$_pages[TR_NAV_PUBLIC] = array('index.php' => array('parent'=>TR_NAV_PUBLIC)); diff --git a/include/sidemenus/category.inc.php b/include/sidemenus/category.inc.php index 644e0a53..2adc162a 100644 --- a/include/sidemenus/category.inc.php +++ b/include/sidemenus/category.inc.php @@ -37,7 +37,7 @@ foreach ($categories as $category) { $output .= ''; - if ($_GET['catid'] <> '' && $_GET['catid'] == $category['category_id']) { + if (isset($_GET['catid']) && $_GET['catid'] <> '' && $_GET['catid'] == $category['category_id']) { $output .= ''; } $output .= $category['category_name'].' '; @@ -47,7 +47,7 @@ else { $output .= '(0)'; } - if ($_GET['catid'] <> '' && $_GET['catid'] == $category['category_id']) { + if (isset($_GET['catid']) && $_GET['catid'] <> '' && $_GET['catid'] == $category['category_id']) { $output .= ''; } $output .= '
'; @@ -58,12 +58,12 @@ if (isset($course_num_summary[0])) { $output .= ''; - if ($_GET['catid'] <> '' && $_GET['catid'] == 0) { + if (isset($_GET['catid']) && $_GET['catid'] <> '' && $_GET['catid'] == 0) { $output .= ''; } $output .= _AT('cats_uncategorized').' ('.$course_num_summary[0].')'; - if ($_GET['catid'] <> '' && $_GET['catid'] == 0) { + if (isset($_GET['catid']) && $_GET['catid'] <> '' && $_GET['catid'] == 0) { $output .= ''; } $output .= '
'; diff --git a/include/vitals.inc.php b/include/vitals.inc.php index ab4ed7ee..33b41e6a 100644 --- a/include/vitals.inc.php +++ b/include/vitals.inc.php @@ -13,7 +13,7 @@ if (!defined('TR_INCLUDE_PATH')) { exit; } define('TR_DEVEL', 1); -define('TR_ERROR_REPORTING', E_ALL ^ E_NOTICE); // default is E_ALL ^ E_NOTICE, use E_ALL or E_ALL + E_STRICT for developing +define('TR_ERROR_REPORTING', E_ALL + E_STRICT); // default is E_ALL ^ E_NOTICE, use E_ALL or E_ALL + E_STRICT for developing // Emulate register_globals off. src: http://php.net/manual/en/faq.misc.php#faq.misc.registerglobals function unregister_GLOBALS() { @@ -150,7 +150,8 @@ function unregister_GLOBALS() { // set default template paths: $savant = new Savant2(); - if (isset($_SESSION['prefs']['PREF_THEME']) && file_exists(TR_INCLUDE_PATH . '../themes/' . $_SESSION['prefs']['PREF_THEME']) && $_SESSION['user_id']>0) + if (isset($_SESSION['prefs']['PREF_THEME']) && file_exists(TR_INCLUDE_PATH . '../themes/' . $_SESSION['prefs']['PREF_THEME']) + && isset($_SESSION['user_id']) && $_SESSION['user_id']>0) { if (!is_dir(TR_INCLUDE_PATH . '../themes/' . $_SESSION['prefs']['PREF_THEME'])) { @@ -239,14 +240,14 @@ function unregister_GLOBALS() { if ($user_courses_row && $user_courses_row['last_cid'] > 0) $_SESSION['s_cid'] = $user_courses_row['last_cid']; - else if ($_content_id > 0) + else if (isset($_content_id) && $_content_id > 0) $_SESSION['s_cid'] = $_content_id; else // first time accessing this course, no last cid yet unset($_SESSION['s_cid']); } else // guest { - $_SESSION['s_cid'] = $_content_id; + if (isset($_content_id)) $_SESSION['s_cid'] = $_content_id; } } @@ -259,7 +260,7 @@ function unregister_GLOBALS() { include_once(TR_INCLUDE_PATH. '../home/classes/ContentManager.class.php'); $contentManager = new ContentManager($_course_id); - $_sequence_links = $contentManager->generateSequenceCrumbs($_content_id); + $_sequence_links = isset($_content_id) ? $contentManager->generateSequenceCrumbs($_content_id) : NULL; } /*** 10. register pages based on user's priviledge ***/ @@ -270,11 +271,11 @@ function unregister_GLOBALS() { $_SESSION['flash'] = $_COOKIE["flash"]; //delete the cookie - AContent.setcookie("flash",'',time()-3600); + setcookie("flash",'',time()-3600); } if (!isset($_SESSION["flash"])) { - $_custom_head .= ' + $_custom_head = ' - + @@ -92,7 +93,7 @@ custom_css; ?> - +
@@ -100,7 +101,7 @@ <?php echo _AT('goto_content'); ?> ALT+c - <?php echo _AT('goto_menu'); ?> ALT+m + <?php echo _AT('goto_menu'); ?> ALT+m user_name)) @@ -203,13 +204,13 @@ - sub_level_pages) > 0): ?> + sub_level_pages) && count($this->sub_level_pages) > 0): ?>