From c2bf8d9fb46c6bf6b1c6edd2b380ade4a78ca608 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 17 Jul 2012 19:06:34 +0200 Subject: [PATCH 01/36] Minor cosmetic changes --- .../lib/formvalidator/Element/html_editor.php | 225 +++++++++--------- 1 file changed, 112 insertions(+), 113 deletions(-) mode change 100755 => 100644 main/inc/lib/formvalidator/Element/html_editor.php diff --git a/main/inc/lib/formvalidator/Element/html_editor.php b/main/inc/lib/formvalidator/Element/html_editor.php old mode 100755 new mode 100644 index 69fcb1f1c3..0b73953b8b --- a/main/inc/lib/formvalidator/Element/html_editor.php +++ b/main/inc/lib/formvalidator/Element/html_editor.php @@ -1,120 +1,119 @@ _persistantFreeze = true; - $this->_type = 'html_editor'; - $this->fullPage = false; - - $name = $this->getAttribute('name'); - $this -> fck_editor = new FCKeditor($name); - - $this->fck_editor->ToolbarSet = $fck_attribute['ToolbarSet'] ; - $this -> fck_editor->Width = !empty($fck_attribute['Width']) ? $fck_attribute['Width'] : '990'; - $this -> fck_editor->Height = !empty($fck_attribute['Height']) ? $fck_attribute['Height'] : '400'; - //We get the optionnals config parameters in $fck_attribute array - $this -> fck_editor->Config = !empty($fck_attribute['Config']) ? $fck_attribute['Config'] : array(); - - // This is an alternative (a better) way to pass configuration data to the editor. - if (is_array($config)) { - foreach ($config as $key => $value) { - $this->fck_editor->Config[$key] = $config[$key]; - } - if (isset($config['ToolbarSet'])) { - $this->fck_editor->ToolbarSet = $config['ToolbarSet']; - } - if (isset($config['Width'])) { - $this->fck_editor->Width = $config['Width']; - } - if (isset($config['Height'])) { - $this->fck_editor->Height = $config['Height']; - } - if (isset($config['FullPage'])) { - $this->fullPage = is_bool($config['FullPage']) ? $config['FullPage'] : ($config['FullPage'] === 'true'); - } - } - } - - /** - * Check if the browser supports FCKeditor - * - * @access public - * @return boolean - */ - function browserSupported() - { - return FCKeditor :: IsCompatible(); - } - /** - * Return the HTML editor in HTML - * @return string - */ - function toHtml() - { - $value = $this->getValue(); - if ($this->fullPage) { - - if (strlen(trim($value)) == 0) { - // TODO: To be considered whether here to be added DOCTYPE, language and character set declarations. - $value = ''; - $this->setValue($value); - } - } - if ($this->_flagFrozen) { - return $this->getFrozenHtml(); - } else { - return $this->build_FCKeditor(); - } - - } - /** - * Returns the htmlarea content in HTML - *@return string - */ - function getFrozenHtml() - { - return $this->getValue(); - } - /** - * Build this element using FCKeditor - */ - function build_FCKeditor() - { - $result = ''; - if(! FCKeditor :: IsCompatible()) - { - return parent::toHTML(); - } - $this->fck_editor->Value= $this->getValue(); - $result .= $this->fck_editor->CreateHtml(); - - //Add a link to open the allowed html tags window - //$result .= ''.get_lang('AllowedHTMLTags').''; - return $result; - } + * A html editor field to use with QuickForm + */ +class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea { + + /** + * Full page + */ + var $fullPage; + var $fck_editor; + + /** + * Class constructor + * @param string HTML editor name/id + * @param string HTML editor label + * @param string Attributes for the textarea + * @param array $editor_config Optional configuration settings for the online editor. + */ + function HTML_QuickForm_html_editor($elementName = null, $elementLabel = null, $attributes = null, $config = null) { + // The global variable $fck_attribute has been deprecated. It stays here for supporting old external code. + global $fck_attribute; + + HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes); + $this->_persistantFreeze = true; + $this->_type = 'html_editor'; + $this->fullPage = false; + + $name = $this->getAttribute('name'); + $this->fck_editor = new FCKeditor($name); + + $this->fck_editor->ToolbarSet = $fck_attribute['ToolbarSet']; + $this->fck_editor->Width = !empty($fck_attribute['Width']) ? $fck_attribute['Width'] : '990'; + $this->fck_editor->Height = !empty($fck_attribute['Height']) ? $fck_attribute['Height'] : '400'; + //We get the optionnals config parameters in $fck_attribute array + $this->fck_editor->Config = !empty($fck_attribute['Config']) ? $fck_attribute['Config'] : array(); + + // This is an alternative (a better) way to pass configuration data to the editor. + if (is_array($config)) { + foreach ($config as $key => $value) { + $this->fck_editor->Config[$key] = $config[$key]; + } + if (isset($config['ToolbarSet'])) { + $this->fck_editor->ToolbarSet = $config['ToolbarSet']; + } + if (isset($config['Width'])) { + $this->fck_editor->Width = $config['Width']; + } + if (isset($config['Height'])) { + $this->fck_editor->Height = $config['Height']; + } + if (isset($config['FullPage'])) { + $this->fullPage = is_bool($config['FullPage']) ? $config['FullPage'] : ($config['FullPage'] === 'true'); + } + } + } + + /** + * Check if the browser supports FCKeditor + * + * @access public + * @return boolean + */ + function browserSupported() { + return FCKeditor :: IsCompatible(); + } + + /** + * Return the HTML editor in HTML + * @return string + */ + function toHtml() { + $value = $this->getValue(); + if ($this->fullPage) { + + if (strlen(trim($value)) == 0) { + // TODO: To be considered whether here to be added DOCTYPE, language and character set declarations. + $value = ''; + $this->setValue($value); + } + } + if ($this->_flagFrozen) { + return $this->getFrozenHtml(); + } else { + return $this->build_FCKeditor(); + } + } + + /** + * Returns the htmlarea content in HTML + * @return string + */ + function getFrozenHtml() { + return $this->getValue(); + } + + /** + * Build this element using FCKeditor + */ + function build_FCKeditor() { + if (!FCKeditor :: IsCompatible()) { + return parent::toHTML(); + } + + $this->fck_editor->Value = $this->getValue(); + $result .= $this->fck_editor->CreateHtml(); + + //Add a link to open the allowed html tags window + //$result .= ''.get_lang('AllowedHTMLTags').''; + return $result; + } + } \ No newline at end of file From fad0697cfadd4af2e7c9b74c138fbdb181589106 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 17 Jul 2012 19:08:52 +0200 Subject: [PATCH 02/36] Minor - cosmetic changes (bis) --- main/inc/lib/formvalidator/Element/html_editor.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/formvalidator/Element/html_editor.php b/main/inc/lib/formvalidator/Element/html_editor.php index 0b73953b8b..d7dde836be 100644 --- a/main/inc/lib/formvalidator/Element/html_editor.php +++ b/main/inc/lib/formvalidator/Element/html_editor.php @@ -78,7 +78,6 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea { function toHtml() { $value = $this->getValue(); if ($this->fullPage) { - if (strlen(trim($value)) == 0) { // TODO: To be considered whether here to be added DOCTYPE, language and character set declarations. $value = ''; @@ -107,13 +106,10 @@ class HTML_QuickForm_html_editor extends HTML_QuickForm_textarea { if (!FCKeditor :: IsCompatible()) { return parent::toHTML(); } - - $this->fck_editor->Value = $this->getValue(); - $result .= $this->fck_editor->CreateHtml(); - + $this->fck_editor->Value = $this->getValue(); + $result = $this->fck_editor->CreateHtml(); //Add a link to open the allowed html tags window //$result .= ''.get_lang('AllowedHTMLTags').''; return $result; } - } \ No newline at end of file From 3f2fbb064f12f36b37d6125a650498c6f813026e Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 18 Jul 2012 01:36:16 -0500 Subject: [PATCH 03/36] Added some additional information to the Chamilo data recollection in order to know how many users are active --- main/admin/index.php | 2 ++ main/admin/statistics/statistics.lib.php | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/main/admin/index.php b/main/admin/index.php index 933e1a0ae7..1a29cd3fab 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -407,6 +407,7 @@ function check_system_version() { // The number of users $number_of_users = statistics::count_users(); + $number_of_active_users = statistics::count_users(null,null,null,true); $data = array( 'url' => api_get_path(WEB_PATH), @@ -415,6 +416,7 @@ function check_system_version() { 'version' => $system_version, 'numberofcourses' => $number_of_courses, 'numberofusers' => $number_of_users, + 'numberofactiveusers' => $number_of_active_users, //The donotlistcampus setting recovery should be improved to make // it true by default - this does not affect numbers counting 'donotlistcampus' => api_get_setting('donotlistcampus'), diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php index 95c0865d12..da638c3e79 100644 --- a/main/admin/statistics/statistics.lib.php +++ b/main/admin/statistics/statistics.lib.php @@ -48,10 +48,11 @@ class Statistics { * Count users * @param int optional, user status (COURSEMANAGER or STUDENT), if it's not setted it'll count all users. * @param string optional, code of a course category. Default: count only users without filtering category - * @todo count invisible courses + * @param bool count invisible courses (todo) + * @param bool count only active users (false to only return currently active users) * @return int Number of users counted */ - function count_users($status = null, $category_code = null, $count_invisible_courses = true) { + function count_users($status = null, $category_code = null, $count_invisible_courses = true, $only_active = false) { global $_configuration; // Database table definitions @@ -60,19 +61,19 @@ class Statistics { $user_table = Database :: get_main_table(TABLE_MAIN_USER); $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $current_url_id = api_get_current_access_url_id(); + $active_filter = $only_active?' AND active=1':''; + $status_filter = isset($status)?' AND status = '.intval($status):''; if ($_configuration['multiple_access_urls']) { - $status_filter = isset($status)?' AND status = '.intval($status):''; - $sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number FROM $user_table as u, $access_url_rel_user_table as url WHERE u.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter "; + $sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number FROM $user_table as u, $access_url_rel_user_table as url WHERE u.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter $active_filter"; if (isset ($category_code)) { - $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter "; + $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter $active_filter"; } } else { - $status_filter = isset($status)?' WHERE status = '.intval($status):''; - $sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table $status_filter "; + $sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table $status_filter $active_filter"; if (isset ($category_code)) { $status_filter = isset($status)?' AND status = '.intval($status):''; - $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' $status_filter "; + $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' $status_filter $active_filter"; } } From 534c0e92f19ec1737d532bc53cecab189feb78c7 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 18 Jul 2012 01:50:24 -0500 Subject: [PATCH 04/36] Fix previous commit on users count query --- main/admin/statistics/statistics.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php index da638c3e79..7f3484843f 100644 --- a/main/admin/statistics/statistics.lib.php +++ b/main/admin/statistics/statistics.lib.php @@ -70,7 +70,7 @@ class Statistics { $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter $active_filter"; } } else { - $sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table $status_filter $active_filter"; + $sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table WHERE 1=1 $status_filter $active_filter"; if (isset ($category_code)) { $status_filter = isset($status)?' AND status = '.intval($status):''; $sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' $status_filter $active_filter"; From a37eef73457fbb4223e7575a215002a71912074b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 10:25:03 +0200 Subject: [PATCH 05/36] Fixing query --- main/inc/lib/document.lib.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index d5a830b108..bbc67c5544 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -797,11 +797,11 @@ class DocumentManager { } if (!empty($document_id)) { - $sql= 'SELECT a.insert_user_id, b.readonly FROM '.$TABLE_PROPERTY.' a,'.$TABLE_DOCUMENT.' b + $sql= "SELECT a.insert_user_id, b.readonly FROM $TABLE_PROPERTY a, $TABLE_DOCUMENT b WHERE a.c_id = $course_id AND b.c_id = $course_id AND - a.ref = b.id and a.ref='.$document_id.' LIMIT 1'; + a.ref = b.id and a.ref= $document_id LIMIT 1"; $resultans = Database::query($sql); $doc_details = Database ::fetch_array($resultans, 'ASSOC'); @@ -1306,7 +1306,7 @@ class DocumentManager { } $sql='UPDATE '.$tbl_category.' SET document_id="'.Database::escape_string($document_id).'" WHERE course_code="'.Database::escape_string($course_id).'" '.$sql_session; - $rs=Database::query($sql); + Database::query($sql); } /** @@ -1461,7 +1461,7 @@ class DocumentManager { $default_certificate=self::get_default_certificate_id($course_id); if ((int)$default_certificate==(int)$default_certificate_id) { $tbl_category=Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $session_id=api_get_session_id(); + $session_id = api_get_session_id(); if ($session_id==0 || is_null($session_id)) { $sql_session='AND (session_id='.Database::escape_string($session_id).' OR isnull(session_id)) '; } elseif ($session_id>0) { @@ -1471,8 +1471,8 @@ class DocumentManager { } $sql='UPDATE '.$tbl_category.' SET document_id=null - WHERE course_code="'.Database::escape_string($course_id).'" AND document_id="'.$default_certificate_id.'" '.$sql_session; - $rs=Database::query($sql); + WHERE course_code="'.Database::escape_string($course_id).'" AND document_id="'.$default_certificate_id.'" '.$sql_session; + Database::query($sql); } } From 0c9f1892acdd0c8e0563e9038dc12f32f822b2e0 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 11:28:22 +0200 Subject: [PATCH 06/36] Minor - moving functions --- main/inc/lib/template.lib.php | 66 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index e13977f5bf..a129865544 100644 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -12,39 +12,6 @@ require_once api_get_path(LIBRARY_PATH) . 'symfony/Twig/Autoloader.php'; class Template { - public static function get_icon_path($image, $size = ICON_SIZE_SMALL) { - return Display:: return_icon($image, '', array(), $size, $show_text = false, $return_only_path = true); - } - - public static function format_date($timestamp, $format = null) { - return api_format_date($timestamp, $format); - } - - /** - * Return the item's url key: - * - * c_id=xx&id=xx - * - * @param object $item - * @return string - */ - public static function key($item){ - $id = isset($item->id) ? $item->id : null; - $c_id = isset($item->c_id) ? $item->c_id : null; - $result = ''; - if($c_id){ - $result = "c_id=$c_id"; - } - if($id){ - if($result){ - $result .= "&id=$id"; - }else{ - $result .= "&id=$id"; - } - } - return $result; - } - var $style = 'default'; //see the template folder var $preview_theme = null; var $theme; // the chamilo theme public_admin, chamilo, chamilo_red, etc @@ -169,6 +136,39 @@ class Template { } } } + } + + public static function get_icon_path($image, $size = ICON_SIZE_SMALL) { + return Display:: return_icon($image, '', array(), $size, $show_text = false, $return_only_path = true); + } + + public static function format_date($timestamp, $format = null) { + return api_format_date($timestamp, $format); + } + + /** + * Return the item's url key: + * + * c_id=xx&id=xx + * + * @param object $item + * @return string + */ + public static function key($item){ + $id = isset($item->id) ? $item->id : null; + $c_id = isset($item->c_id) ? $item->c_id : null; + $result = ''; + if($c_id){ + $result = "c_id=$c_id"; + } + if($id){ + if($result){ + $result .= "&id=$id"; + }else{ + $result .= "&id=$id"; + } + } + return $result; } function set_help($help_input = null) { From 8cb0949c99cbebaf73ce86299c45b1b7df68ed1f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 11:34:50 +0200 Subject: [PATCH 07/36] Fixing minor js errors --- main/template/default/layout/footer.tpl | 2 +- main/template/default/layout/head.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/template/default/layout/footer.tpl b/main/template/default/layout/footer.tpl index 60c4e320a4..203dbfd481 100644 --- a/main/template/default/layout/footer.tpl +++ b/main/template/default/layout/footer.tpl @@ -74,7 +74,7 @@ $(document).ready( function() { }); var tip_options = { - placement : 'right', + placement : 'right' } $('.boot-tooltip').tooltip(tip_options); diff --git a/main/template/default/layout/head.tpl b/main/template/default/layout/head.tpl index f9ee799fb2..dda13f6064 100644 --- a/main/template/default/layout/head.tpl +++ b/main/template/default/layout/head.tpl @@ -219,7 +219,7 @@ $(function() { modal : true, width : width_value, height : height_value, - resizable : resizable_value, + resizable : resizable_value }); }); //prevent the browser to follow the link From e0efd42c62414002f451e7b8dc425511c1728255 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 12:49:51 +0200 Subject: [PATCH 08/36] Should fix bug when adding editing meta tags inside the head tag see BT#4370 --- main/inc/lib/fckeditor/editor/_source/internals/fck.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) mode change 100755 => 100644 main/inc/lib/fckeditor/editor/_source/internals/fck.js diff --git a/main/inc/lib/fckeditor/editor/_source/internals/fck.js b/main/inc/lib/fckeditor/editor/_source/internals/fck.js old mode 100755 new mode 100644 index f3553d091e..b5a4a9a912 --- a/main/inc/lib/fckeditor/editor/_source/internals/fck.js +++ b/main/inc/lib/fckeditor/editor/_source/internals/fck.js @@ -381,10 +381,10 @@ var FCK = var oRegex ; if ( sTags.length > 0 ) { - oRegex = new RegExp( '<(' + sTags + ')(?!\w|:)', 'gi' ) ; + oRegex = new RegExp( '<(' + sTags + ')(?!\w|:)', 'gi' ) ; html = html.replace( oRegex, '', 'gi' ) ; + oRegex = new RegExp( '<\/(' + sTags + ')>', 'gi' ) ; html = html.replace( oRegex, '<\/FCK:$1>' ) ; } @@ -398,8 +398,10 @@ var FCK = sTags = 'META' ; if ( FCKBrowserInfo.IsIE ) sTags += '|HR' ; - - oRegex = new RegExp( '<((' + sTags + ')(?=\\s|>|/)[\\s\\S]*?)/?>', 'gi' ) ; + + //Fixes bug when editing meta tags see BT#4370 + //oRegex = new RegExp( '<((' + sTags + ')(?=\\s|>|/)[\\s\\S]*?)/?>', 'gi' ) ; + oRegex = new RegExp( '<((' + sTags + ')(?=\s|>)[\s\S]*?)/?>', 'gi' ) ; html = html.replace( oRegex, '' ) ; return html ; From 520589412434ea636248737c81cd409dca12b40c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 13:17:41 +0200 Subject: [PATCH 09/36] Minor - removing character --- main/inc/lib/fckeditor/editor/fckeditor.original.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 main/inc/lib/fckeditor/editor/fckeditor.original.html diff --git a/main/inc/lib/fckeditor/editor/fckeditor.original.html b/main/inc/lib/fckeditor/editor/fckeditor.original.html old mode 100755 new mode 100644 index 07272aee09..4271a59cfb --- a/main/inc/lib/fckeditor/editor/fckeditor.original.html +++ b/main/inc/lib/fckeditor/editor/fckeditor.original.html @@ -1,4 +1,4 @@ - + /g,//gi,//gi];FCKConfig.ProtectedSource.Add=function(A){this.RegexEntries.push(A);};FCKConfig.ProtectedSource.Protect=function(A){var B=this._CodeTag;function _Replace(protectedSource){var C=FCKTempBin.AddElement(protectedSource);return '';};for (var i=0;i|>)","g");return A.replace(D,_Replace);};FCKConfig.GetBodyAttributes=function(){var A='';if (this.BodyId&&this.BodyId.length>0) A+=' id="'+this.BodyId+'"';if (this.BodyClass&&this.BodyClass.length>0) A+=' class="'+this.BodyClass+'"';return A;};FCKConfig.ApplyBodyAttributes=function(A){if (this.BodyId&&this.BodyId.length>0) A.id=FCKConfig.BodyId;if (this.BodyClass&&this.BodyClass.length>0) A.className+=' '+FCKConfig.BodyClass;}; var FCKDebug={Output:function(){},OutputObject:function(){}}; diff --git a/main/inc/lib/fckeditor/editor/js/fckeditorcode_ie.js b/main/inc/lib/fckeditor/editor/js/fckeditorcode_ie.js old mode 100755 new mode 100644 index 42e410cd06..472d3d686c --- a/main/inc/lib/fckeditor/editor/js/fckeditorcode_ie.js +++ b/main/inc/lib/fckeditor/editor/js/fckeditorcode_ie.js @@ -29,7 +29,7 @@ var s=navigator.userAgent.toLowerCase();var FCKBrowserInfo={IsIE:/*@cc_on!@*/fal var FCKURLParams={};(function(){var A=document.location.search.substr(1).split('&');for (var i=0;i';if (!FCKRegexLib.HtmlOpener.test(A)) A=''+A+'';if (!FCKRegexLib.HeadOpener.test(A)) A=A.replace(FCKRegexLib.HtmlOpener,'$&');return A;}else{var B=FCKConfig.DocType+'0&&!FCKRegexLib.Html4DocType.test(FCKConfig.DocType)) B+=' style="overflow-y: scroll"';B+='>'+A+'';return B;}},ConvertToDataFormat:function(A,B,C,D){var E=FCKXHtml.GetXHTML(A,!B,D);if (C&&FCKRegexLib.EmptyOutParagraph.test(E)) return '';return E;},FixHtml:function(A){return A;}}; -var FCK={Name:FCKURLParams['InstanceName'],Status:0,EditMode:0,Toolbar:null,HasFocus:false,DataProcessor:new FCKDataProcessor(),GetInstanceObject:(function(){var w=window;return function(name){return w[name];}})(),AttachToOnSelectionChange:function(A){this.Events.AttachEvent('OnSelectionChange',A);},GetLinkedFieldValue:function(){return this.LinkedField.value;},GetParentForm:function(){return this.LinkedField.form;},StartupValue:'',IsDirty:function(){if (this.EditMode==1) return (this.StartupValue!=this.EditingArea.Textarea.value);else{if (!this.EditorDocument) return false;return (this.StartupValue!=this.EditorDocument.body.innerHTML);}},ResetIsDirty:function(){if (this.EditMode==1) this.StartupValue=this.EditingArea.Textarea.value;else if (this.EditorDocument.body) this.StartupValue=this.EditorDocument.body.innerHTML;},StartEditor:function(){this.TempBaseTag=FCKConfig.BaseHref.length>0?'':'';var A=FCK.KeystrokeHandler=new FCKKeystrokeHandler();A.OnKeystroke=_FCK_KeystrokeHandler_OnKeystroke;A.SetKeystrokes(FCKConfig.Keystrokes);if (FCKBrowserInfo.IsIE7){if ((CTRL+86) in A.Keystrokes) A.SetKeystrokes([CTRL+86,true]);if ((SHIFT+45) in A.Keystrokes) A.SetKeystrokes([SHIFT+45,true]);};A.SetKeystrokes([CTRL+8,true]);this.EditingArea=new FCKEditingArea(document.getElementById('xEditingArea'));this.EditingArea.FFSpellChecker=FCKConfig.FirefoxSpellChecker;this.SetData(this.GetLinkedFieldValue(),true);FCKTools.AddEventListener(document,"keydown",this._TabKeyHandler);this.AttachToOnSelectionChange(_FCK_PaddingNodeListener);if (FCKBrowserInfo.IsGecko) this.AttachToOnSelectionChange(this._ExecCheckEmptyBlock);},Focus:function(){FCK.EditingArea.Focus();},SetStatus:function(A){this.Status=A;if (A==1){FCKFocusManager.AddWindow(window,true);if (FCKBrowserInfo.IsIE) FCKFocusManager.AddWindow(window.frameElement,true);if (FCKConfig.StartupFocus) FCK.Focus();};this.Events.FireEvent('OnStatusChange',A);},FixBody:function(){var A=FCKConfig.EnterMode;if (A!='p'&&A!='div') return;var B=this.EditorDocument;if (!B) return;var C=B.body;if (!C) return;FCKDomTools.TrimNode(C);var D=C.firstChild;var E;while (D){var F=false;switch (D.nodeType){case 1:var G=D.nodeName.toLowerCase();if (!FCKListsLib.BlockElements[G]&&G!='li'&&!D.getAttribute('_fckfakelement')&&D.getAttribute('_moz_dirty')==null) F=true;break;case 3:if (E||D.nodeValue.Trim().length>0) F=true;break;case 8:if (E) F=true;break;};if (F){var H=D.parentNode;if (!E) E=H.insertBefore(B.createElement(A),D);E.appendChild(H.removeChild(D));D=E.nextSibling;}else{if (E){FCKDomTools.TrimNode(E);E=null;};D=D.nextSibling;}};if (E) FCKDomTools.TrimNode(E);},GetData:function(A){FCK.Events.FireEvent("OnBeforeGetData");if (FCK.EditMode==1) return FCK.EditingArea.Textarea.value;this.FixBody();var B=FCK.EditorDocument;if (!B) return null;var C=FCKConfig.FullPage;var D=FCK.DataProcessor.ConvertToDataFormat(C?B.documentElement:B.body,!C,FCKConfig.IgnoreEmptyParagraphValue,A);D=FCK.ProtectEventsRestore(D);if (FCKBrowserInfo.IsIE) D=D.replace(FCKRegexLib.ToReplace,'$1');if (C){if (FCK.DocTypeDeclaration&&FCK.DocTypeDeclaration.length>0) D=FCK.DocTypeDeclaration+'\n'+D;if (FCK.XmlDeclaration&&FCK.XmlDeclaration.length>0) D=FCK.XmlDeclaration+'\n'+D;};D=FCKConfig.ProtectedSource.Revert(D);setTimeout(function() { FCK.Events.FireEvent("OnAfterGetData");},0);return D;},UpdateLinkedField:function(){var A=FCK.GetXHTML(FCKConfig.FormatOutput);if (FCKConfig.HtmlEncodeOutput) A=FCKTools.HTMLEncode(A);FCK.LinkedField.value=A;FCK.Events.FireEvent('OnAfterLinkedFieldUpdate');},RegisteredDoubleClickHandlers:{},OnDoubleClick:function(A){var B=FCK.RegisteredDoubleClickHandlers[A.tagName.toUpperCase()];if (B){for (var i=0;i0?'|ABBR|XML|EMBED|OBJECT':'ABBR|XML|EMBED|OBJECT';var C;if (B.length>0){C=new RegExp('<('+B+')(?!\w|:)','gi');A=A.replace(C,'','gi');A=A.replace(C,'<\/FCK:$1>');};B='META';if (FCKBrowserInfo.IsIE) B+='|HR';C=new RegExp('<(('+B+')(?=\\s|>|/)[\\s\\S]*?)/?>','gi');A=A.replace(C,'');return A;},SetData:function(A,B){this.EditingArea.Mode=FCK.EditMode;if (FCKBrowserInfo.IsIE&&FCK.EditorDocument){FCK.EditorDocument.detachEvent("onselectionchange",Doc_OnSelectionChange);};FCKTempBin.Reset();FCK.Selection.Release();if (FCK.EditMode==0){this._ForceResetIsDirty=(B===true);A=FCKConfig.ProtectedSource.Protect(A);A=FCK.DataProcessor.ConvertToHtml(A);A=A.replace(FCKRegexLib.InvalidSelfCloseTags,'$1>');A=FCK.ProtectEvents(A);A=FCK.ProtectUrls(A);A=FCK.ProtectTags(A);if (FCK.TempBaseTag.length>0&&!FCKRegexLib.HasBaseTag.test(A)) A=A.replace(FCKRegexLib.HeadOpener,'$&'+FCK.TempBaseTag);var C='';if (!FCKConfig.FullPage) C+=_FCK_GetEditorAreaStyleTags();if (FCKBrowserInfo.IsIE) C+=FCK._GetBehaviorsStyle();else if (FCKConfig.ShowBorders) C+=FCKTools.GetStyleHtml(FCK_ShowTableBordersCSS,true);C+=FCKTools.GetStyleHtml(FCK_InternalCSS,true);A=A.replace(FCKRegexLib.HeadCloser,C+'$&');this.EditingArea.OnLoad=_FCK_EditingArea_OnLoad;this.EditingArea.Start(A);}else{FCK.EditorWindow=null;FCK.EditorDocument=null;FCKDomTools.PaddingNode=null;this.EditingArea.OnLoad=null;this.EditingArea.Start(A);this.EditingArea.Textarea._FCKShowContextMenu=true;FCK.EnterKeyHandler=null;if (B) this.ResetIsDirty();FCK.KeystrokeHandler.AttachToElement(this.EditingArea.Textarea);this.EditingArea.Textarea.focus();FCK.Events.FireEvent('OnAfterSetHTML');};if (window.onresize) window.onresize();},RedirectNamedCommands:{},ExecuteNamedCommand:function(A,B,C,D){if (!D) FCKUndo.SaveUndoStep();if (!C&&FCK.RedirectNamedCommands[A]!=null) FCK.ExecuteRedirectedNamedCommand(A,B);else{FCK.Focus();FCK.EditorDocument.execCommand(A,false,B);FCK.Events.FireEvent('OnSelectionChange');};if (!D) FCKUndo.SaveUndoStep();},GetNamedCommandState:function(A){try{if (FCKBrowserInfo.IsSafari&&FCK.EditorWindow&&A.IEquals('Paste')) return 0;if (!FCK.EditorDocument.queryCommandEnabled(A)) return -1;else{return FCK.EditorDocument.queryCommandState(A)?1:0;}}catch (e){return 0;}},GetNamedCommandValue:function(A){var B='';var C=FCK.GetNamedCommandState(A);if (C==-1) return null;try{B=this.EditorDocument.queryCommandValue(A);}catch(e) {};return B?B:'';},Paste:function(A){if (FCK.Status!=2||!FCK.Events.FireEvent('OnPaste')) return false;return A||FCK._ExecPaste();},PasteFromWord:function(){FCKDialog.OpenDialog('FCKDialog_Paste',FCKLang.PasteFromWord,'dialog/fck_paste.html',400,330,'Word');},Preview:function(){var A;if (FCKConfig.FullPage){if (FCK.TempBaseTag.length>0) A=FCK.TempBaseTag+FCK.GetXHTML();else A=FCK.GetXHTML();}else{A=FCKConfig.DocType+''+FCK.TempBaseTag+''+FCKLang.Preview+''+_FCK_GetEditorAreaStyleTags()+''+FCK.GetXHTML()+'';};var B=FCKConfig.ScreenWidth*0.8;var C=FCKConfig.ScreenHeight*0.7;var D=(FCKConfig.ScreenWidth-B)/2;var E='';if (FCK_IS_CUSTOM_DOMAIN&&FCKBrowserInfo.IsIE){window._FCKHtmlToLoad=A;E='javascript:void( (function(){document.open() ;document.domain="'+document.domain+'" ;document.write( window.opener._FCKHtmlToLoad );document.close() ;window.opener._FCKHtmlToLoad = null ;})() )';};var F=window.open(E,null,'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+B+',height='+C+',left='+D);if (!FCK_IS_CUSTOM_DOMAIN||!FCKBrowserInfo.IsIE){F.document.write(A);F.document.close();}},SwitchEditMode:function(A){var B=(FCK.EditMode==0);var C=FCK.IsDirty();var D;if (B){FCKCommands.GetCommand('ShowBlocks').SaveState();if (!A&&FCKBrowserInfo.IsIE) FCKUndo.SaveUndoStep();D=FCK.GetXHTML(FCKConfig.FormatSource);if (FCKBrowserInfo.IsIE) FCKTempBin.ToHtml();if (D==null) return false;}else D=this.EditingArea.Textarea.value;FCK.EditMode=B?1:0;FCK.SetData(D,!C);FCK.Focus();FCKTools.RunFunction(FCK.ToolbarSet.RefreshModeState,FCK.ToolbarSet);return true;},InsertElement:function(A){if (typeof A=='string') A=this.EditorDocument.createElement(A);var B=A.nodeName.toLowerCase();FCKSelection.Restore();var C=new FCKDomRange(this.EditorWindow);C.MoveToSelection();C.DeleteContents();if (FCKListsLib.BlockElements[B]!=null){if (C.StartBlock){if (C.CheckStartOfBlock()) C.MoveToPosition(C.StartBlock,3);else if (C.CheckEndOfBlock()) C.MoveToPosition(C.StartBlock,4);else C.SplitBlock();};C.InsertNode(A);var D=FCKDomTools.GetNextSourceElement(A,false,null,['hr','br','param','img','area','input'],true);if (!D&&FCKConfig.EnterMode!='br'){D=this.EditorDocument.body.appendChild(this.EditorDocument.createElement(FCKConfig.EnterMode));if (FCKBrowserInfo.IsGeckoLike) FCKTools.AppendBogusBr(D);};if (FCKListsLib.EmptyElements[B]==null) C.MoveToElementEditStart(A);else if (D) C.MoveToElementEditStart(D);else C.MoveToPosition(A,4);if (FCKBrowserInfo.IsGeckoLike){if (D) FCKDomTools.ScrollIntoView(D,false);FCKDomTools.ScrollIntoView(A,false);}}else{C.InsertNode(A);C.SetStart(A,4);C.SetEnd(A,4);};C.Select();C.Release();this.Focus();return A;},_InsertBlockElement:function(A){},_IsFunctionKey:function(A){if (A>=16&&A<=20) return true;if (A==27||(A>=33&&A<=40)) return true;if (A==45) return true;return false;},_KeyDownListener:function(A){if (!A) A=FCK.EditorWindow.event;if (FCK.EditorWindow){if (!FCK._IsFunctionKey(A.keyCode)&&!(A.ctrlKey||A.metaKey)&&!(A.keyCode==46)) FCK._KeyDownUndo();};return true;},_KeyDownUndo:function(){if (!FCKUndo.Typing){FCKUndo.SaveUndoStep();FCKUndo.Typing=true;FCK.Events.FireEvent("OnSelectionChange");};FCKUndo.TypesCount++;FCKUndo.Changed=1;if (FCKUndo.TypesCount>FCKUndo.MaxTypes){FCKUndo.TypesCount=0;FCKUndo.SaveUndoStep();}},_TabKeyHandler:function(A){if (!A) A=window.event;var B=A.keyCode;if (B==9&&FCK.EditMode!=0){if (FCKBrowserInfo.IsIE){var C=document.selection.createRange();if (C.parentElement()!=FCK.EditingArea.Textarea) return true;C.text='\t';C.select();}else{var a=[];var D=FCK.EditingArea.Textarea;var E=D.selectionStart;var F=D.selectionEnd;a.push(D.value.substr(0,E));a.push('\t');a.push(D.value.substr(F));D.value=a.join('');D.setSelectionRange(E+1,E+1);};if (A.preventDefault) return A.preventDefault();return A.returnValue=false;};return true;}};FCK.Events=new FCKEvents(FCK);FCK.GetHTML=FCK.GetXHTML=FCK.GetData;FCK.SetHTML=FCK.SetData;FCK.InsertElementAndGetIt=FCK.CreateElement=FCK.InsertElement;function _FCK_ProtectEvents_ReplaceTags(A){return A.replace(FCKRegexLib.EventAttributes,_FCK_ProtectEvents_ReplaceEvents);};function _FCK_ProtectEvents_ReplaceEvents(A,B){return ' '+B+'_fckprotectedatt="'+encodeURIComponent(A)+'"';};function _FCK_ProtectEvents_RestoreEvents(A,B){return decodeURIComponent(B);};function _FCK_MouseEventsListener(A){if (!A) A=window.event;if (A.type=='mousedown') FCK.MouseDownFlag=true;else if (A.type=='mouseup') FCK.MouseDownFlag=false;else if (A.type=='mousemove') FCK.Events.FireEvent('OnMouseMove',A);};function _FCK_PaddingNodeListener(){if (FCKConfig.EnterMode.IEquals('br')) return;FCKDomTools.EnforcePaddingNode(FCK.EditorDocument,FCKConfig.EnterMode);if (!FCKBrowserInfo.IsIE&&FCKDomTools.PaddingNode){var A=FCKSelection.GetSelection();if (A&&A.rangeCount==1){var B=A.getRangeAt(0);if (B.collapsed&&B.startContainer==FCK.EditorDocument.body&&B.startOffset==0){B.selectNodeContents(FCKDomTools.PaddingNode);B.collapse(true);A.removeAllRanges();A.addRange(B);}}}else if (FCKDomTools.PaddingNode){var C=FCKSelection.GetParentElement();var D=FCKDomTools.PaddingNode;if (C&&C.nodeName.IEquals('body')){if (FCK.EditorDocument.body.childNodes.length==1&&FCK.EditorDocument.body.firstChild==D){if (FCKSelection._GetSelectionDocument(FCK.EditorDocument.selection)!=FCK.EditorDocument) return;var B=FCK.EditorDocument.body.createTextRange();var F=false;if (!D.childNodes.firstChild){D.appendChild(FCKTools.GetElementDocument(D).createTextNode('\ufeff'));F=true;};B.moveToElementText(D);B.select();if (F) B.pasteHTML('');}}}};function _FCK_EditingArea_OnLoad(){FCK.EditorWindow=FCK.EditingArea.Window;FCK.EditorDocument=FCK.EditingArea.Document;if (FCKBrowserInfo.IsIE) FCKTempBin.ToElements();FCK.InitializeBehaviors();FCK.MouseDownFlag=false;FCKTools.AddEventListener(FCK.EditorDocument,'mousemove',_FCK_MouseEventsListener);FCKTools.AddEventListener(FCK.EditorDocument,'mousedown',_FCK_MouseEventsListener);FCKTools.AddEventListener(FCK.EditorDocument,'mouseup',_FCK_MouseEventsListener);if (FCKBrowserInfo.IsSafari){FCKTools.AddEventListener(FCK.EditorDocument,'paste',function(evt){var A=new FCKDomRange(FCK.EditorWindow);var B=FCK.EditorDocument.createTextNode('\ufeff');var C=FCK.EditorDocument.createElement('a');C.id='fck_paste_padding';C.innerHTML='';A.MoveToSelection();A.DeleteContents();A.InsertNode(B);A.Collapse();A.InsertNode(C);A.MoveToPosition(C,3);A.Select();setTimeout(function(){B.parentNode.removeChild(B);C=FCK.EditorDocument.getElementById('fck_paste_padding');C.parentNode.removeChild(C);},0);});};if (FCKBrowserInfo.IsSafari){var D=function(evt){if (!(evt.ctrlKey||evt.metaKey)) return;if (FCK.EditMode!=0) return;switch (evt.keyCode){case 89:FCKUndo.Redo();break;case 90:FCKUndo.Undo();break;}};FCKTools.AddEventListener(FCK.EditorDocument,'keyup',D);};FCK.EnterKeyHandler=new FCKEnterKey(FCK.EditorWindow,FCKConfig.EnterMode,FCKConfig.ShiftEnterMode,FCKConfig.TabSpaces);FCK.KeystrokeHandler.AttachToElement(FCK.EditorDocument);if (FCK._ForceResetIsDirty) FCK.ResetIsDirty();if (FCKBrowserInfo.IsIE&&FCK.HasFocus) FCK.EditorDocument.body.setActive();FCK.OnAfterSetHTML();FCKCommands.GetCommand('ShowBlocks').RestoreState();if (FCK.Status!=0) return;FCK.SetStatus(1);};function _FCK_GetEditorAreaStyleTags(){return FCKTools.GetStyleHtml(FCKConfig.EditorAreaCSS)+FCKTools.GetStyleHtml(FCKConfig.EditorAreaStyles);};function _FCK_KeystrokeHandler_OnKeystroke(A,B){if (FCK.Status!=2) return false;if (FCK.EditMode==0){switch (B){case 'Paste':return!FCK.Paste();case 'Cut':FCKUndo.SaveUndoStep();return false;}}else{if (B.Equals('Paste','Undo','Redo','SelectAll','Cut')) return false;};var C=FCK.Commands.GetCommand(B);if (C.GetState()==-1) return false;return (C.Execute.apply(C,FCKTools.ArgumentsToArray(arguments,2))!==false);};(function(){var A=window.parent.document;var B=A.getElementById(FCK.Name);var i=0;while (B||i==0){if (B&&B.tagName.toLowerCase().Equals('input','textarea')){FCK.LinkedField=B;break;};B=A.getElementsByName(FCK.Name)[i++];}})();var FCKTempBin={Elements:[],AddElement:function(A){var B=this.Elements.length;this.Elements[B]=A;return B;},RemoveElement:function(A){var e=this.Elements[A];this.Elements[A]=null;return e;},Reset:function(){var i=0;while (i '+this.Elements[i].outerHTML+'';this.Elements[i].isHtml=true;}},ToElements:function(){var A=FCK.EditorDocument.createElement('div');for (var i=0;i0?'':'';var A=FCK.KeystrokeHandler=new FCKKeystrokeHandler();A.OnKeystroke=_FCK_KeystrokeHandler_OnKeystroke;A.SetKeystrokes(FCKConfig.Keystrokes);if (FCKBrowserInfo.IsIE7){if ((CTRL+86) in A.Keystrokes) A.SetKeystrokes([CTRL+86,true]);if ((SHIFT+45) in A.Keystrokes) A.SetKeystrokes([SHIFT+45,true]);};A.SetKeystrokes([CTRL+8,true]);this.EditingArea=new FCKEditingArea(document.getElementById('xEditingArea'));this.EditingArea.FFSpellChecker=FCKConfig.FirefoxSpellChecker;this.SetData(this.GetLinkedFieldValue(),true);FCKTools.AddEventListener(document,"keydown",this._TabKeyHandler);this.AttachToOnSelectionChange(_FCK_PaddingNodeListener);if (FCKBrowserInfo.IsGecko) this.AttachToOnSelectionChange(this._ExecCheckEmptyBlock);},Focus:function(){FCK.EditingArea.Focus();},SetStatus:function(A){this.Status=A;if (A==1){FCKFocusManager.AddWindow(window,true);if (FCKBrowserInfo.IsIE) FCKFocusManager.AddWindow(window.frameElement,true);if (FCKConfig.StartupFocus) FCK.Focus();};this.Events.FireEvent('OnStatusChange',A);},FixBody:function(){var A=FCKConfig.EnterMode;if (A!='p'&&A!='div') return;var B=this.EditorDocument;if (!B) return;var C=B.body;if (!C) return;FCKDomTools.TrimNode(C);var D=C.firstChild;var E;while (D){var F=false;switch (D.nodeType){case 1:var G=D.nodeName.toLowerCase();if (!FCKListsLib.BlockElements[G]&&G!='li'&&!D.getAttribute('_fckfakelement')&&D.getAttribute('_moz_dirty')==null) F=true;break;case 3:if (E||D.nodeValue.Trim().length>0) F=true;break;case 8:if (E) F=true;break;};if (F){var H=D.parentNode;if (!E) E=H.insertBefore(B.createElement(A),D);E.appendChild(H.removeChild(D));D=E.nextSibling;}else{if (E){FCKDomTools.TrimNode(E);E=null;};D=D.nextSibling;}};if (E) FCKDomTools.TrimNode(E);},GetData:function(A){FCK.Events.FireEvent("OnBeforeGetData");if (FCK.EditMode==1) return FCK.EditingArea.Textarea.value;this.FixBody();var B=FCK.EditorDocument;if (!B) return null;var C=FCKConfig.FullPage;var D=FCK.DataProcessor.ConvertToDataFormat(C?B.documentElement:B.body,!C,FCKConfig.IgnoreEmptyParagraphValue,A);D=FCK.ProtectEventsRestore(D);if (FCKBrowserInfo.IsIE) D=D.replace(FCKRegexLib.ToReplace,'$1');if (C){if (FCK.DocTypeDeclaration&&FCK.DocTypeDeclaration.length>0) D=FCK.DocTypeDeclaration+'\n'+D;if (FCK.XmlDeclaration&&FCK.XmlDeclaration.length>0) D=FCK.XmlDeclaration+'\n'+D;};D=FCKConfig.ProtectedSource.Revert(D);setTimeout(function() { FCK.Events.FireEvent("OnAfterGetData");},0);return D;},UpdateLinkedField:function(){var A=FCK.GetXHTML(FCKConfig.FormatOutput);if (FCKConfig.HtmlEncodeOutput) A=FCKTools.HTMLEncode(A);FCK.LinkedField.value=A;FCK.Events.FireEvent('OnAfterLinkedFieldUpdate');},RegisteredDoubleClickHandlers:{},OnDoubleClick:function(A){var B=FCK.RegisteredDoubleClickHandlers[A.tagName.toUpperCase()];if (B){for (var i=0;i0?'|ABBR|XML|EMBED|OBJECT':'ABBR|XML|EMBED|OBJECT';var C;if (B.length>0){C=new RegExp('<('+B+')(?!\w|:)','gi');A=A.replace(C,'','gi');A=A.replace(C,'<\/FCK:$1>');};B='META';if (FCKBrowserInfo.IsIE) B+='|HR';C=new RegExp('<(('+B+')(?=\s|>)[\s\S]*?)/?>','gi');A=A.replace(C,'');return A;},SetData:function(A,B){this.EditingArea.Mode=FCK.EditMode;if (FCKBrowserInfo.IsIE&&FCK.EditorDocument){FCK.EditorDocument.detachEvent("onselectionchange",Doc_OnSelectionChange);};FCKTempBin.Reset();FCK.Selection.Release();if (FCK.EditMode==0){this._ForceResetIsDirty=(B===true);A=FCKConfig.ProtectedSource.Protect(A);A=FCK.DataProcessor.ConvertToHtml(A);A=A.replace(FCKRegexLib.InvalidSelfCloseTags,'$1>');A=FCK.ProtectEvents(A);A=FCK.ProtectUrls(A);A=FCK.ProtectTags(A);if (FCK.TempBaseTag.length>0&&!FCKRegexLib.HasBaseTag.test(A)) A=A.replace(FCKRegexLib.HeadOpener,'$&'+FCK.TempBaseTag);var C='';if (!FCKConfig.FullPage) C+=_FCK_GetEditorAreaStyleTags();if (FCKBrowserInfo.IsIE) C+=FCK._GetBehaviorsStyle();else if (FCKConfig.ShowBorders) C+=FCKTools.GetStyleHtml(FCK_ShowTableBordersCSS,true);C+=FCKTools.GetStyleHtml(FCK_InternalCSS,true);A=A.replace(FCKRegexLib.HeadCloser,C+'$&');this.EditingArea.OnLoad=_FCK_EditingArea_OnLoad;this.EditingArea.Start(A);}else{FCK.EditorWindow=null;FCK.EditorDocument=null;FCKDomTools.PaddingNode=null;this.EditingArea.OnLoad=null;this.EditingArea.Start(A);this.EditingArea.Textarea._FCKShowContextMenu=true;FCK.EnterKeyHandler=null;if (B) this.ResetIsDirty();FCK.KeystrokeHandler.AttachToElement(this.EditingArea.Textarea);this.EditingArea.Textarea.focus();FCK.Events.FireEvent('OnAfterSetHTML');};if (window.onresize) window.onresize();},RedirectNamedCommands:{},ExecuteNamedCommand:function(A,B,C,D){if (!D) FCKUndo.SaveUndoStep();if (!C&&FCK.RedirectNamedCommands[A]!=null) FCK.ExecuteRedirectedNamedCommand(A,B);else{FCK.Focus();FCK.EditorDocument.execCommand(A,false,B);FCK.Events.FireEvent('OnSelectionChange');};if (!D) FCKUndo.SaveUndoStep();},GetNamedCommandState:function(A){try{if (FCKBrowserInfo.IsSafari&&FCK.EditorWindow&&A.IEquals('Paste')) return 0;if (!FCK.EditorDocument.queryCommandEnabled(A)) return -1;else{return FCK.EditorDocument.queryCommandState(A)?1:0;}}catch (e){return 0;}},GetNamedCommandValue:function(A){var B='';var C=FCK.GetNamedCommandState(A);if (C==-1) return null;try{B=this.EditorDocument.queryCommandValue(A);}catch(e) {};return B?B:'';},Paste:function(A){if (FCK.Status!=2||!FCK.Events.FireEvent('OnPaste')) return false;return A||FCK._ExecPaste();},PasteFromWord:function(){FCKDialog.OpenDialog('FCKDialog_Paste',FCKLang.PasteFromWord,'dialog/fck_paste.html',400,330,'Word');},Preview:function(){var A;if (FCKConfig.FullPage){if (FCK.TempBaseTag.length>0) A=FCK.TempBaseTag+FCK.GetXHTML();else A=FCK.GetXHTML();}else{A=FCKConfig.DocType+''+FCK.TempBaseTag+''+FCKLang.Preview+''+_FCK_GetEditorAreaStyleTags()+''+FCK.GetXHTML()+'';};var B=FCKConfig.ScreenWidth*0.8;var C=FCKConfig.ScreenHeight*0.7;var D=(FCKConfig.ScreenWidth-B)/2;var E='';if (FCK_IS_CUSTOM_DOMAIN&&FCKBrowserInfo.IsIE){window._FCKHtmlToLoad=A;E='javascript:void( (function(){document.open() ;document.domain="'+document.domain+'" ;document.write( window.opener._FCKHtmlToLoad );document.close() ;window.opener._FCKHtmlToLoad = null ;})() )';};var F=window.open(E,null,'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+B+',height='+C+',left='+D);if (!FCK_IS_CUSTOM_DOMAIN||!FCKBrowserInfo.IsIE){F.document.write(A);F.document.close();}},SwitchEditMode:function(A){var B=(FCK.EditMode==0);var C=FCK.IsDirty();var D;if (B){FCKCommands.GetCommand('ShowBlocks').SaveState();if (!A&&FCKBrowserInfo.IsIE) FCKUndo.SaveUndoStep();D=FCK.GetXHTML(FCKConfig.FormatSource);if (FCKBrowserInfo.IsIE) FCKTempBin.ToHtml();if (D==null) return false;}else D=this.EditingArea.Textarea.value;FCK.EditMode=B?1:0;FCK.SetData(D,!C);FCK.Focus();FCKTools.RunFunction(FCK.ToolbarSet.RefreshModeState,FCK.ToolbarSet);return true;},InsertElement:function(A){if (typeof A=='string') A=this.EditorDocument.createElement(A);var B=A.nodeName.toLowerCase();FCKSelection.Restore();var C=new FCKDomRange(this.EditorWindow);C.MoveToSelection();C.DeleteContents();if (FCKListsLib.BlockElements[B]!=null){if (C.StartBlock){if (C.CheckStartOfBlock()) C.MoveToPosition(C.StartBlock,3);else if (C.CheckEndOfBlock()) C.MoveToPosition(C.StartBlock,4);else C.SplitBlock();};C.InsertNode(A);var D=FCKDomTools.GetNextSourceElement(A,false,null,['hr','br','param','img','area','input'],true);if (!D&&FCKConfig.EnterMode!='br'){D=this.EditorDocument.body.appendChild(this.EditorDocument.createElement(FCKConfig.EnterMode));if (FCKBrowserInfo.IsGeckoLike) FCKTools.AppendBogusBr(D);};if (FCKListsLib.EmptyElements[B]==null) C.MoveToElementEditStart(A);else if (D) C.MoveToElementEditStart(D);else C.MoveToPosition(A,4);if (FCKBrowserInfo.IsGeckoLike){if (D) FCKDomTools.ScrollIntoView(D,false);FCKDomTools.ScrollIntoView(A,false);}}else{C.InsertNode(A);C.SetStart(A,4);C.SetEnd(A,4);};C.Select();C.Release();this.Focus();return A;},_InsertBlockElement:function(A){},_IsFunctionKey:function(A){if (A>=16&&A<=20) return true;if (A==27||(A>=33&&A<=40)) return true;if (A==45) return true;return false;},_KeyDownListener:function(A){if (!A) A=FCK.EditorWindow.event;if (FCK.EditorWindow){if (!FCK._IsFunctionKey(A.keyCode)&&!(A.ctrlKey||A.metaKey)&&!(A.keyCode==46)) FCK._KeyDownUndo();};return true;},_KeyDownUndo:function(){if (!FCKUndo.Typing){FCKUndo.SaveUndoStep();FCKUndo.Typing=true;FCK.Events.FireEvent("OnSelectionChange");};FCKUndo.TypesCount++;FCKUndo.Changed=1;if (FCKUndo.TypesCount>FCKUndo.MaxTypes){FCKUndo.TypesCount=0;FCKUndo.SaveUndoStep();}},_TabKeyHandler:function(A){if (!A) A=window.event;var B=A.keyCode;if (B==9&&FCK.EditMode!=0){if (FCKBrowserInfo.IsIE){var C=document.selection.createRange();if (C.parentElement()!=FCK.EditingArea.Textarea) return true;C.text='\t';C.select();}else{var a=[];var D=FCK.EditingArea.Textarea;var E=D.selectionStart;var F=D.selectionEnd;a.push(D.value.substr(0,E));a.push('\t');a.push(D.value.substr(F));D.value=a.join('');D.setSelectionRange(E+1,E+1);};if (A.preventDefault) return A.preventDefault();return A.returnValue=false;};return true;}};FCK.Events=new FCKEvents(FCK);FCK.GetHTML=FCK.GetXHTML=FCK.GetData;FCK.SetHTML=FCK.SetData;FCK.InsertElementAndGetIt=FCK.CreateElement=FCK.InsertElement;function _FCK_ProtectEvents_ReplaceTags(A){return A.replace(FCKRegexLib.EventAttributes,_FCK_ProtectEvents_ReplaceEvents);};function _FCK_ProtectEvents_ReplaceEvents(A,B){return ' '+B+'_fckprotectedatt="'+encodeURIComponent(A)+'"';};function _FCK_ProtectEvents_RestoreEvents(A,B){return decodeURIComponent(B);};function _FCK_MouseEventsListener(A){if (!A) A=window.event;if (A.type=='mousedown') FCK.MouseDownFlag=true;else if (A.type=='mouseup') FCK.MouseDownFlag=false;else if (A.type=='mousemove') FCK.Events.FireEvent('OnMouseMove',A);};function _FCK_PaddingNodeListener(){if (FCKConfig.EnterMode.IEquals('br')) return;FCKDomTools.EnforcePaddingNode(FCK.EditorDocument,FCKConfig.EnterMode);if (!FCKBrowserInfo.IsIE&&FCKDomTools.PaddingNode){var A=FCKSelection.GetSelection();if (A&&A.rangeCount==1){var B=A.getRangeAt(0);if (B.collapsed&&B.startContainer==FCK.EditorDocument.body&&B.startOffset==0){B.selectNodeContents(FCKDomTools.PaddingNode);B.collapse(true);A.removeAllRanges();A.addRange(B);}}}else if (FCKDomTools.PaddingNode){var C=FCKSelection.GetParentElement();var D=FCKDomTools.PaddingNode;if (C&&C.nodeName.IEquals('body')){if (FCK.EditorDocument.body.childNodes.length==1&&FCK.EditorDocument.body.firstChild==D){if (FCKSelection._GetSelectionDocument(FCK.EditorDocument.selection)!=FCK.EditorDocument) return;var B=FCK.EditorDocument.body.createTextRange();var F=false;if (!D.childNodes.firstChild){D.appendChild(FCKTools.GetElementDocument(D).createTextNode('\ufeff'));F=true;};B.moveToElementText(D);B.select();if (F) B.pasteHTML('');}}}};function _FCK_EditingArea_OnLoad(){FCK.EditorWindow=FCK.EditingArea.Window;FCK.EditorDocument=FCK.EditingArea.Document;if (FCKBrowserInfo.IsIE) FCKTempBin.ToElements();FCK.InitializeBehaviors();FCK.MouseDownFlag=false;FCKTools.AddEventListener(FCK.EditorDocument,'mousemove',_FCK_MouseEventsListener);FCKTools.AddEventListener(FCK.EditorDocument,'mousedown',_FCK_MouseEventsListener);FCKTools.AddEventListener(FCK.EditorDocument,'mouseup',_FCK_MouseEventsListener);if (FCKBrowserInfo.IsSafari){FCKTools.AddEventListener(FCK.EditorDocument,'paste',function(evt){var A=new FCKDomRange(FCK.EditorWindow);var B=FCK.EditorDocument.createTextNode('\ufeff');var C=FCK.EditorDocument.createElement('a');C.id='fck_paste_padding';C.innerHTML='';A.MoveToSelection();A.DeleteContents();A.InsertNode(B);A.Collapse();A.InsertNode(C);A.MoveToPosition(C,3);A.Select();setTimeout(function(){B.parentNode.removeChild(B);C=FCK.EditorDocument.getElementById('fck_paste_padding');C.parentNode.removeChild(C);},0);});};if (FCKBrowserInfo.IsSafari){var D=function(evt){if (!(evt.ctrlKey||evt.metaKey)) return;if (FCK.EditMode!=0) return;switch (evt.keyCode){case 89:FCKUndo.Redo();break;case 90:FCKUndo.Undo();break;}};FCKTools.AddEventListener(FCK.EditorDocument,'keyup',D);};FCK.EnterKeyHandler=new FCKEnterKey(FCK.EditorWindow,FCKConfig.EnterMode,FCKConfig.ShiftEnterMode,FCKConfig.TabSpaces);FCK.KeystrokeHandler.AttachToElement(FCK.EditorDocument);if (FCK._ForceResetIsDirty) FCK.ResetIsDirty();if (FCKBrowserInfo.IsIE&&FCK.HasFocus) FCK.EditorDocument.body.setActive();FCK.OnAfterSetHTML();FCKCommands.GetCommand('ShowBlocks').RestoreState();if (FCK.Status!=0) return;FCK.SetStatus(1);};function _FCK_GetEditorAreaStyleTags(){return FCKTools.GetStyleHtml(FCKConfig.EditorAreaCSS)+FCKTools.GetStyleHtml(FCKConfig.EditorAreaStyles);};function _FCK_KeystrokeHandler_OnKeystroke(A,B){if (FCK.Status!=2) return false;if (FCK.EditMode==0){switch (B){case 'Paste':return!FCK.Paste();case 'Cut':FCKUndo.SaveUndoStep();return false;}}else{if (B.Equals('Paste','Undo','Redo','SelectAll','Cut')) return false;};var C=FCK.Commands.GetCommand(B);if (C.GetState()==-1) return false;return (C.Execute.apply(C,FCKTools.ArgumentsToArray(arguments,2))!==false);};(function(){var A=window.parent.document;var B=A.getElementById(FCK.Name);var i=0;while (B||i==0){if (B&&B.tagName.toLowerCase().Equals('input','textarea')){FCK.LinkedField=B;break;};B=A.getElementsByName(FCK.Name)[i++];}})();var FCKTempBin={Elements:[],AddElement:function(A){var B=this.Elements.length;this.Elements[B]=A;return B;},RemoveElement:function(A){var e=this.Elements[A];this.Elements[A]=null;return e;},Reset:function(){var i=0;while (i '+this.Elements[i].outerHTML+'';this.Elements[i].isHtml=true;}},ToElements:function(){var A=FCK.EditorDocument.createElement('div');for (var i=0;i0) C+='TABLE { behavior: '+B+' ; }';C+='';FCK._BehaviorsStyle=C;};return FCK._BehaviorsStyle;};function Doc_OnMouseUp(){if (FCK.EditorWindow.event.srcElement.tagName=='HTML'){FCK.Focus();FCK.EditorWindow.event.cancelBubble=true;FCK.EditorWindow.event.returnValue=false;}};function Doc_OnPaste(){var A=FCK.EditorDocument.body;A.detachEvent('onpaste',Doc_OnPaste);var B=FCK.Paste(!FCKConfig.ForcePasteAsPlainText&&!FCKConfig.AutoDetectPasteFromWord);A.attachEvent('onpaste',Doc_OnPaste);return B;};function Doc_OnDblClick(){FCK.OnDoubleClick(FCK.EditorWindow.event.srcElement);FCK.EditorWindow.event.cancelBubble=true;};function Doc_OnSelectionChange(){if (!FCK.IsSelectionChangeLocked&&FCK.EditorDocument) FCK.Events.FireEvent("OnSelectionChange");};function Doc_OnDrop(){if (FCK.MouseDownFlag){FCK.MouseDownFlag=false;return;};if (FCKConfig.ForcePasteAsPlainText){var A=FCK.EditorWindow.event;if (FCK._CheckIsPastingEnabled()||FCKConfig.ShowDropDialog) FCK.PasteAsPlainText(A.dataTransfer.getData('Text'));A.returnValue=false;A.cancelBubble=true;}};FCK.InitializeBehaviors=function(A){this.EditorDocument.attachEvent('onmouseup',Doc_OnMouseUp);this.EditorDocument.body.attachEvent('onpaste',Doc_OnPaste);this.EditorDocument.body.attachEvent('ondrop',Doc_OnDrop);FCK.ContextMenu._InnerContextMenu.AttachToElement(FCK.EditorDocument.body);this.EditorDocument.attachEvent("onkeydown",FCK._KeyDownListener);this.EditorDocument.attachEvent("ondblclick",Doc_OnDblClick);this.EditorDocument.attachEvent("onbeforedeactivate",function(){ FCKSelection.Save();});this.EditorDocument.attachEvent("onselectionchange",Doc_OnSelectionChange);FCKTools.AddEventListener(FCK.EditorDocument,'mousedown',Doc_OnMouseDown);};FCK.InsertHtml=function(A){A=FCKConfig.ProtectedSource.Protect(A);A=FCK.ProtectEvents(A);A=FCK.ProtectUrls(A);A=FCK.ProtectTags(A);FCKSelection.Restore();FCK.EditorWindow.focus();FCKUndo.SaveUndoStep();var B=FCKSelection.GetSelection();if (B.type.toLowerCase()=='control') B.clear();A=''+A;B.createRange().pasteHTML(A);var C=FCK.EditorDocument.getElementById('__fakeFCKRemove__');if (C.parentNode.childNodes.length==1) C=C.parentNode;C.removeNode(true);FCKDocumentProcessor.Process(FCK.EditorDocument);this.Events.FireEvent("OnSelectionChange");};FCK.SetInnerHtml=function(A){var B=FCK.EditorDocument;B.body.innerHTML='
 
'+A;B.getElementById('__fakeFCKRemove__').removeNode(true);};function FCK_PreloadImages(){var A=new FCKImagePreloader();A.AddImages(FCKConfig.PreloadImages);A.AddImages(FCKConfig.SkinPath+'fck_strip.gif');A.OnComplete=LoadToolbarSetup;A.Start();};function Document_OnContextMenu(){return (event.srcElement._FCKShowContextMenu==true);};document.oncontextmenu=Document_OnContextMenu;function FCK_Cleanup(){this.LinkedField=null;this.EditorWindow=null;this.EditorDocument=null;};FCK._ExecPaste=function(){if (FCK._PasteIsRunning) return true;if (FCKConfig.ForcePasteAsPlainText){FCK.PasteAsPlainText();return false;};var A=FCK._CheckIsPastingEnabled(true);if (A===false) FCKTools.RunFunction(FCKDialog.OpenDialog,FCKDialog,['FCKDialog_Paste',FCKLang.Paste,'dialog/fck_paste.html',400,330,'Security']);else{if (FCKConfig.AutoDetectPasteFromWord&&A.length>0){var B=/<\w[^>]*(( class="?MsoNormal"?)|(="mso-))/gi;if (B.test(A)){if (confirm(FCKLang.PasteWordConfirm)){FCK.PasteFromWord();return false;}}};FCK._PasteIsRunning=true;FCK.ExecuteNamedCommand('Paste');delete FCK._PasteIsRunning;};return false;};FCK.PasteAsPlainText=function(A){if (!FCK._CheckIsPastingEnabled()){FCKDialog.OpenDialog('FCKDialog_Paste',FCKLang.PasteAsText,'dialog/fck_paste.html',400,330,'PlainText');return;};var B=null;if (!A) B=clipboardData.getData("Text");else B=A;if (B&&B.length>0){B=FCKTools.HTMLEncode(B);B=FCKTools.ProcessLineBreaks(window,FCKConfig,B);var C=B.search('

');var D=B.search('

');if ((C!=-1&&D!=-1&&C0){if (D){var F=this.EditorDocument.createElement('A');F.href=A;var G=E;G.parentNode.insertBefore(F,G);G.parentNode.removeChild(G);F.appendChild(G);return [F];};var H='javascript:void(0);/*'+(new Date().getTime())+'*/';FCK.ExecuteNamedCommand('CreateLink',H,false,!!B);var I=this.EditorDocument.links;for (i=0;i0&&!isNaN(E)) this.PageConfig[D]=parseFloat(E);else this.PageConfig[D]=E;}};function FCKConfig_LoadPageConfig(){var A=FCKConfig.PageConfig;for (var B in A) FCKConfig[B]=A[B];};function FCKConfig_PreProcess(){var A=FCKConfig;if (A.AllowQueryStringDebug){try{if ((/fckdebug=true/i).test(window.top.location.search)) A.Debug=true;}catch (e) { }};if (!A.PluginsPath.EndsWith('/')) A.PluginsPath+='/';var B=A.ToolbarComboPreviewCSS;if (!B||B.length==0) A.ToolbarComboPreviewCSS=A.EditorAreaCSS;A.RemoveAttributesArray=(A.RemoveAttributes||'').split(',');if (!FCKConfig.SkinEditorCSS||FCKConfig.SkinEditorCSS.length==0) FCKConfig.SkinEditorCSS=FCKConfig.SkinPath+'fck_editor.css';if (!FCKConfig.SkinDialogCSS||FCKConfig.SkinDialogCSS.length==0) FCKConfig.SkinDialogCSS=FCKConfig.SkinPath+'fck_dialog.css';};FCKConfig.ToolbarSets={};FCKConfig.Plugins={};FCKConfig.Plugins.Items=[];FCKConfig.Plugins.Add=function(A,B,C){FCKConfig.Plugins.Items.push([A,B,C]);};FCKConfig.ProtectedSource={};FCKConfig.ProtectedSource._CodeTag=(new Date()).valueOf();FCKConfig.ProtectedSource.RegexEntries=[//g,//gi,//gi];FCKConfig.ProtectedSource.Add=function(A){this.RegexEntries.push(A);};FCKConfig.ProtectedSource.Protect=function(A){var B=this._CodeTag;function _Replace(protectedSource){var C=FCKTempBin.AddElement(protectedSource);return '';};for (var i=0;i|>)","g");return A.replace(D,_Replace);};FCKConfig.GetBodyAttributes=function(){var A='';if (this.BodyId&&this.BodyId.length>0) A+=' id="'+this.BodyId+'"';if (this.BodyClass&&this.BodyClass.length>0) A+=' class="'+this.BodyClass+'"';return A;};FCKConfig.ApplyBodyAttributes=function(A){if (this.BodyId&&this.BodyId.length>0) A.id=FCKConfig.BodyId;if (this.BodyClass&&this.BodyClass.length>0) A.className+=' '+FCKConfig.BodyClass;}; var FCKDebug={Output:function(){},OutputObject:function(){}}; From 47f36bafc694174aaff7edbc08fe730744ef3c3e Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 13:53:22 +0200 Subject: [PATCH 11/36] Review only marked questions in all-on-one-page mode see #4542 --- main/exercice/exercise_submit.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index 30ffafb864..584ad789a2 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -740,8 +740,7 @@ if (!empty($error)) { $number_of_hotspot_questions = 0; $onsubmit = ''; $i = 0; - //i have a doubt in this line cvargas - //var_dump($questionList); + if (!strcmp($questionList[0], '') === 0) { foreach ($questionList as $questionId) { $i++; @@ -782,6 +781,8 @@ if (!empty($error)) { //$(this).find(".exercise_save_now_button").hide(); $(this).removeClass("question_highlight"); }); + + $(".no_remind_highlight").hide(); }); @@ -973,6 +974,12 @@ if (!empty($error)) { $user_choice = $attempt_list[$questionId]; $remind_highlight = ''; + + //Hides questions when reviewing a ALL_ON_ONE_PAGE exercise see #4542 no_remind_highlight class hide with jquery + if ($objExercise->type == ALL_ON_ONE_PAGE && isset($_GET['reminder']) && $_GET['reminder'] == 2) { + $remind_highlight = 'no_remind_highlight'; + } + $exercise_actions = ''; $is_remind_on = false; From 3f3e517169983d3ed683c7c6fa5f12a741563e78 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 14:02:21 +0200 Subject: [PATCH 12/36] Fixing js error --- main/document/showinframes.php | 80 ++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/main/document/showinframes.php b/main/document/showinframes.php index 625e3a7710..a58dd94212 100644 --- a/main/document/showinframes.php +++ b/main/document/showinframes.php @@ -173,34 +173,6 @@ if (api_get_setting('show_glossary_in_documents') == 'ismanual') { // });'; } -if (!$jplayer_supported) { - $htmlHeadXtra[] = ''; - $htmlHeadXtra[] = ''; - - $htmlHeadXtra[] = ''; -} $web_odf_supported_files = DocumentManager::get_web_odf_extension_list(); if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) { @@ -220,6 +192,8 @@ if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) { '; } +$execute_iframe = true; + if ($jplayer_supported) { $extension = api_strtolower($pathinfo['extension']); @@ -251,11 +225,46 @@ if ($jplayer_supported) { '.$jquery.' }); '; + $execute_iframe = false; +} +if ($show_web_odf) { + $execute_iframe = false; +} + +$is_nanogong_available = $pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'; +if ($is_nanogong_available){ + $execute_iframe = false; +} + +if (!$jplayer_supported && $execute_iframe) { + + $htmlHeadXtra[] = ''; + $htmlHeadXtra[] = ''; + $htmlHeadXtra[] = ''; } + Display::display_header(''); -$execute_iframe = true; echo '

'; $file_url_web = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$header_file.'?'.api_get_cidreq(); @@ -268,19 +277,17 @@ if (in_array(strtolower($pathinfo['extension']) , array('html', "htm"))) { if ($show_web_odf) { //echo Display::url(get_lang('Show'), api_get_path(WEB_CODE_PATH).'document/edit_odf.php?id='.$document_data['id'], array('class' => 'btn')); - echo '
'; - $execute_iframe = false; + echo '
'; } echo '
'; -if ($jplayer_supported) { +if ($jplayer_supported) { echo '
'; echo DocumentManager::generate_video_preview($document_data); - echo '
'; - $execute_iframe = false; + echo ''; } -if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web) && api_get_setting('enable_nanogong') == 'true'){ +if ($is_nanogong_available){ echo '
'; echo '
'; echo ''; @@ -289,8 +296,7 @@ if ($pathinfo['extension']=='wav' && preg_match('/_chnano_.wav/i', $file_url_web echo ''; echo ''; echo ''; - echo '
'; - $execute_iframe = false; + echo ''; } if ($execute_iframe) { From e00e2af2655b6c491943eb980c25f1bd570ed8ce Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 15:05:39 +0200 Subject: [PATCH 13/36] Hiding closed hot courses see #5140 --- main/inc/lib/course.lib.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 9ade12cc17..b825beabf8 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3705,13 +3705,18 @@ class CourseManager { foreach ($courses as &$my_course) { $course_info = api_get_course_info($my_course['course_code']); + + if ($course_info['visibility'] = COURSE_VISIBILITY_CLOSED) { + continue; + } + $my_course['extra_info'] = $course_info; $my_course['extra_info']['go_to_course_button'] = ''; //Course visibility if (api_is_platform_admin() || ( $course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || - ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && api_user_is_login()) || in_array($course_info['real_id'], $my_course_code_list) && $course_info['visibility'] != COURSE_VISIBILITY_CLOSED ) + ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && api_user_is_login()) || in_array($course_info['real_id'], $my_course_code_list)) ) { $my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$my_course['extra_info']['path'].'/index.php', array('class' => 'btn btn-primary')); } From 779a379221547ac6afc0569c773cc754370773c2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 15:17:16 +0200 Subject: [PATCH 14/36] Fixing PHP warning --- main/social/message_for_group_form.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/social/message_for_group_form.inc.php b/main/social/message_for_group_form.inc.php index ad39c694b2..cc96e3088f 100644 --- a/main/social/message_for_group_form.inc.php +++ b/main/social/message_for_group_form.inc.php @@ -16,8 +16,8 @@ if (api_get_setting('allow_social_tool') !='true') { api_not_allowed(); } -require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'; require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php'; +require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php'; $tok = Security::get_token(); @@ -112,7 +112,7 @@ $page_topic = !empty($_GET['topics_page_nr'])?intval($_GET['topics_page_nr']):1 - () + ()

From 34f0dcca9745c9326bfb5bb1d56e51a04cbe69f8 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 15:19:34 +0200 Subject: [PATCH 15/36] Minor - fixing message format --- main/social/group_members.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/main/social/group_members.php b/main/social/group_members.php index 2f011fdcbc..4c13b82dca 100644 --- a/main/social/group_members.php +++ b/main/social/group_members.php @@ -57,7 +57,7 @@ if (isset($_GET['action']) && $_GET['action']=='delete') { //if i'm a moderator if (GroupPortalManager::is_group_moderator($group_id)) { GroupPortalManager::delete_user_rel_group($user_join, $group_id); - $show_message = get_lang('UserDeleted'); + $show_message = Display::return_message(get_lang('UserDeleted')); } } @@ -67,7 +67,7 @@ if (isset($_GET['action']) && $_GET['action']=='set_moderator') { //if i'm the admin if (GroupPortalManager::is_group_admin($group_id)) { GroupPortalManager::update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_MODERATOR); - $show_message = get_lang('UserChangeToModerator'); + $show_message = Display::return_message(get_lang('UserChangeToModerator')); } } @@ -77,12 +77,10 @@ if (isset($_GET['action']) && $_GET['action']=='delete_moderator') { //only group admins can do that if (GroupPortalManager::is_group_admin($group_id)) { GroupPortalManager::update_user_role($user_moderator, $group_id, GROUP_USER_PERMISSION_READER); - $show_message = get_lang('UserChangeToReader'); + $show_message = Display::return_message(get_lang('UserChangeToReader')); } } - - $users = GroupPortalManager::get_users_by_group($group_id, false, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_MODERATOR), 0 , 1000); $new_member_list = array(); @@ -92,10 +90,6 @@ $social_right_content = '

'.$group_info['name'].'

'; $social_right_content .= '
'; -if (! empty($show_message)){ - $social_right_content .= Display :: return_message($show_message,'confirmation', false); -} - foreach($users as $user) { switch ($user['relation_type']) { case GROUP_USER_PERMISSION_ADMIN: From f33d9c855e13b313de97582bb51499c3d2afcb2c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 15:41:43 +0200 Subject: [PATCH 16/36] Adding delete topic links see #5203 --- main/css/base.css | 3 +- main/inc/lib/message.lib.php | 85 +++++++++++++++++++++--------------- main/social/group_topics.php | 6 ++- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/main/css/base.css b/main/css/base.css index a7eb8d44d3..ef092ab68d 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -2548,7 +2548,8 @@ div.admin_section h4 { } .topics_grid_item { - /* margin-left:20px; */ + border-bottom: 1px solid #CCCCCC; + margin-bottom: 20px; } #div_content_table { diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index e33fa33f37..4e59abf7ec 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -885,7 +885,8 @@ class MessageManager * @param int group id */ public static function display_messages_for_group($group_id) { - global $my_group_role; + global $my_group_role; + $rows = self::get_messages_by_group($group_id); $topics_per_page = 10; $html_messages = ''; @@ -904,7 +905,7 @@ class MessageManager $new_topics = array(); - foreach($topics as $id => $value) { + foreach ($topics as $id => $value) { $rows = null; $rows = self::get_messages_by_group_by_message($group_id, $value['id']); if (!empty($rows)) { @@ -922,43 +923,59 @@ class MessageManager foreach ($new_topics as $index => $topic) { $html = ''; // topics - $indent = 0; + //$indent = 0; $user_sender_info = UserManager::get_user_info_by_id($topic['user_sender_id']); - $files_attachments = self::get_links_message_attachment_files($topic['id']); + //$files_attachments = self::get_links_message_attachment_files($topic['id']); $name = api_get_person_name($user_sender_info['firstname'], $user_sender_info['lastname']); - $html .= '
'; + $html .= '
'; - $items = $topic['count']; - $reply_label = ($items == 1) ? get_lang('GroupReply'): get_lang('GroupReplies'); - $html .= ''; - //$date. - $html .= Display::div($title.Security::remove_XSS(cut($topic['content'], 150), STUDENT, true).$user_info, array('class'=>'group_discussions_info')).'
'; - $html .= Display::div(Display::tag('span', $items).$reply_label, array('class' =>'group_discussions_replies')); - $html .= ''; - - $topic['title'] = trim($topic['title']); - - if (empty($topic['title'])) { - $topic['title'] = get_lang('Untitled'); - } - $title = Display::tag('h4', Display::url(Security::remove_XSS($topic['title'], STUDENT, true), 'group_topics.php?id='.$group_id.'&topic_id='.$topic['id'])); - - $date = ''; - $link = ''; - if ($topic['send_date']!=$topic['update_date']) { - if (!empty($topic['update_date']) && $topic['update_date'] != '0000-00-00 00:00:00' ) { - $date .= '
'.get_lang('LastUpdate').' '.date_to_str_ago($topic['update_date']).'
'; - } - } else { + $items = $topic['count']; + $reply_label = ($items == 1) ? get_lang('GroupReply'): get_lang('GroupReplies'); + + $html .= '
'; + $html .= Display::div(Display::tag('span', $items).$reply_label, array('class' =>'group_discussions_replies')); + $html .= '
'; + + $topic['title'] = trim($topic['title']); + + if (empty($topic['title'])) { + $topic['title'] = get_lang('Untitled'); + } + + $html .= '
'; + $html .= Display::tag('h4', Display::url(Security::remove_XSS($topic['title'], STUDENT, true), 'group_topics.php?id='.$group_id.'&topic_id='.$topic['id'])); + + if ($my_group_role == GROUP_USER_PERMISSION_ADMIN || $my_group_role == GROUP_USER_PERMISSION_MODERATOR) { + $actions = '
'.Display::url(get_lang('Delete'), api_get_path(WEB_CODE_PATH).'social/group_topics.php?action=delete&id='.$group_id.'&topic_id='.$topic['id'], array('class' => 'btn')); + } + + $date = ''; + if ($topic['send_date']!=$topic['update_date']) { + if (!empty($topic['update_date']) && $topic['update_date'] != '0000-00-00 00:00:00' ) { + $date .= '
'.get_lang('LastUpdate').' '.date_to_str_ago($topic['update_date']).'
'; + } + } else { $date .= '
'.get_lang('Created').' '.date_to_str_ago($topic['send_date']).'
'; - } - $image_path = UserManager::get_user_picture_path_by_id($topic['user_sender_id'], 'web', false, true); - $image_repository = $image_path['dir']; - $existing_image = $image_path['file']; - $user_info = '
'.$name.' '; - $user_info .= '
'.$name.'
'; - $user_info .= '
'.$user.'
'; + } + $html .= $date.$actions; + $html .= '
'; + + $image_path = UserManager::get_user_picture_path_by_id($topic['user_sender_id'], 'web', false, true); + $image_repository = $image_path['dir']; + $existing_image = $image_path['file']; + + $user_info = ''.$name.' '; + $user_info .= '
'.$name.'
'; + $user_info .= ''; + + $html .= '
'; + $html .= $user_info; + $html .= '
'; + //group_topics.php?action=delete&id=3&topic_id=6 + //$date. + + //$html .= Display::div($title.Security::remove_XSS(cut($topic['content'], 150), STUDENT, true).$user_info, array('class'=>'group_discussions_info')).' '.$actions.''; $html .= '
'; //rounded_div diff --git a/main/social/group_topics.php b/main/social/group_topics.php index 6f29634780..bb8ca56d8c 100644 --- a/main/social/group_topics.php +++ b/main/social/group_topics.php @@ -37,10 +37,12 @@ if (empty($group_id)) { } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') { - if (api_is_platform_admin()) { + $group_role = GroupPortalManager::get_user_group_role(api_get_user_id(), $group_id); + + if (api_is_platform_admin() || in_array($group_role, array(GROUP_USER_PERMISSION_ADMIN, GROUP_USER_PERMISSION_MODERATOR))) { GroupPortalManager::delete_topic($group_id, $topic_id); header("Location: groups.php?id=$group_id&action=show_message&msg=topic_deleted"); - } + } } // save message group From 3a27a490b0e9b628e5562b575163043a2354ed77 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 16:39:49 +0200 Subject: [PATCH 17/36] Fixing js errors see #5214 --- main/newscorm/lp_view.php | 7 ++++++- main/newscorm/scorm_api.php | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/main/newscorm/lp_view.php b/main/newscorm/lp_view.php index 3a8d214b02..bfe5499a4a 100644 --- a/main/newscorm/lp_view.php +++ b/main/newscorm/lp_view.php @@ -414,7 +414,12 @@ if (Database::num_rows($res_media) > 0) { var hauteurHeader = document.getElementById('header').offsetHeight; var hauteurAuthorImg = document.getElementById('author_image').offsetHeight; var hauteurAuthorName = document.getElementById('author_name').offsetHeight; - var hauteurMedia = document.getElementById('lp_media_file').offsetHeight; + + var hauteurMedia = 0; + if ($("#lp_media_file").length != 0) { + hauteurMedia = document.getElementById('lp_media_file').offsetHeight; + } + var hauteurTitre = document.getElementById('scorm_title').offsetHeight; var hauteurAction = 0; if (document.getElementById('actions_lp')) hauteurAction = document.getElementById('actions_lp').offsetHeight; diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index a3b8e6da18..bc9b54e04b 100644 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1495,7 +1495,9 @@ function switch_item(current_item, next_item){ url: "lp_nav.php", data: "", success: function(tmp_data) { - $("#lp_media_file").html(tmp_data); + if ($("#lp_media_file").length != 0) { + $("#lp_media_file").html(tmp_data); + } } }); return true; From 515c0a5b3b4527b8d872781698a21d148b0d3c1c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 17:15:19 +0200 Subject: [PATCH 18/36] Adding known issue with hotspots see #3980 --- documentation/changelog.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/documentation/changelog.html b/documentation/changelog.html index 1fb05be244..9867d3d152 100644 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -200,11 +200,10 @@ This version of Chamilo only includes new features:

Known issues

    -
  • - Document title: The option to NOT use a document title different than the filename in the documents tool has been removed. This means that if this setting was not set to the default option in your Chamilo option or if you have a very old installation that you have been upgrading over the years, you might experience problems accessing the documents. In this case, we recommend contacting an official provider of Chamilo to take this migration in charge. -
  • +
  • Document title: The option to NOT use a document title different than the filename in the documents tool has been removed. This means that if this setting was not set to the default option in your Chamilo option or if you have a very old installation that you have been upgrading over the years, you might experience problems accessing the documents. In this case, we recommend contacting an official provider of Chamilo to take this migration in charge.
  • During upgrade, if your database ends with "c_", the installation process will report errors in the PHP error log. This is due to a check on the new c_id field for database normalization, but is not important. The corresponding logging code can be disabled in database.lib.php
  • Agenda regression: because we implemented a much more usable and familiar agenda for most of you, and because we lacked some time to go into the details, we have temporarily removed the possibility to make an event visible to specific users (they are always visible to all the course users right now) - see task #5201 for details
  • +
  • Exercises: When reviewing an exercise, hotspot questions results are not remembered see #3980

Third-Party Libraries additions/updates

@@ -684,7 +683,7 @@ This version of Chamilo only includes a few minor new features:
  • If you used split users directories before v1.8.8 in combination with the "My files" feature (if it existed at all at that point), you will probably have a problem now, as the code in the previous version was wrong and was saving the personal portfolio file in another directory than the user's. Sorry about that. If you need professional assistance, see the http://www.chamilo.org/ website under support -> professional support for official providers who could help you. And don't forget to keep a backup. If you don't understand a thing about what I'm talking about, you are probable not concerned by this bug, so don't worry too much.
  • For some reason, we have been reported unsuccessful migrations from 1.8.7 to 1.8.7.1 whereby the course_rel_user table was not integrally copied. We recommend keeping your database backup until you're sure every student/course relationship was copied (comparing the lines in the table before and after migration might help you)
  • Document tool: when moving an HTML file using the "move" funcionality, images, videos and any incrusted file in that HTML will not be moved automatically see #1278
  • -
  • Hotpotatoes: When taking a Hotpotato exam added to Chamilo there is a javascript error, this bug can be only reproduced using Google Chrome see #3332
  • +
  • Hotpotatoes: When taking a Hotpotato exam added to Chamilo there is a javascript error, this bug can be only reproduced using Google Chrome see #3332
  • Deprecated features

    From 5186a7750d964d03e8457b3a085ac2b08d676f2d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 18:14:57 +0200 Subject: [PATCH 19/36] Should fix bug that enables inactive users to ask email passwords see #3855 --- main/auth/lostPassword.php | 34 +++++-------------------------- main/inc/lib/login.lib.php | 41 ++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/main/auth/lostPassword.php b/main/auth/lostPassword.php index 5842d083d2..7dd2e6327d 100644 --- a/main/auth/lostPassword.php +++ b/main/auth/lostPassword.php @@ -109,36 +109,12 @@ if (isset($_GET['reset']) && isset($_GET['id'])) { if ($form->validate()) { $values = $form->exportValues(); + + $users_related_to_username = Login::get_user_accounts_by_username($values['user']); - if(strpos($values['user'],'@')){ - $user = strtolower($values['user']); - $email = TRUE; - } else { - $user = strtolower($values['user']); - $email = FALSE; - } - - $condition = ''; - if ($email) { - $condition = "LOWER(email) = '".Database::escape_string($user)."' "; - } else { - $condition = "LOWER(username) = '".Database::escape_string($user)."'"; - } - - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); - $query = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, ". - "username AS loginName, password, email, status AS status, ". - "official_code, phone, picture_uri, creator_id ". - "FROM ".$tbl_user." ". - "WHERE ( $condition ) "; - - $result = Database::query($query); - $num_rows = Database::num_rows($result); - - if ($result && $num_rows > 0) { - $by_username = true; - $users = Database::store_result($result); - foreach ($users as $user ) { + if ($users_related_to_username) { + $by_username = true; + foreach ($users_related_to_username as $user) { if ($_configuration['password_encryption'] != 'none') { Login::handle_encrypted_password($user, $by_username); } else { diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index 7299389903..a17ea10f4e 100644 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -21,7 +21,7 @@ class Login /** * Get user account list * - * @param unknown_type $user + * @param array $user array with keys: email, password, uid, loginName * @param boolean $reset * @param boolean $by_username * @return unknown @@ -80,7 +80,7 @@ class Login /** * This function sends the actual password to the user * - * @param unknown_type $user + * @param int $user * @author Olivier Cauberghe , Ghent University */ public static function send_password_to_user($user, $by_username = false) @@ -125,8 +125,7 @@ class Login * * @author Olivier Cauberghe , Ghent University */ - public static function handle_encrypted_password($user, $by_username = false) - { + public static function handle_encrypted_password($user, $by_username = false) { global $_configuration; $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT @@ -785,5 +784,39 @@ class Login } } } + + /** + * Returns true if user exists in the platform when asking the password + * + * @param string $username (email or username) + * @return boolean + */ + function get_user_accounts_by_username($username) { + if (strpos($username,'@')){ + $username = api_strtolower($username); + $email = true; + } else { + $username = api_strtolower($username); + $email = false; + } + $condition = ''; + if ($email) { + $condition = "LOWER(email) = '".Database::escape_string($username)."' "; + } else { + $condition = "LOWER(username) = '".Database::escape_string($username)."'"; + } + + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); + $query = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email, + status AS status, official_code, phone, picture_uri, creator_id + FROM $tbl_user + WHERE ( $condition AND active = 1) "; + $result = Database::query($query); + $num_rows = Database::num_rows($result); + if ($result && $num_rows > 0) { + return Database::store_result($result); + } + return false; + } } From 145b1d05bf590a13e652059df4b14d20c443cde2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 18:17:04 +0200 Subject: [PATCH 20/36] Minor - cosmetic changes --- main/inc/lib/group_portal_manager.lib.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index 36f4c73859..e10d06cc7a 100644 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -156,8 +156,7 @@ class GroupPortalManager { public static function get_group_data($group_id) { $table = Database :: get_main_table(TABLE_MAIN_GROUP); - $group_id = intval($group_id); - $user_condition = ''; + $group_id = intval($group_id); $sql = "SELECT id, name, description, picture_uri, url, visibility FROM $table WHERE id = $group_id "; $res = Database::query($sql); $item = array(); @@ -296,8 +295,7 @@ class GroupPortalManager { $tag = Database :: get_main_table(TABLE_MAIN_TAG); $table_group_rel_tag = Database :: get_main_table(TABLE_MAIN_GROUP_REL_TAG); $group_id = intval($group_id); - $user_condition = ''; - + $sql = "SELECT tag FROM $tag t INNER JOIN $table_group_rel_tag gt ON (gt.tag_id= t.id) WHERE gt.group_id = $group_id "; $res = Database::query($sql); $tags = array(); @@ -326,8 +324,7 @@ class GroupPortalManager { * @return array Database::store_result of the result * @author Julio Montoya * */ - public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) { - $where = ''; + public static function get_groups_by_user($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) { $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); $user_id = intval($user_id); @@ -365,8 +362,7 @@ class GroupPortalManager { * @return array with group content * @author Julio Montoya * */ - public static function get_groups_by_popularity($num = 6, $with_image = true) { - $where = ''; + public static function get_groups_by_popularity($num = 6, $with_image = true) { $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); if (empty($num)) { @@ -403,8 +399,7 @@ class GroupPortalManager { * @return array with group content * @author Julio Montoya * */ - public static function get_groups_by_age($num = 6, $with_image = true) { - $where = ''; + public static function get_groups_by_age($num = 6, $with_image = true) { $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); @@ -647,7 +642,7 @@ class GroupPortalManager { $sql = "UPDATE $table_group_rel_user SET relation_type = ".intval($relation_type)." WHERE user_id = $user_id AND group_id = $group_id" ; - $result = Database::query($sql); + Database::query($sql); } @@ -823,8 +818,7 @@ class GroupPortalManager { $medium = self::resize_picture($source_file, 85); $normal = self::resize_picture($source_file, 200); - $big = new Image($source_file); // This is the original picture. - $ok = false; + $big = new Image($source_file); // This is the original picture. $ok = $small->send_image($path.'small_'.$filename) && $medium->send_image($path.'medium_'.$filename) && $normal->send_image($path.'big_'.$filename) From f8a460f8ec7e87ebfc91af0606b2fde035095d14 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 19:03:11 +0200 Subject: [PATCH 21/36] Moving code from local to the conditional login see #5217 --- main/admin/configure_inscription.php | 4 -- .../complete_phone_number.php | 6 +-- .../conditional_login/conditional_login.php | 42 ++++++++++++++++--- main/inc/lib/conditional_login.class.php | 11 +++-- main/inc/local.inc.php | 33 ++++----------- 5 files changed, 54 insertions(+), 42 deletions(-) diff --git a/main/admin/configure_inscription.php b/main/admin/configure_inscription.php index 420a136394..3e0077e19b 100644 --- a/main/admin/configure_inscription.php +++ b/main/admin/configure_inscription.php @@ -301,10 +301,6 @@ if (get_setting('allow_terms_conditions') == 'true') { $form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']); $form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']); - /*if (isset($_SESSION['term_and_condition']['user_id']) && isset($_SESSION['term_and_condition']['password'])) { - $form->addElement('hidden', 'login', $_SESSION['term_and_condition']['user_id']); - $form->addElement('hidden', 'password', $_SESSION['term_and_condition']['password']); - }*/ if ($term_preview['type'] == 1) { $form->addElement('checkbox', 'legal_accept', null, get_lang('IHaveReadAndAgree').' '.get_lang('TermsAndConditions').''); $form->addRule('extra_legal_accept', get_lang('ThisFieldIsRequired'), 'required'); diff --git a/main/auth/conditional_login/complete_phone_number.php b/main/auth/conditional_login/complete_phone_number.php index 0a06b0dee3..01fff2f0de 100644 --- a/main/auth/conditional_login/complete_phone_number.php +++ b/main/auth/conditional_login/complete_phone_number.php @@ -1,7 +1,7 @@ 'check_platform_legal', + 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php' +)); + + //array_push($dc_conditions, array( // 'conditional_function' => 'dc_check_phone_number', // 'url' => api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php' @@ -19,7 +31,7 @@ require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; */ function dc_check_phone_number($user){ $uInfo = UserManager::get_user_info_by_id($user['user_id']); - if ( empty($uInfo['phone'])) { + if (empty($uInfo['phone'])) { return true; } return false; @@ -27,5 +39,25 @@ function dc_check_phone_number($user){ function dc_check_first_login($user){ $uInfo = UserManager::get_user_info_by_id($user['user_id']); - return(($uInfo['extra']['already_logged_in'] === 'false')); + return $uInfo['extra']['already_logged_in'] === 'false'; +} + +function check_platform_legal($user) { + if (api_get_setting('allow_terms_conditions') == 'true') { + $term_and_condition_status = api_check_term_condition($user['user_id']); + // @todo not sure why we need the login password and update_term_status + if ($term_and_condition_status === false) { + $_SESSION['term_and_condition'] = array('user_id' => $user['user_id'], + //'login' => $user['username'], + //'password' => $user['password'], + //'update_term_status' => true, + ); + return true; + /*header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php'); + exit;*/ + } else { + unset($_SESSION['term_and_condition']); + } + } + return false; } \ No newline at end of file diff --git a/main/inc/lib/conditional_login.class.php b/main/inc/lib/conditional_login.class.php index 1ede1715f9..ebcd4eb122 100644 --- a/main/inc/lib/conditional_login.class.php +++ b/main/inc/lib/conditional_login.class.php @@ -1,14 +1,17 @@ +/* For licensing terms, see /license.txt */ +/* + * Conditional login + * Used to implement the loading of custom pages + * 2011, Noel Dieschburg + */ class ConditionalLogin { public static function check_conditions($user) { if (file_exists(api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php')) { include_once api_get_path(SYS_PATH).'main/auth/conditional_login/conditional_login.php'; - if (isset($dc_conditions)){ + if (isset($dc_conditions)) { foreach ($dc_conditions as $dc_condition) { if (isset($dc_condition['conditional_function']) && $dc_condition['conditional_function']($user)) { $_SESSION['conditional_login']['uid'] = $user['user_id']; diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index be29b074c8..79227dd52d 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -227,8 +227,8 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) { $login = $_POST['login']; $password = $_POST['password']; } - - //lookup the user in the main database + + //Lookup the user in the main database $user_table = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT user_id, username, password, auth_source, active, expiration_date, status FROM $user_table WHERE username = '".Database::escape_string($login)."'"; @@ -238,38 +238,19 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) { $uData = Database::fetch_array($result); if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) { - //the authentification of this user is managed by Chamilo itself + //The authentification of this user is managed by Chamilo itself $password = api_get_encrypted_password(trim(stripslashes($password))); - - if (api_get_setting('allow_terms_conditions')=='true') { - if ($password == $uData['password'] AND (trim($login) == $uData['username']) OR $cas_login ) { - $temp_user_id = $uData['user_id']; - - $term_and_condition_status = api_check_term_condition($temp_user_id);//false or true - - if ($term_and_condition_status === false) { - $_SESSION['term_and_condition'] = array('user_id' => $temp_user_id, - 'login' => $login, - 'password' => $password, - 'update_term_status' => true, - ); - header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php'); - exit; - } else { - unset($_SESSION['term_and_condition']); - } - } - } - + // Check the user's password - if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) { + if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) { $update_type = UserManager::get_extra_user_data_by_field($uData['user_id'], 'update_type'); $update_type= $update_type['update_type']; if (!empty($extAuthSource[$update_type]['updateUser']) && file_exists($extAuthSource[$update_type]['updateUser'])) { include_once $extAuthSource[$update_type]['updateUser']; } + // Check if the account is active (not locked) - if ($uData['active']=='1') { + if ($uData['active'] == '1') { // Check if the expiration date has not been reached if ($uData['expiration_date'] > date('Y-m-d H:i:s') OR $uData['expiration_date'] == '0000-00-00 00:00:00') { From e0d0a62ddae8caa992841bde8e5c8784c3c5c280 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 19:05:05 +0200 Subject: [PATCH 22/36] Updating validation see #5217 --- main/auth/conditional_login/conditional_login.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/main/auth/conditional_login/conditional_login.php b/main/auth/conditional_login/conditional_login.php index 15d5fdce38..2b4d4c2375 100644 --- a/main/auth/conditional_login/conditional_login.php +++ b/main/auth/conditional_login/conditional_login.php @@ -12,7 +12,7 @@ $dc_conditions = array(); array_push($dc_conditions, array( - 'conditional_function' => 'check_platform_legal', + 'conditional_function' => 'check_platform_legal_conditions', 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php' )); @@ -42,8 +42,8 @@ function dc_check_first_login($user){ return $uInfo['extra']['already_logged_in'] === 'false'; } -function check_platform_legal($user) { - if (api_get_setting('allow_terms_conditions') == 'true') { +function check_platform_legal_conditions($user) { + if (api_get_setting('allow_terms_conditions') == 'true') { $term_and_condition_status = api_check_term_condition($user['user_id']); // @todo not sure why we need the login password and update_term_status if ($term_and_condition_status === false) { @@ -57,7 +57,10 @@ function check_platform_legal($user) { exit;*/ } else { unset($_SESSION['term_and_condition']); + return false; } - } - return false; + } else { + //No validation + return true; + } } \ No newline at end of file From 7a6c0d9518bbeb79b9733f8deb722a67bdd1bd46 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 18 Jul 2012 19:27:53 +0200 Subject: [PATCH 23/36] Hiding user emails if platform setting says so see #5216 --- main/user/subscribe_user.php | 115 +++++++++++++---------------------- main/user/user.php | 24 +++++--- main/user/userInfo.php | 10 ++- 3 files changed, 63 insertions(+), 86 deletions(-) diff --git a/main/user/subscribe_user.php b/main/user/subscribe_user.php index 077c70218c..949d0905f7 100644 --- a/main/user/subscribe_user.php +++ b/main/user/subscribe_user.php @@ -201,8 +201,11 @@ if (api_is_western_name_order()) { $table->set_header($col ++, get_lang('LastName')); $table->set_header($col ++, get_lang('FirstName')); } -$table->set_header($col ++, get_lang('Email')); -$table->set_column_filter($col -1, 'email_filter'); + +if (api_get_setting('show_email_addresses') == 'true') { + $table->set_header($col ++, get_lang('Email')); + $table->set_column_filter($col -1, 'email_filter'); +} $table->set_header($col ++, get_lang('Active'),false); $table->set_column_filter($col -1, 'active_filter'); $table->set_header($col ++, get_lang('Actions'), false); @@ -248,7 +251,7 @@ function get_number_of_users() { $url_access_id = api_get_current_access_url_id(); if ($url_access_id !=-1) { $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql = "SELECT COUNT(u.user_id) FROM $user_table u + $sql = "SELECT COUNT(u.user_id) FROM $user_table u LEFT JOIN $tbl_session_rel_course_user cu on u.user_id = cu.id_user and course_code='".api_get_course_id()."' AND id_session ='".api_get_session_id()."' INNER JOIN $tbl_url_rel_user as url_rel_user ON (url_rel_user.user_id = u.user_id) @@ -293,7 +296,7 @@ function get_number_of_users() { } } } else { - $sql = "SELECT COUNT(u.user_id) + $sql = "SELECT COUNT(u.user_id) FROM $user_table u LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'"; @@ -383,23 +386,39 @@ function get_user_data($from, $number_of_items, $column, $direction) { $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES); - - // adding teachers + + // adding teachers $is_western_name_order = api_is_western_name_order(); + + if (api_get_setting('show_email_addresses') == 'true') { + + $select_fields = "u.user_id AS col0, + u.official_code AS col1, + ".($is_western_name_order + ? "u.firstname AS col2, + u.lastname AS col3," + : "u.lastname AS col2, + u.firstname AS col3,")." + u.email AS col4, + u.active AS col5, + u.user_id AS col6"; + } else { + $select_fields = "u.user_id AS col0, + u.official_code AS col1, + ".($is_western_name_order + ? "u.firstname AS col2, + u.lastname AS col3," + : "u.lastname AS col2, + u.firstname AS col3,")." + u.active AS col4, + u.user_id AS col5"; + } + + if (isset($_REQUEST['type']) && $_REQUEST['type']=='teacher') { // adding a teacher through a session if (!empty($_SESSION["id_session"])) { - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $tbl_session_rel_course_user cu on u.user_id = cu.id_user AND course_code='".$_SESSION['_course']['id']."' AND id_session ='".$_SESSION["id_session"]."' "; @@ -417,17 +436,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { } } else { // adding a teacher NOT through a session - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'"; @@ -449,17 +458,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { $url_access_id = api_get_current_access_url_id(); if ($url_access_id !=-1) { $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."' INNER JOIN $tbl_url_rel_user as url_rel_user ON (url_rel_user.user_id = u.user_id) "; @@ -482,17 +481,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { } else { // adding a student if (!empty($_SESSION["id_session"])) { - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $tbl_session_rel_course_user cu on u.user_id = cu.id_user and course_code='".$_SESSION['_course']['id']."' AND id_session ='".$_SESSION["id_session"]."' "; @@ -510,17 +499,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { } } else { - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'"; @@ -544,17 +523,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { if ($url_access_id !=-1) { $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".($is_western_name_order - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.email AS col4, - u.active AS col5, - u.user_id AS col6 + $sql = "SELECT $select_fields FROM $user_table u LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."' INNER JOIN $tbl_url_rel_user as url_rel_user @@ -608,7 +577,7 @@ function get_user_data($from, $number_of_items, $column, $direction) { $res = Database::query($sql); $users = array (); - while ($user = Database::fetch_row($res)) { + while ($user = Database::fetch_row($res)) { $users[] = $user; $_SESSION['session_user_id'][] = $user[0]; if ($is_western_name_order) { diff --git a/main/user/user.php b/main/user/user.php index b976eecc7f..4459d23f50 100644 --- a/main/user/user.php +++ b/main/user/user.php @@ -89,11 +89,21 @@ if (api_is_allowed_to_edit(null, true)) { $extra_fields = UserManager::get_extra_user_data(api_get_user_id(), false, false, false, true); $extra_fields = array_keys($extra_fields); - if ($sort_by_first_name) { - $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); - } else { - $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); - } + $select_email_condition = ''; + if (api_get_setting('show_email_addresses') == 'true') { + $select_email_condition = ' user.email, '; + if ($sort_by_first_name) { + $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); + } else { + $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); + } + } else { + if ($sort_by_first_name) { + $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); + } else { + $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active')); + } + } $legal = ''; @@ -116,7 +126,7 @@ if (api_is_allowed_to_edit(null, true)) { if (api_get_setting('use_session_mode') == 'true') { if (api_get_session_id()) { $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.email, phone, user.official_code, active $legal + $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", $select_email_condition phone, user.official_code, active $legal FROM $table_session_course_user as session_course_user, $table_users as user "; if ($_configuration['multiple_access_urls']) { $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; @@ -170,7 +180,7 @@ if (api_is_allowed_to_edit(null, true)) { // users directly subscribed to the course $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.email, phone, user.official_code, active $legal + $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", $select_email_condition phone, user.official_code, active $legal FROM $table_course_user as course_user, $table_users as user "; if ($_configuration['multiple_access_urls']) { $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; diff --git a/main/user/userInfo.php b/main/user/userInfo.php index c6f84ecfd4..1868f94c6d 100644 --- a/main/user/userInfo.php +++ b/main/user/userInfo.php @@ -402,8 +402,10 @@ elseif ($displayMode == "viewContentEdit") { echo "\n", "", "", "\n"; - - echo "

    ".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."

    "; + + if (api_get_setting('show_email_addresses') == 'true') { + echo "

    ".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."

    "; + } if (api_get_setting('extended_profile') == 'true') { if (!empty($mainUserInfo['competences'])) @@ -522,10 +524,6 @@ elseif ($displayMode == "viewContentEdit") { if (api_get_setting("show_email_addresses") == "true") { echo "

    ". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "

    "; - } else { - if (api_is_allowed_to_edit()) { - echo "

    ". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "

    "; - } } if (api_get_setting('extended_profile') == 'true') { From 2e489db15f54e59bbdc4e3ffb32c87490ced2a7d Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 18 Jul 2012 16:00:25 -0500 Subject: [PATCH 24/36] Minor - code indentation fix --- main/inc/local.inc.php | 1042 ++++++++++++++++++++-------------------- 1 file changed, 521 insertions(+), 521 deletions(-) diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index 79227dd52d..1b01a67a1e 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -92,7 +92,7 @@ * reset, setting correctly $cidReset (for course) and $gidReset (for group). * * 3. If needed, the script retrieves the other user informations (first name, - * last name, ...) and stores them in session. + * last name, ...) and stores them in session. * * 4. If needed, the script retrieves the course information and stores them * in session @@ -109,8 +109,8 @@ */ /* - INIT SECTION - variables should be initialised here + INIT SECTION + variables should be initialised here */ //require_once api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'; moved to autologin @@ -120,15 +120,15 @@ use \ChamiloSession as Session; //Conditional login if (isset($_SESSION['conditional_login']['uid']) && $_SESSION['conditional_login']['can_login']=== true){ - $uData = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']); - ConditionalLogin::check_conditions($uData); - - $_user['user_id'] = $_SESSION['conditional_login']['uid']; - $_user['status'] = $uData['status']; - Session::write('_user',$_user); - Session::erase('conditional_login'); - $uidReset=true; - event_login(); + $uData = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']); + ConditionalLogin::check_conditions($uData); + + $_user['user_id'] = $_SESSION['conditional_login']['uid']; + $_user['status'] = $uData['status']; + Session::write('_user',$_user); + Session::erase('conditional_login'); + $uidReset=true; + event_login(); } // parameters passed via GET @@ -155,382 +155,382 @@ $gidReset = isset($gidReset) ? $gidReset : ''; // parameters passed via POST $login = isset($_POST["login"]) ? $_POST["login"] : ''; -/* MAIN CODE */ +/* MAIN CODE */ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) { - // uid is in session => login already done, continue with this value - $_user['user_id'] = $_SESSION['_user']['user_id']; + // uid is in session => login already done, continue with this value + $_user['user_id'] = $_SESSION['_user']['user_id']; //Check if we have to reset user data //This param can be used to reload user data if user has been logged by external script if (isset($_SESSION['_user']['uidReset']) && $_SESSION['_user']['uidReset']){ $uidReset=true; } } else { - if (isset($_user['user_id'])) { - unset($_user['user_id']); - } - - if (api_get_setting('allow_terms_conditions') == 'true') { - if (isset($_POST['login']) && isset($_POST['password']) && isset($_SESSION['term_and_condition']['user_id'])) { - $user_id = $_SESSION['term_and_condition']['user_id']; // user id - // Update the terms & conditions + if (isset($_user['user_id'])) { + unset($_user['user_id']); + } + + if (api_get_setting('allow_terms_conditions') == 'true') { + if (isset($_POST['login']) && isset($_POST['password']) && isset($_SESSION['term_and_condition']['user_id'])) { + $user_id = $_SESSION['term_and_condition']['user_id']; // user id + // Update the terms & conditions $legal_type = null; - //verify type of terms and conditions + //verify type of terms and conditions if (isset($_POST['legal_info'])) { $info_legal = explode(':', $_POST['legal_info']); $legal_type = LegalManager::get_type_of_terms_and_conditions($info_legal[0], $info_legal[1]); } - //is necessary verify check - if ($legal_type == 1) { - if ((isset($_POST['legal_accept']) && $_POST['legal_accept']=='1')) { - $legal_option = true; - } else { - $legal_option = false; - } - } - - //no is check option - if ($legal_type == 0) { - $legal_option=true; - } - - if (isset($_POST['legal_accept_type']) && $legal_option===true) { - $cond_array = explode(':',$_POST['legal_accept_type']); - if (!empty($cond_array[0]) && !empty($cond_array[1])){ - $time = time(); - $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time; - UserManager::update_extra_field_value($user_id,'legal_accept',$condition_to_save); - } - } - } - } - - //IF cas is activated and user isn't logged in - if (api_get_setting('cas_activate') == 'true') { - $cas_activated = true; - } else { - $cas_activated = false; - } - - $cas_login=false; - if ($cas_activated AND !isset($_user['user_id']) and !isset($_POST['login']) && !$logout) { - require_once(api_get_path(SYS_PATH).'main/auth/cas/authcas.php'); - $cas_login = cas_is_authenticated(); - } - if ( ( isset($_POST['login']) AND isset($_POST['password']) ) OR ($cas_login) ) { - - // $login && $password are given to log in - if ( $cas_login && empty($_POST['login']) ) { - $login = $cas_login; - } else { - $login = $_POST['login']; - $password = $_POST['password']; - } + //is necessary verify check + if ($legal_type == 1) { + if ((isset($_POST['legal_accept']) && $_POST['legal_accept']=='1')) { + $legal_option = true; + } else { + $legal_option = false; + } + } + + //no is check option + if ($legal_type == 0) { + $legal_option=true; + } + + if (isset($_POST['legal_accept_type']) && $legal_option===true) { + $cond_array = explode(':',$_POST['legal_accept_type']); + if (!empty($cond_array[0]) && !empty($cond_array[1])){ + $time = time(); + $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time; + UserManager::update_extra_field_value($user_id,'legal_accept',$condition_to_save); + } + } + } + } + + //IF cas is activated and user isn't logged in + if (api_get_setting('cas_activate') == 'true') { + $cas_activated = true; + } else { + $cas_activated = false; + } + + $cas_login=false; + if ($cas_activated AND !isset($_user['user_id']) and !isset($_POST['login']) && !$logout) { + require_once(api_get_path(SYS_PATH).'main/auth/cas/authcas.php'); + $cas_login = cas_is_authenticated(); + } + if ( ( isset($_POST['login']) AND isset($_POST['password']) ) OR ($cas_login) ) { + + // $login && $password are given to log in + if ( $cas_login && empty($_POST['login']) ) { + $login = $cas_login; + } else { + $login = $_POST['login']; + $password = $_POST['password']; + } - //Lookup the user in the main database - $user_table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT user_id, username, password, auth_source, active, expiration_date, status FROM $user_table - WHERE username = '".Database::escape_string($login)."'"; - $result = Database::query($sql); + //Lookup the user in the main database + $user_table = Database::get_main_table(TABLE_MAIN_USER); + $sql = "SELECT user_id, username, password, auth_source, active, expiration_date, status FROM $user_table + WHERE username = '".Database::escape_string($login)."'"; + $result = Database::query($sql); - if (Database::num_rows($result) > 0) { - $uData = Database::fetch_array($result); + if (Database::num_rows($result) > 0) { + $uData = Database::fetch_array($result); - if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) { - //The authentification of this user is managed by Chamilo itself + if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) { + //The authentification of this user is managed by Chamilo itself $password = api_get_encrypted_password(trim(stripslashes($password))); - - // Check the user's password - if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) { + + // Check the user's password + if ( ($password == $uData['password'] OR $cas_login) AND (trim($login) == $uData['username'])) { $update_type = UserManager::get_extra_user_data_by_field($uData['user_id'], 'update_type'); $update_type= $update_type['update_type']; if (!empty($extAuthSource[$update_type]['updateUser']) && file_exists($extAuthSource[$update_type]['updateUser'])) { include_once $extAuthSource[$update_type]['updateUser']; } - // Check if the account is active (not locked) - if ($uData['active'] == '1') { + // Check if the account is active (not locked) + if ($uData['active'] == '1') { - // Check if the expiration date has not been reached + // Check if the expiration date has not been reached if ($uData['expiration_date'] > date('Y-m-d H:i:s') OR $uData['expiration_date'] == '0000-00-00 00:00:00') { - global $_configuration; + global $_configuration; if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) { - //Check if user is an admin + //Check if user is an admin $my_user_is_admin = UserManager::is_admin($uData['user_id']); - // This user is subscribed in these sites => $my_url_list - $my_url_list = api_get_access_url_from_user($uData['user_id']); - - //Check the access_url configuration setting if the user is registered in the access_url_rel_user table - //Getting the current access_url_id of the platform - $current_access_url_id = api_get_current_access_url_id(); - - if ($my_user_is_admin === false) { - - if (is_array($my_url_list) && count($my_url_list)>0 ) { - // the user have the permissions to enter at this site - if (in_array($current_access_url_id, $my_url_list)) { - ConditionalLogin::check_conditions($uData); - - $_user['user_id'] = $uData['user_id']; - $_user['status'] = $uData['status']; - Session::write('_user',$_user); - event_login(); - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); - exit; - } - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); - exit; - } - } else { //Only admins of the "main" (first) Chamilo portal can login wherever they want - //var_dump($current_access_url_id, $my_url_list); exit; - if (in_array(1, $my_url_list)) { //Check if this admin have the access_url_id = 1 which means the principal - ConditionalLogin::check_conditions($uData); - $_user['user_id'] = $uData['user_id']; - $_user['status'] = $uData['status']; - Session::write('_user',$_user); - event_login(); - } else { - //This means a secondary admin wants to login so we check as he's a normal user - if (in_array($current_access_url_id, $my_url_list)) { - $_user['user_id'] = $uData['user_id']; - $_user['status'] = $uData['status']; - Session::write('_user',$_user); - event_login(); - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); - exit; - } - } - } + // This user is subscribed in these sites => $my_url_list + $my_url_list = api_get_access_url_from_user($uData['user_id']); + + //Check the access_url configuration setting if the user is registered in the access_url_rel_user table + //Getting the current access_url_id of the platform + $current_access_url_id = api_get_current_access_url_id(); + + if ($my_user_is_admin === false) { + + if (is_array($my_url_list) && count($my_url_list)>0 ) { + // the user have the permissions to enter at this site + if (in_array($current_access_url_id, $my_url_list)) { + ConditionalLogin::check_conditions($uData); + + $_user['user_id'] = $uData['user_id']; + $_user['status'] = $uData['status']; + Session::write('_user',$_user); + event_login(); + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); + exit; + } + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); + exit; + } + } else { //Only admins of the "main" (first) Chamilo portal can login wherever they want + //var_dump($current_access_url_id, $my_url_list); exit; + if (in_array(1, $my_url_list)) { //Check if this admin have the access_url_id = 1 which means the principal + ConditionalLogin::check_conditions($uData); + $_user['user_id'] = $uData['user_id']; + $_user['status'] = $uData['status']; + Session::write('_user',$_user); + event_login(); + } else { + //This means a secondary admin wants to login so we check as he's a normal user + if (in_array($current_access_url_id, $my_url_list)) { + $_user['user_id'] = $uData['user_id']; + $_user['status'] = $uData['status']; + Session::write('_user',$_user); + event_login(); + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=access_url_inactive'); + exit; + } + } + } } else { //error_log('Loggedin'); - ConditionalLogin::check_conditions($uData); + ConditionalLogin::check_conditions($uData); $_user['user_id'] = $uData['user_id']; $_user['status'] = $uData['status']; Session::write('_user',$_user); event_login(); - } - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=account_expired'); - exit; - } - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=account_inactive'); - exit; - } - } else { - // login failed: username or password incorrect - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'); - exit; - } - - if (isset($uData['creator_id']) && $_user['user_id'] != $uData['creator_id']) { - //first login for a not self registred - //e.g. registered by a teacher - //do nothing (code may be added later) - } - } elseif (!empty($extAuthSource[$uData['auth_source']]['login']) && file_exists($extAuthSource[$uData['auth_source']]['login'])) { - /* - * Process external authentication - * on the basis of the given login name - */ - $loginFailed = true; // Default initialisation. It could - // change after the external authentication - $key = $uData['auth_source']; //'ldap','shibboleth'... - /* >>>>>>>> External authentication modules <<<<<<<<< */ - // see configuration.php to define these - include_once($extAuthSource[$key]['login']); - /* >>>>>>>> External authentication modules <<<<<<<<< */ - } else { // no standard Chamilo login - try external authentification - //huh... nothing to do... we shouldn't get here - error_log('Chamilo Authentication file '. $extAuthSource[$uData['auth_source']]['login']. ' could not be found - this might prevent your system from doing the corresponding authentication process',0); - } - } else { - // login failed, Database::num_rows($result) <= 0 - $loginFailed = true; // Default initialisation. It could - // change after the external authentication - - /* - * In this section: - * there is no entry for the $login user in the Chamilo - * database. This also means there is no auth_source for the user. - * We let all external procedures attempt to add him/her - * to the system. - * - * Process external login on the basis - * of the authentication source list - * provided by the configuration settings. - * If the login succeeds, for going further, - * Chamilo needs the $_user['user_id'] variable to be - * set and registered in the session. It's the - * responsability of the external login script - * to provide this $_user['user_id']. - */ - - if (isset($extAuthSource) && is_array($extAuthSource)) { - foreach($extAuthSource as $thisAuthSource) { - if (!empty($thisAuthSource['newUser']) && file_exists($thisAuthSource['newUser'])) { - include_once($thisAuthSource['newUser']); - } else { - error_log('Chamilo Authentication file '. $thisAuthSource['newUser']. ' could not be found - this might prevent your system from using the authentication process in the user creation process',0); - } - } - } //end if is_array($extAuthSource) - if ($loginFailed) { //If we are here username given is wrong - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'); - } - } //end else login failed - } elseif (api_get_setting('sso_authentication')==='true' && !in_array('webservices', explode('/', $_SERVER['REQUEST_URI']))) { - /** - * TODO: - * - Work on a better validation for webservices paths. Current is very poor and exit - */ - $subsso = api_get_setting('sso_authentication_subclass'); - //require_once(api_get_path(SYS_CODE_PATH).'auth/sso/sso.class.php'); moved to autologin - if (!empty($subsso)) { - require_once(api_get_path(SYS_CODE_PATH).'auth/sso/sso.'.$subsso.'.class.php'); - $subsso = 'sso'.$subsso; - $osso = new $subsso(); //load the subclass - } else { - $osso = new sso(); - } - if (isset($_SESSION['_user']['user_id'])) { - if ($logout) { - // Make custom redirect after logout - online_logout($_SESSION['_user']['user_id'], false); - $osso->logout(); //redirects and exits - } - } elseif(!$logout) { - // Handle cookie comming from Master Server - if (!isset($_GET['sso_referer']) && !isset($_GET['loginFailed'])) { - // Redirect to master server - $osso->ask_master(); - } elseif (isset($_GET['sso_cookie'])) { - // Here we are going to check the origin of - // what the call says should be used for - // authentication, and ensure we know it - $matches_domain = false; - if (isset($_GET['sso_referer'])) { - $protocol = api_get_setting('sso_authentication_protocol'); - // sso_authentication_domain can list - // several, comma-separated, domains - $master_urls = split(',',api_get_setting('sso_authentication_domain')); - if (!empty($master_urls)) { - $master_auth_uri = api_get_setting('sso_authentication_auth_uri'); - foreach ($master_urls as $mu) { - if (empty($mu)) { continue; } - // for each URL, check until we find *one* that matches the $_GET['sso_referer'], then skip the rest - if ($protocol.trim($mu).$master_auth_uri === $_GET['sso_referer']) { - $matches_domain = true; - break; - } - } - } else { - error_log('Your sso_authentication_master param is empty. Check the platform configuration, security section. It can be a list of comma-separated domains'); - } - } - if ($matches_domain) { + } + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=account_expired'); + exit; + } + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=account_inactive'); + exit; + } + } else { + // login failed: username or password incorrect + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'); + exit; + } + + if (isset($uData['creator_id']) && $_user['user_id'] != $uData['creator_id']) { + //first login for a not self registred + //e.g. registered by a teacher + //do nothing (code may be added later) + } + } elseif (!empty($extAuthSource[$uData['auth_source']]['login']) && file_exists($extAuthSource[$uData['auth_source']]['login'])) { + /* + * Process external authentication + * on the basis of the given login name + */ + $loginFailed = true; // Default initialisation. It could + // change after the external authentication + $key = $uData['auth_source']; //'ldap','shibboleth'... + /* >>>>>>>> External authentication modules <<<<<<<<< */ + // see configuration.php to define these + include_once($extAuthSource[$key]['login']); + /* >>>>>>>> External authentication modules <<<<<<<<< */ + } else { // no standard Chamilo login - try external authentification + //huh... nothing to do... we shouldn't get here + error_log('Chamilo Authentication file '. $extAuthSource[$uData['auth_source']]['login']. ' could not be found - this might prevent your system from doing the corresponding authentication process',0); + } + } else { + // login failed, Database::num_rows($result) <= 0 + $loginFailed = true; // Default initialisation. It could + // change after the external authentication + + /* + * In this section: + * there is no entry for the $login user in the Chamilo + * database. This also means there is no auth_source for the user. + * We let all external procedures attempt to add him/her + * to the system. + * + * Process external login on the basis + * of the authentication source list + * provided by the configuration settings. + * If the login succeeds, for going further, + * Chamilo needs the $_user['user_id'] variable to be + * set and registered in the session. It's the + * responsability of the external login script + * to provide this $_user['user_id']. + */ + + if (isset($extAuthSource) && is_array($extAuthSource)) { + foreach($extAuthSource as $thisAuthSource) { + if (!empty($thisAuthSource['newUser']) && file_exists($thisAuthSource['newUser'])) { + include_once($thisAuthSource['newUser']); + } else { + error_log('Chamilo Authentication file '. $thisAuthSource['newUser']. ' could not be found - this might prevent your system from using the authentication process in the user creation process',0); + } + } + } //end if is_array($extAuthSource) + if ($loginFailed) { //If we are here username given is wrong + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'); + } + } //end else login failed + } elseif (api_get_setting('sso_authentication')==='true' && !in_array('webservices', explode('/', $_SERVER['REQUEST_URI']))) { + /** + * TODO: + * - Work on a better validation for webservices paths. Current is very poor and exit + */ + $subsso = api_get_setting('sso_authentication_subclass'); + //require_once(api_get_path(SYS_CODE_PATH).'auth/sso/sso.class.php'); moved to autologin + if (!empty($subsso)) { + require_once(api_get_path(SYS_CODE_PATH).'auth/sso/sso.'.$subsso.'.class.php'); + $subsso = 'sso'.$subsso; + $osso = new $subsso(); //load the subclass + } else { + $osso = new sso(); + } + if (isset($_SESSION['_user']['user_id'])) { + if ($logout) { + // Make custom redirect after logout + online_logout($_SESSION['_user']['user_id'], false); + $osso->logout(); //redirects and exits + } + } elseif(!$logout) { + // Handle cookie comming from Master Server + if (!isset($_GET['sso_referer']) && !isset($_GET['loginFailed'])) { + // Redirect to master server + $osso->ask_master(); + } elseif (isset($_GET['sso_cookie'])) { + // Here we are going to check the origin of + // what the call says should be used for + // authentication, and ensure we know it + $matches_domain = false; + if (isset($_GET['sso_referer'])) { + $protocol = api_get_setting('sso_authentication_protocol'); + // sso_authentication_domain can list + // several, comma-separated, domains + $master_urls = split(',',api_get_setting('sso_authentication_domain')); + if (!empty($master_urls)) { + $master_auth_uri = api_get_setting('sso_authentication_auth_uri'); + foreach ($master_urls as $mu) { + if (empty($mu)) { continue; } + // for each URL, check until we find *one* that matches the $_GET['sso_referer'], then skip the rest + if ($protocol.trim($mu).$master_auth_uri === $_GET['sso_referer']) { + $matches_domain = true; + break; + } + } + } else { + error_log('Your sso_authentication_master param is empty. Check the platform configuration, security section. It can be a list of comma-separated domains'); + } + } + if ($matches_domain) { //make all the process of checking //if the user exists (delegated to the sso class) $osso->check_user(); - } else { - error_log('Check the sso_referer URL in your script, it doesn\'t match any of the possibilities'); - //Request comes from unknown source - $loginFailed = true; - Session::erase('_uid'); - header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=unrecognize_sso_origin'); - exit; - } - } - }//end logout ... else ... login - } elseif (api_get_setting('openid_authentication')=='true') { - if (!empty($_POST['openid_url'])) { - include 'main/auth/openid/login.php'; - openid_begin(trim($_POST['openid_url']),api_get_path(WEB_PATH).'index.php'); - //this last function should trigger a redirect, so we can die here safely - die('Openid login redirection should be in progress'); - } elseif (!empty($_GET['openid_identity'])) { - //it's usual for PHP to replace '.' (dot) by '_' (underscore) in URL parameters - include('main/auth/openid/login.php'); - $res = openid_complete($_GET); - if ($res['status'] == 'success') { - $id1 = Database::escape_string($res['openid.identity']); - //have another id with or without the final '/' - $id2 = (substr($id1,-1,1)=='/'?substr($id1,0,-1):$id1.'/'); - //lookup the user in the main database - $user_table = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT user_id, username, password, auth_source, active, expiration_date - FROM $user_table - WHERE openid = '$id1' - OR openid = '$id2' "; - $result = Database::query($sql); - if ($result !== false) { - if (Database::num_rows($result)>0) { - //$row = Database::fetch_array($res); - $uData = Database::fetch_array($result); - - if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) { - //the authentification of this user is managed by Chamilo itself - - // check if the account is active (not locked) - if ($uData['active']=='1') { - // check if the expiration date has not been reached - if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00') { - $_user['user_id'] = $uData['user_id']; - $_user['status'] = $uData['status']; - - Session::write('_user',$_user); - event_login(); - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: index.php?loginFailed=1&error=account_expired'); - exit; - } - } else { - $loginFailed = true; - Session::erase('_uid'); - header('Location: index.php?loginFailed=1&error=account_inactive'); - exit; - } - if (isset($uData['creator_id']) && $_user['user_id'] != $uData['creator_id']) { - //first login for a not self registred - //e.g. registered by a teacher - //do nothing (code may be added later) - } - } - } else { - //Redirect to the subscription form - header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?username='.$res['openid.sreg.nickname'].'&email='.$res['openid.sreg.email'].'&openid='.$res['openid.identity'].'&openid_msg=idnotfound'); - //$loginFailed = true; - } - } else { - $loginFailed = true; - } - } else { - $loginFailed = true; - } - } - } elseif (KeyAuth::is_enabled()) { + } else { + error_log('Check the sso_referer URL in your script, it doesn\'t match any of the possibilities'); + //Request comes from unknown source + $loginFailed = true; + Session::erase('_uid'); + header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=unrecognize_sso_origin'); + exit; + } + } + }//end logout ... else ... login + } elseif (api_get_setting('openid_authentication')=='true') { + if (!empty($_POST['openid_url'])) { + include 'main/auth/openid/login.php'; + openid_begin(trim($_POST['openid_url']),api_get_path(WEB_PATH).'index.php'); + //this last function should trigger a redirect, so we can die here safely + die('Openid login redirection should be in progress'); + } elseif (!empty($_GET['openid_identity'])) { + //it's usual for PHP to replace '.' (dot) by '_' (underscore) in URL parameters + include('main/auth/openid/login.php'); + $res = openid_complete($_GET); + if ($res['status'] == 'success') { + $id1 = Database::escape_string($res['openid.identity']); + //have another id with or without the final '/' + $id2 = (substr($id1,-1,1)=='/'?substr($id1,0,-1):$id1.'/'); + //lookup the user in the main database + $user_table = Database::get_main_table(TABLE_MAIN_USER); + $sql = "SELECT user_id, username, password, auth_source, active, expiration_date + FROM $user_table + WHERE openid = '$id1' + OR openid = '$id2' "; + $result = Database::query($sql); + if ($result !== false) { + if (Database::num_rows($result)>0) { + //$row = Database::fetch_array($res); + $uData = Database::fetch_array($result); + + if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) { + //the authentification of this user is managed by Chamilo itself + + // check if the account is active (not locked) + if ($uData['active']=='1') { + // check if the expiration date has not been reached + if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00') { + $_user['user_id'] = $uData['user_id']; + $_user['status'] = $uData['status']; + + Session::write('_user',$_user); + event_login(); + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: index.php?loginFailed=1&error=account_expired'); + exit; + } + } else { + $loginFailed = true; + Session::erase('_uid'); + header('Location: index.php?loginFailed=1&error=account_inactive'); + exit; + } + if (isset($uData['creator_id']) && $_user['user_id'] != $uData['creator_id']) { + //first login for a not self registred + //e.g. registered by a teacher + //do nothing (code may be added later) + } + } + } else { + //Redirect to the subscription form + header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?username='.$res['openid.sreg.nickname'].'&email='.$res['openid.sreg.email'].'&openid='.$res['openid.identity'].'&openid_msg=idnotfound'); + //$loginFailed = true; + } + } else { + $loginFailed = true; + } + } else { + $loginFailed = true; + } + } + } elseif (KeyAuth::is_enabled()) { $success = KeyAuth::instance()->login(); if($success) { @@ -538,41 +538,41 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) { } } - // else {} => continue as anonymous user - $uidReset = true; + // else {} => continue as anonymous user + $uidReset = true; - // $cidReset = true; - // $gidReset = true; + // $cidReset = true; + // $gidReset = true; } // end else //Now check for anonymous user mode if (isset($use_anonymous) && $use_anonymous) { - //if anonymous mode is set, then try to set the current user as anonymous - //if he doesn't have a login yet - api_set_anonymous(); + //if anonymous mode is set, then try to set the current user as anonymous + //if he doesn't have a login yet + api_set_anonymous(); } else { - //if anonymous mode is not set, then check if this user is anonymous. If it - //is, clean it from being anonymous (make him a nobody :-)) - api_clear_anonymous(); + //if anonymous mode is not set, then check if this user is anonymous. If it + //is, clean it from being anonymous (make him a nobody :-)) + api_clear_anonymous(); } // if there is a cDir parameter in the URL (coming from courses/.htaccess redirection) if (!empty($cDir)) { - $c = CourseManager::get_course_id_from_path($cDir); - if ($c) { $cidReq = $c; } + $c = CourseManager::get_course_id_from_path($cDir); + if ($c) { $cidReq = $c; } } // if the requested course is different from the course in session if (!empty($cidReq) && (!isset($_SESSION['_cid']) or (isset($_SESSION['_cid']) && $cidReq != $_SESSION['_cid']))) { - $cidReset = true; - $gidReset = true; // As groups depend from courses, group id is reset + $cidReset = true; + $gidReset = true; // As groups depend from courses, group id is reset } // if the requested group is different from the group in session $gid = isset($_SESSION['_gid']) ? $_SESSION['_gid'] : ''; if ($gidReq && $gidReq != $gid) { - $gidReset = true; + $gidReset = true; } @@ -583,48 +583,48 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested $is_platformAdmin = false; $is_allowedCreateCourse = false; - if (isset($_user['user_id']) && $_user['user_id'] && ! api_is_anonymous()) { + if (isset($_user['user_id']) && $_user['user_id'] && ! api_is_anonymous()) { // a uid is given (log in succeeded) - $user_table = Database::get_main_table(TABLE_MAIN_USER); - $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); - $track_e_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - - $sql = "SELECT user.*, a.user_id is_admin, UNIX_TIMESTAMP(login.login_date) login_date - FROM $user_table - LEFT JOIN $admin_table a - ON user.user_id = a.user_id - LEFT JOIN $track_e_login login - ON user.user_id = login.login_user_id - WHERE user.user_id = '".$_user['user_id']."' - ORDER BY login.login_date DESC LIMIT 1"; - - $result = Database::query($sql); - - if (Database::num_rows($result) > 0) { - // Extracting the user data - - $uData = Database::fetch_array($result); - - $_user ['firstName'] = $uData ['firstname' ]; - $_user ['lastName' ] = $uData ['lastname' ]; - $_user ['mail' ] = $uData ['email' ]; - $_user ['lastLogin'] = $uData ['login_date']; - $_user ['official_code'] = $uData ['official_code']; - $_user ['picture_uri'] = $uData ['picture_uri']; - $_user ['user_id'] = $uData ['user_id']; - $_user ['language'] = $uData ['language']; - $_user ['auth_source'] = $uData ['auth_source']; - $_user ['theme'] = $uData ['theme']; - $_user ['status'] = $uData ['status']; - - $is_platformAdmin = (bool) (! is_null( $uData['is_admin'])); - $is_allowedCreateCourse = (bool) (($uData ['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $uData['status'] == DRH)); - ConditionalLogin::check_conditions($uData); - - Session::write('_user',$_user); - UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true'); - Session::write('is_platformAdmin',$is_platformAdmin); - Session::write('is_allowedCreateCourse',$is_allowedCreateCourse); + $user_table = Database::get_main_table(TABLE_MAIN_USER); + $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); + $track_e_login = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + + $sql = "SELECT user.*, a.user_id is_admin, UNIX_TIMESTAMP(login.login_date) login_date + FROM $user_table + LEFT JOIN $admin_table a + ON user.user_id = a.user_id + LEFT JOIN $track_e_login login + ON user.user_id = login.login_user_id + WHERE user.user_id = '".$_user['user_id']."' + ORDER BY login.login_date DESC LIMIT 1"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) { + // Extracting the user data + + $uData = Database::fetch_array($result); + + $_user ['firstName'] = $uData ['firstname' ]; + $_user ['lastName' ] = $uData ['lastname' ]; + $_user ['mail' ] = $uData ['email' ]; + $_user ['lastLogin'] = $uData ['login_date']; + $_user ['official_code'] = $uData ['official_code']; + $_user ['picture_uri'] = $uData ['picture_uri']; + $_user ['user_id'] = $uData ['user_id']; + $_user ['language'] = $uData ['language']; + $_user ['auth_source'] = $uData ['auth_source']; + $_user ['theme'] = $uData ['theme']; + $_user ['status'] = $uData ['status']; + + $is_platformAdmin = (bool) (! is_null( $uData['is_admin'])); + $is_allowedCreateCourse = (bool) (($uData ['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $uData['status'] == DRH)); + ConditionalLogin::check_conditions($uData); + + Session::write('_user',$_user); + UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true'); + Session::write('is_platformAdmin',$is_platformAdmin); + Session::write('is_allowedCreateCourse',$is_allowedCreateCourse); // If request_uri is setted we have to go further to have course permissions /*if (empty($_SESSION['request_uri']) || !isset($_SESSION['request_uri'])) { @@ -635,17 +635,17 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested LoginRedirection::redirect(); } }*/ - } else { - header('location:'.api_get_path(WEB_PATH)); - //exit("WARNING UNDEFINED UID !! "); - } - } else { // no uid => logout or Anonymous - Session::erase('_user'); - Session::erase('_uid'); - } - - Session::write('is_platformAdmin',$is_platformAdmin); - Session::write('is_allowedCreateCourse',$is_allowedCreateCourse); + } else { + header('location:'.api_get_path(WEB_PATH)); + //exit("WARNING UNDEFINED UID !! "); + } + } else { // no uid => logout or Anonymous + Session::erase('_user'); + Session::erase('_uid'); + } + + Session::write('is_platformAdmin',$is_platformAdmin); + Session::write('is_allowedCreateCourse',$is_allowedCreateCourse); } else { // continue with the previous values $_user = $_SESSION['_user']; $is_platformAdmin = isset($_SESSION['is_platformAdmin']) ? $_SESSION['is_platformAdmin'] : false; @@ -656,39 +656,39 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested if (isset($cidReset) && $cidReset) { // Course session data refresh requested or empty data - if ($cidReq) { + if ($cidReq) { $_course = CourseManager::get_course_info_with_category($cidReq); - if (!empty($_course)) { + if (!empty($_course)) { //@TODO real_cid should be cid, for working with numeric course id $_real_cid = $_course['real_id']; - $_cid = $_course['code']; + $_cid = $_course['code']; Session::write('_real_cid', $_real_cid); - Session::write('_cid', $_cid); - Session::write('_course', $_course); - - // if a session id has been given in url, we store the session - if (api_get_setting('use_session_mode') == 'true') { - // Database Table Definitions - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - if (!empty($_GET['id_session'])) { - $_SESSION['id_session'] = intval($_GET['id_session']); - $sql = 'SELECT name FROM '.$tbl_session . ' WHERE id="'.intval($_SESSION['id_session']) . '"'; - $rs = Database::query($sql); - list($_SESSION['session_name']) = Database::fetch_array($rs); - } else { - Session::erase('session_name'); - Session::erase('id_session'); - } - } + Session::write('_cid', $_cid); + Session::write('_course', $_course); + + // if a session id has been given in url, we store the session + if (api_get_setting('use_session_mode') == 'true') { + // Database Table Definitions + $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); + $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + + if (!empty($_GET['id_session'])) { + $_SESSION['id_session'] = intval($_GET['id_session']); + $sql = 'SELECT name FROM '.$tbl_session . ' WHERE id="'.intval($_SESSION['id_session']) . '"'; + $rs = Database::query($sql); + list($_SESSION['session_name']) = Database::fetch_array($rs); + } else { + Session::erase('session_name'); + Session::erase('id_session'); + } + } if (!isset($_SESSION['login_as'])) { - //Course login + //Course login if (isset($_user['user_id'])) { event_course_login($_course['code'], $_user['user_id'], api_get_session_id()); } @@ -878,36 +878,36 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - //Session coach, session admin, course coach admin + //Session coach, session admin, course coach admin $sql = "SELECT session.id_coach, session_admin_id, session_rcru.id_user - FROM $tbl_session session, $tbl_session_course_user session_rcru - WHERE session_rcru.id_session = session.id AND - session_rcru.course_code = '$_cid' AND - session_rcru.id_user = '$user_id' AND + FROM $tbl_session session, $tbl_session_course_user session_rcru + WHERE session_rcru.id_session = session.id AND + session_rcru.course_code = '$_cid' AND + session_rcru.id_user = '$user_id' AND session_rcru.id_session = $session_id AND - session_rcru.status = 2"; + session_rcru.status = 2"; - $result = Database::query($sql); - $row = Database::store_result($result); + $result = Database::query($sql); + $row = Database::store_result($result); //I'm a session admin? if (isset($row) && isset($row[0]) && $row[0]['session_admin_id'] == $user_id) { - $_courseUser['role'] = 'Professor'; - $is_courseMember = false; - $is_courseTutor = false; - $is_courseAdmin = false; - $is_courseCoach = false; - $is_sessionAdmin = true; - } else { + $_courseUser['role'] = 'Professor'; + $is_courseMember = false; + $is_courseTutor = false; + $is_courseAdmin = false; + $is_courseCoach = false; + $is_sessionAdmin = true; + } else { //Im a coach or a student? - $sql = "SELECT id_user, status FROM ".$tbl_session_course_user." + $sql = "SELECT id_user, status FROM ".$tbl_session_course_user." WHERE course_code = '$_cid' AND id_user = '".$user_id."' AND id_session = '".$session_id."' LIMIT 1"; - $result = Database::query($sql); + $result = Database::query($sql); - if (Database::num_rows($result)) { + if (Database::num_rows($result)) { $row = Database::fetch_array($result, 'ASSOC'); $session_course_status = $row['status']; @@ -947,7 +947,7 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { Session::erase('_courseUser'); break; } - } else { + } else { //unregister user $is_courseMember = false; $is_courseTutor = false; @@ -955,8 +955,8 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { $is_sessionAdmin = false; $is_courseCoach = false; Session::erase('_courseUser'); - } - } + } + } } //If I'm the admin platform i'm a teacher of the course @@ -974,10 +974,10 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { Session::erase('_courseUser'); } - //Checking the course access + //Checking the course access $is_allowed_in_course = false; - if (isset($_course)) { + if (isset($_course)) { switch ($_course['visibility']) { case COURSE_VISIBILITY_OPEN_WORLD: //3 $is_allowed_in_course = true; @@ -998,16 +998,16 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { } break; } - } + } // check the session visibility - if ($is_allowed_in_course == true) { + if ($is_allowed_in_course == true) { - //if I'm in a session - if ($session_id != 0) { - if (!$is_platformAdmin) { - // admin is not affected to the invisible session mode - $session_visibility = api_get_session_visibility($session_id); + //if I'm in a session + if ($session_id != 0) { + if (!$is_platformAdmin) { + // admin is not affected to the invisible session mode + $session_visibility = api_get_session_visibility($session_id); switch ($session_visibility) { case SESSION_INVISIBLE: @@ -1015,84 +1015,84 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { break; } //checking date - } + } } - } + } - // save the states + // save the states Session::write('is_courseAdmin', $is_courseAdmin); - Session::write('is_courseMember', $is_courseMember); - Session::write('is_courseTutor', $is_courseTutor); + Session::write('is_courseMember', $is_courseMember); + Session::write('is_courseTutor', $is_courseTutor); Session::write('is_courseCoach', $is_courseCoach); - Session::write('is_allowed_in_course', $is_allowed_in_course); - Session::write('is_sessionAdmin', $is_sessionAdmin); + Session::write('is_allowed_in_course', $is_allowed_in_course); + Session::write('is_sessionAdmin', $is_sessionAdmin); } else { // continue with the previous values - if (isset($_SESSION['_courseUser'])) { - $_courseUser = $_SESSION ['_courseUser']; - } + if (isset($_SESSION['_courseUser'])) { + $_courseUser = $_SESSION ['_courseUser']; + } $is_courseAdmin = isset($_SESSION ['is_courseAdmin']) ? $_SESSION ['is_courseAdmin'] : false; $is_courseTutor = isset($_SESSION ['is_courseTutor']) ? $_SESSION ['is_courseTutor'] : false; $is_courseCoach = isset($_SESSION ['is_courseCoach']) ? $_SESSION ['is_courseCoach'] : false; - $is_courseMember = isset($_SESSION ['is_courseMember']) ? $_SESSION ['is_courseMember'] : false; - $is_allowed_in_course = isset($_SESSION ['is_allowed_in_course']) ? $_SESSION ['is_allowed_in_course'] : false; + $is_courseMember = isset($_SESSION ['is_courseMember']) ? $_SESSION ['is_courseMember'] : false; + $is_allowed_in_course = isset($_SESSION ['is_allowed_in_course']) ? $_SESSION ['is_allowed_in_course'] : false; } /* GROUP INIT */ if ((isset($gidReset) && $gidReset) || (isset($cidReset) && $cidReset)) { // session data refresh requested - if ($gidReq && $_cid && !empty($_course['real_id'])) { // have keys to search data - $group_table = Database::get_course_table(TABLE_GROUP); - $sql = "SELECT * FROM $group_table WHERE c_id = ".$_course['real_id']." AND id = '$gidReq'"; - $result = Database::query($sql); - if (Database::num_rows($result) > 0) { // This group has recorded status related to this course - $gpData = Database::fetch_array($result); - $_gid = $gpData ['id']; - Session::write('_gid',$_gid); - } else { + if ($gidReq && $_cid && !empty($_course['real_id'])) { // have keys to search data + $group_table = Database::get_course_table(TABLE_GROUP); + $sql = "SELECT * FROM $group_table WHERE c_id = ".$_course['real_id']." AND id = '$gidReq'"; + $result = Database::query($sql); + if (Database::num_rows($result) > 0) { // This group has recorded status related to this course + $gpData = Database::fetch_array($result); + $_gid = $gpData ['id']; + Session::write('_gid',$_gid); + } else { Session::erase('_gid'); - } - } elseif (isset($_SESSION['_gid']) or isset($_gid)) { // Keys missing => not anymore in the group - course relation - Session::erase('_gid'); - } + } + } elseif (isset($_SESSION['_gid']) or isset($_gid)) { // Keys missing => not anymore in the group - course relation + Session::erase('_gid'); + } } elseif (isset($_SESSION['_gid'])) { // continue with the previous values - $_gid = $_SESSION ['_gid']; + $_gid = $_SESSION ['_gid']; } else { //if no previous value, assign caracteristic undefined value - $_gid = -1; + $_gid = -1; } //set variable according to student_view_enabled choices if (api_get_setting('student_view_enabled') == "true") { - if (isset($_GET['isStudentView'])) { - if ($_GET['isStudentView'] == 'true') { - if (isset($_SESSION['studentview'])) { - if (!empty($_SESSION['studentview'])) { - // switching to studentview - $_SESSION['studentview'] = 'studentview'; - } - } - } elseif ($_GET['isStudentView'] == 'false') { - if (isset($_SESSION['studentview'])) { - if (!empty($_SESSION['studentview'])) { - // switching to teacherview - $_SESSION['studentview'] = 'teacherview'; - } - } - } - } elseif (!empty($_SESSION['studentview'])) { - //all is fine, no change to that, obviously - } elseif (empty($_SESSION['studentview'])) { - // We are in teacherview here - $_SESSION['studentview'] = 'teacherview'; - } + if (isset($_GET['isStudentView'])) { + if ($_GET['isStudentView'] == 'true') { + if (isset($_SESSION['studentview'])) { + if (!empty($_SESSION['studentview'])) { + // switching to studentview + $_SESSION['studentview'] = 'studentview'; + } + } + } elseif ($_GET['isStudentView'] == 'false') { + if (isset($_SESSION['studentview'])) { + if (!empty($_SESSION['studentview'])) { + // switching to teacherview + $_SESSION['studentview'] = 'teacherview'; + } + } + } + } elseif (!empty($_SESSION['studentview'])) { + //all is fine, no change to that, obviously + } elseif (empty($_SESSION['studentview'])) { + // We are in teacherview here + $_SESSION['studentview'] = 'teacherview'; + } } if (isset($_cid)) { - $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); - $time = api_get_datetime(); - $sql="UPDATE $tbl_course SET last_visit= '$time' WHERE code='$_cid'"; - Database::query($sql); + $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); + $time = api_get_datetime(); + $sql="UPDATE $tbl_course SET last_visit= '$time' WHERE code='$_cid'"; + Database::query($sql); } Redirect::session_request_uri(); From 2fcf01df4ca4ea5818f41a055a7d02ef0d973820 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 18 Jul 2012 16:23:55 -0500 Subject: [PATCH 25/36] Fix issue with conditional login preventing... login - fixes changeset a7b4c0037b056d --- main/auth/conditional_login/conditional_login.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/auth/conditional_login/conditional_login.php b/main/auth/conditional_login/conditional_login.php index 2b4d4c2375..1bd5045306 100644 --- a/main/auth/conditional_login/conditional_login.php +++ b/main/auth/conditional_login/conditional_login.php @@ -12,8 +12,8 @@ $dc_conditions = array(); array_push($dc_conditions, array( - 'conditional_function' => 'check_platform_legal_conditions', - 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php' +// 'conditional_function' => 'check_platform_legal_conditions', +// 'url' => api_get_path(WEB_CODE_PATH).'auth/inscription.php' )); @@ -63,4 +63,4 @@ function check_platform_legal_conditions($user) { //No validation return true; } -} \ No newline at end of file +} From d2cab9c4d6870563a0501d8e3e93754b7aa46f47 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 11:30:43 +0200 Subject: [PATCH 26/36] Removing notifications and "since last visit" in userportal for closed courses see #5207 --- main/inc/lib/course.lib.php | 89 ++++++++++++++------------------- main/inc/lib/userportal.lib.php | 2 +- 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index b825beabf8..e6b9c679f2 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2782,9 +2782,7 @@ class CourseManager { $html .= '
    '; $html .= '
    '; $html .= '
    '; - $html .= '
    '; - if (!empty($params['link'])) { $html .= ''; $html .= $params['icon']; @@ -2853,14 +2851,12 @@ class CourseManager { $rs_special_course = Database::query($sql); $number_of_courses = Database::num_rows($rs_special_course); $key = 0; - $status_icon = ''; - + $html = ''; if ($number_of_courses > 0) { while ($course = Database::fetch_array($rs_special_course)) { $course_info = api_get_course_info($course['code']); - $params = array(); // Get notifications. //$course['id_session'] = null; @@ -2876,7 +2872,7 @@ class CourseManager { $params['icon'] = Display::return_icon('blackboard.png', $course_info['title'], array(), ICON_SIZE_LARGE); - $params['right_actions'] = ''; + $params['right_actions'] = ''; if (api_is_platform_admin()) { if ($load_dirs) { $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; @@ -2889,9 +2885,11 @@ class CourseManager { //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;')); } } else { - if ($load_dirs) { - $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; - $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course['real_id'].'_0', 'class'=>'document_preview_container')); + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + if ($load_dirs) { + $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course['real_id'].'_0', 'class'=>'document_preview_container')); + } } } @@ -2912,7 +2910,11 @@ class CourseManager { $params['title'] = $course_title; $params['link'] = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/?id_session=0&autoreg=1'; - $params['notifications'] = $show_notification; + + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + $params['notifications'] = $show_notification; + } + $html .= self::course_item_html($params, false); $key++; } @@ -2993,7 +2995,6 @@ class CourseManager { $result = Database::query($sql_select_courses); $key = 0; $status_icon = ''; - $html = ''; // Browse through all courses. @@ -3026,12 +3027,14 @@ class CourseManager { //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;')); } } else { - if ($load_dirs) { - $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; - $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_0', 'class'=>'document_preview_container')); - } else { - if ($course_info['status'] == COURSEMANAGER) { - $params['right_actions'].= ''.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + if ($load_dirs) { + $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_0', 'class'=>'document_preview_container')); + } else { + if ($course_info['status'] == COURSEMANAGER) { + $params['right_actions'].= ''.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + } } } } @@ -3057,7 +3060,10 @@ class CourseManager { $params['icon'] = $status_icon; $params['title'] = $course_title; $params['teachers'] = $teachers; - $params['notifications'] = $show_notification; + + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + $params['notifications'] = $show_notification; + } $is_subcontent = true; if (empty($user_category_id)) { @@ -3138,7 +3144,7 @@ class CourseManager { $course_info['id_session'] = $session_id; - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { global $now, $date_start, $date_end; } @@ -3152,30 +3158,6 @@ class CourseManager { $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_info['code']); - - // Function logic - act on the data. - /* - $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course_info['code']); - if ($is_virtual_course) { - // If the current user is also subscribed in the real course to which this - // virtual course is linked, we don't need to display the virtual course entry in - // the course list - it is combined with the real course entry. - $target_course_code = CourseManager :: get_target_of_linked_course($course_info['code']); - $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); - if ($is_subscribed_in_target_course) { - return; //do not display this course entry - } - } - $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_info['code'], api_get_user_id()); - if ($has_virtual_courses) { - $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); - $course_display_title = $return_result['name']; - $course_display_code = $return_result['code']; - } else { - $course_display_title = $course_info['name']; - $course_display_code = $course_info['official_code']; - }*/ - $is_coach = api_is_coach($course_info['id_session'], $course['code']); // Display course entry. @@ -3185,7 +3167,7 @@ class CourseManager { if ($session_accessible) { if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { if (empty($course_info['id_session'])) { $course_info['id_session'] = 0; } @@ -3210,9 +3192,12 @@ class CourseManager { $params['title'] = $session_title; $params['right_actions'] = ''; - if ($load_dirs) { - $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; - $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_'.$course_info['id_session'], 'class'=>'document_preview_container')); + + if ($course_visibility != COURSE_VISIBILITY_CLOSED) { + if ($load_dirs) { + $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_'.$course_info['id_session'], 'class'=>'document_preview_container')); + } } if (api_get_setting('display_coursecode_in_courselist') == 'true') { @@ -3220,7 +3205,7 @@ class CourseManager { } if (api_get_setting('display_teacher_in_courselist') == 'true') { - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { $teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code'], self::USER_SEPARATOR, true); $course_coachs = CourseManager::get_coachs_from_course_to_string($course_info['id_session'], $course['code'], self::USER_SEPARATOR, true); @@ -3228,7 +3213,7 @@ class CourseManager { $params['teachers'] = $teacher_list; } if (($course_info['status'] == STUDENT && !empty($course_info['id_session'])) || ($is_coach && $course_info['status'] != COURSEMANAGER)) { - $params['coaches'] = $course_coachs; + $params['coaches'] = $course_coachs; } } else { $params['teachers'] = $teacher_list; @@ -3238,7 +3223,9 @@ class CourseManager { $session_title .= isset($course['special_course']) ? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : ''; // Display the "what's new" icons - $session_title .= Display :: show_notification($course_info); + if ($course_visibility != COURSE_VISIBILITY_CLOSED) { + $session_title .= Display :: show_notification($course_info); + } $params['title'] = $session_title; $params['extra'] = ''; @@ -3246,7 +3233,7 @@ class CourseManager { $html = self::course_item_html($params, true); $session_category_id = null; - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { $session = ''; $active = false; if (!empty($course_info['session_name'])) { diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 6a83f0af36..2a6ce2d533 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -898,7 +898,7 @@ class IndexManager { // Sessions and courses that are not in a session category. // If we're not in the history view... - if (!isset($_GET['history'])) { // + if (!isset($_GET['history'])) { //Display special courses $html .= CourseManager :: display_special_courses($user_id, $this->load_directories_preview); //Display courses From 0543c0b61ec56f5065307b49fc4d3ebca71fd578 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 11:40:38 +0200 Subject: [PATCH 27/36] use_session_mode is always true (variable should be removed in the next version) --- main/admin/index.php | 84 +++++--------- main/admin/settings.php | 1 + main/exercice/question_pool.php | 4 - main/inc/lib/banner.lib.php | 31 +++--- main/inc/lib/course.lib.php | 2 +- main/inc/lib/display.lib.php | 35 +----- main/inc/lib/login.lib.php | 29 +++-- main/inc/lib/main_api.lib.php | 189 ++++++++++++++------------------ main/inc/lib/social.lib.php | 4 +- main/inc/lib/userportal.lib.php | 14 +-- main/inc/local.inc.php | 32 +++--- main/mySpace/myStudents.php | 2 +- main/tracking/userLog.php | 40 +++---- main/tracking/userlogCSV.php | 44 +++----- main/user/class.php | 4 +- main/user/subscribe_class.php | 6 +- main/user/user.php | 104 +++++++++--------- 17 files changed, 254 insertions(+), 371 deletions(-) mode change 100755 => 100644 main/tracking/userlogCSV.php diff --git a/main/admin/index.php b/main/admin/index.php index 1a29cd3fab..bf153e5962 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -175,65 +175,37 @@ if (api_is_platform_admin()) { } /* Sessions */ +$blocks['sessions']['icon'] = Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL, false); +$blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions')); + +$search_form = ' '; +$blocks['sessions']['search_form'] = $search_form; +$items = array(); +$items[] = array('url'=>'session_list.php', 'label' => get_lang('ListSession')); +$items[] = array('url'=>'session_add.php', 'label' => get_lang('AddSession')); +$items[] = array('url'=>'session_category_list.php', 'label' => get_lang('ListSessionCategory')); +$items[] = array('url'=>'session_import.php', 'label' => get_lang('ImportSessionListXMLCSV')); +if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) { + $items[] = array('url'=>'ldap_import_students_to_session.php', 'label' => get_lang('ImportLDAPUsersIntoSession')); +} +$items[] = array('url'=>'session_export.php', 'label' => get_lang('ExportSessionListXMLCSV')); +$items[] = array('url'=>'../coursecopy/copy_course_session.php', 'label' => get_lang('CopyFromCourseInSessionToAnotherSession')); -//if (api_get_setting('use_session_mode') == 'true') { -if (true) { - - $blocks['sessions']['icon'] = Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_SMALL, false); - $blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions')); - - $search_form = ' '; - $blocks['sessions']['search_form'] = $search_form; - $items = array(); - $items[] = array('url'=>'session_list.php', 'label' => get_lang('ListSession')); - $items[] = array('url'=>'session_add.php', 'label' => get_lang('AddSession')); - $items[] = array('url'=>'session_category_list.php', 'label' => get_lang('ListSessionCategory')); - $items[] = array('url'=>'session_import.php', 'label' => get_lang('ImportSessionListXMLCSV')); - if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) { - $items[] = array('url'=>'ldap_import_students_to_session.php', 'label' => get_lang('ImportLDAPUsersIntoSession')); - } - $items[] = array('url'=>'session_export.php', 'label' => get_lang('ExportSessionListXMLCSV')); - $items[] = array('url'=>'../coursecopy/copy_course_session.php', 'label' => get_lang('CopyFromCourseInSessionToAnotherSession')); - - if (api_is_platform_admin()) { - if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) { // option only visible in development mode. Enable through code if required - $items[] = array('url'=>'user_move_stats.php', 'label' => get_lang('MoveUserStats')); - } - $items[] = array('url'=>'career_dashboard.php', 'label' => get_lang('CareersAndPromotions')); - } - - $items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes')); - - $blocks['sessions']['items'] = $items; - $blocks['sessions']['extra'] = null; +if (api_is_platform_admin()) { + if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) { // option only visible in development mode. Enable through code if required + $items[] = array('url'=>'user_move_stats.php', 'label' => get_lang('MoveUserStats')); + } + $items[] = array('url'=>'career_dashboard.php', 'label' => get_lang('CareersAndPromotions')); +} -} elseif (api_is_platform_admin()) { +$items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes')); + +$blocks['sessions']['items'] = $items; +$blocks['sessions']['extra'] = null; - /*$blocks['classes']['items'] = $items; - $blocks['classes']['icon'] = Display::return_icon('group.gif', get_lang('AdminClasses'), array(), ICON_SIZE_SMALL, false); - $blocks['classes']['label'] = api_ucfirst(get_lang('AdminClasses')); - - $search_form = ' '; - $blocks['classes']['search_form'] = $search_form; - $items = array(); - $items[] = array('url'=>'class_list.php', 'label' => get_lang('ClassList')); - $items[] = array('url'=>'class_add.php', 'label' => get_lang('AddClasses')); - $items[] = array('url'=>'class_import.php', 'label' => get_lang('ImportClassListCSV')); - $items[] = array('url'=>'class_user_import.php', 'label' => get_lang('AddUsersToAClass')); - $items[] = array('url'=>'subscribe_class2course.php', 'label' => get_lang('AddClassesToACourse')); - - $items[] = array('url'=>'usergroups.php', 'label' => get_lang('Classes')); - - $blocks['classes']['items'] = $items; - $blocks['classes']['extra'] = null;*/ - -} /* Settings */ if (api_is_platform_admin()) { diff --git a/main/admin/settings.php b/main/admin/settings.php index 1f98c58477..5c5187c808 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -40,6 +40,7 @@ api_protect_admin_script(); // Settings to avoid $settings_to_avoid = array( + 'use_session_mode' => 'true', 'gradebook_enable' => 'false', 'example_material_course_creation' => 'true' // ON by default - now we have this option when we create a course ); diff --git a/main/exercice/question_pool.php b/main/exercice/question_pool.php index a435af85c5..6f76f6b162 100644 --- a/main/exercice/question_pool.php +++ b/main/exercice/question_pool.php @@ -288,10 +288,6 @@ echo ''; $session_list = SessionManager::get_sessions_by_coach(api_get_user_id()); $tabAttrParam = array('class'=>'chzn-select', 'onchange'=>'submit_form(this)'); // when sessions are used $labelFormRow = get_lang('Session'); -if (api_get_setting('use_session_mode') == 'false') { - $tabAttrParam = array('style'=>'visibility:hidden', 'onchange'=>'submit_form(this)'); - $labelFormRow = ""; -} $session_select_list = array(); foreach($session_list as $item) { $session_select_list[$item['id']] = $item['name']; diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index b924afce33..e6c5336b35 100644 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -25,22 +25,17 @@ function get_tabs() { $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage'); // My Courses - if (api_get_setting('use_session_mode')=='true') { - if(api_is_allowed_to_create_course()) { - // Link to my courses for teachers - $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true'; - $navigation['mycourses']['title'] = get_lang('MyCourses'); - } else { - // Link to my courses for students - $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php'; - $navigation['mycourses']['title'] = get_lang('MyCourses'); - } - } else { - // Link to my courses - $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php'; - $navigation['mycourses']['title'] = get_lang('MyCourses'); - } - + + if(api_is_allowed_to_create_course()) { + // Link to my courses for teachers + $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true'; + $navigation['mycourses']['title'] = get_lang('MyCourses'); + } else { + // Link to my courses for students + $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php'; + $navigation['mycourses']['title'] = get_lang('MyCourses'); + } + // My Profile $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH).'auth/profile.php'.(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&courseCode='.$_course['official_code'] : '' ); $navigation['myprofile']['title'] = get_lang('ModifyProfile'); @@ -197,7 +192,7 @@ function return_notification_menu() { } // Display the who's online for the session - if (api_get_setting('use_session_mode') == 'true' && isset($user_id) && api_get_session_id() != 0) { + if (isset($user_id) && api_get_session_id() != 0) { $html .= '
  • '. Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), array(), ICON_SIZE_TINY).'
  • '; } @@ -490,7 +485,7 @@ function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name; break; default: - if (api_get_setting('use_session_mode') == 'true' && api_get_session_id() != -1 ) { + if (api_get_session_id() != -1 ) { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name'].$my_session_name).' '.$course_title.$my_session_name; } else { $navigation_item['title'] = Display::img(api_get_path(WEB_CSS_PATH).'home.png', $_course['name']).' '.$course_title; diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index e6b9c679f2..beb6e78b6c 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1323,7 +1323,7 @@ class CourseManager { // students subscribed to the course through a session - if (api_get_setting('use_session_mode') == 'true' && $with_session) { + if ($with_session) { $sql_query = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE course_code = '$course_code' AND status<>2"; if ($session_id != 0) { $sql_query .= ' AND id_session = '.$session_id; diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 77be3c31bc..1f25c123a2 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1005,37 +1005,6 @@ class Display { return $table->toHtml(); } - /** - * Display dashboard link - * - */ - /*function display_dashboard_link() { - echo '
  • '.get_lang('Dashboard').'
  • '; - }*/ - - /** - * Display edit course list links - * - */ - /*function display_edit_course_list_links() { - echo '
  • '.get_lang('CourseManagement').'
  • '; - }*/ - - /** - * Show history sessions - * - */ - /* - function display_history_course_session() { - if (api_get_setting('use_session_mode') == 'true') { - if (isset($_GET['history']) && intval($_GET['history']) == 1) { - echo '
  • '.get_lang('DisplayTrainingList').'
  • '; - } else { - echo '
  • '.get_lang('HistoryTrainingSessions').'
  • '; - } - } - }*/ - /** * Returns the "what's new" icon notifications * @@ -1251,12 +1220,12 @@ class Display { function get_session_title_box($session_id) { global $nosession; - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { global $now, $date_start, $date_end; } $output = array(); - if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (!$nosession) { $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY); diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index a17ea10f4e..d5236b4106 100644 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -381,21 +381,20 @@ class Login Session::write('_real_cid', $_real_cid); // if a session id has been given in url, we store the session - if (api_get_setting('use_session_mode') == 'true') { - // Database Table Definitions - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - if (!empty($_GET['id_session'])) { - $_SESSION['id_session'] = intval($_GET['id_session']); - $sql = 'SELECT name FROM ' . $tbl_session . ' WHERE id="' . intval($_SESSION['id_session']) . '"'; - $rs = Database::query($sql); - list($_SESSION['session_name']) = Database::fetch_array($rs); - } else { - Session::erase('session_name'); - Session::erase('id_session'); - } + + // Database Table Definitions + $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); + $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + + if (!empty($_GET['id_session'])) { + $_SESSION['id_session'] = intval($_GET['id_session']); + $sql = 'SELECT name FROM ' . $tbl_session . ' WHERE id="' . intval($_SESSION['id_session']) . '"'; + $rs = Database::query($sql); + list($_SESSION['session_name']) = Database::fetch_array($rs); + } else { + Session::erase('session_name'); + Session::erase('id_session'); } if (!isset($_SESSION['login_as'])) { diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index b7107cc07d..d993f27b45 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -4583,144 +4583,115 @@ function api_is_course_visible_for_user($userid = null, $cid = null) { return true; } - if (api_get_setting('use_session_mode') != 'true') { - $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $sql = "SELECT tutor_id, status - FROM $course_user_table - WHERE user_id = '$userid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." - AND course_code = '$cid' - LIMIT 1"; - - $result = Database::query($sql); - - if (Database::num_rows($result) > 0) { - // This user have a recorded state for this course. - $cuData = Database::fetch_array($result); + $sql = "SELECT + tutor_id, status, role + FROM $tbl_course_user + WHERE + user_id = '$userid' + AND + relation_type <> '".COURSE_RELATION_TYPE_RRHH."' + AND + course_code = '$cid' + LIMIT 1"; - $is_courseMember = true; - $is_courseTutor = ($cuData['tutor_id' ] == 1); - $is_courseAdmin = ($cuData['status'] == 1); + $result = Database::query($sql); - } else { - // This user has no status related to this course. - $is_courseMember = false; - $is_courseAdmin = false; - $is_courseTutor = false; - } + if (Database::num_rows($result) > 0) { + // This user has got a recorded state for this course. + $cuData = Database::fetch_array($result); - $is_courseAdmin = ($is_courseAdmin || $is_platformAdmin); - } else { - $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $_courseUser['role'] = $cuData['role']; + $is_courseMember = true; + $is_courseTutor = ($cuData['tutor_id' ] == 1); + $is_courseAdmin = ($cuData['status'] == 1); + } + if (!$is_courseAdmin) { + // This user has no status related to this course. + // Is it the session coach or the session admin? + $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); + $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $sql = "SELECT - tutor_id, status, role - FROM $tbl_course_user - WHERE - user_id = '$userid' - AND - relation_type <> '".COURSE_RELATION_TYPE_RRHH."' - AND - course_code = '$cid' + session.id_coach, session_admin_id, session.id + FROM + $tbl_session as session + INNER JOIN $tbl_session_course + ON session_rel_course.id_session = session.id + AND session_rel_course.course_code = '$cid' LIMIT 1"; $result = Database::query($sql); + $row = Database::store_result($result); - if (Database::num_rows($result) > 0) { - // This user has got a recorded state for this course. - $cuData = Database::fetch_array($result); - - $_courseUser['role'] = $cuData['role']; - $is_courseMember = true; - $is_courseTutor = ($cuData['tutor_id' ] == 1); - $is_courseAdmin = ($cuData['status'] == 1); + if ($row[0]['id_coach'] == $userid) { + $_courseUser['role'] = 'Professor'; + $is_courseMember = true; + $is_courseTutor = true; + $is_courseAdmin = false; + $is_courseCoach = true; + $is_sessionAdmin = false; + Session::write('_courseUser',$_courseUser); } - if (!$is_courseAdmin) { - // This user has no status related to this course. - // Is it the session coach or the session admin? - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - $sql = "SELECT - session.id_coach, session_admin_id, session.id - FROM - $tbl_session as session - INNER JOIN $tbl_session_course - ON session_rel_course.id_session = session.id - AND session_rel_course.course_code = '$cid' + elseif ($row[0]['session_admin_id'] == $userid) { + $_courseUser['role'] = 'Professor'; + $is_courseMember = false; + $is_courseTutor = false; + $is_courseAdmin = false; + $is_courseCoach = false; + $is_sessionAdmin = true; + } else { + // Check if the current user is the course coach. + $sql = "SELECT 1 + FROM $tbl_session_course + WHERE session_rel_course.course_code = '$cid' + AND session_rel_course.id_coach = '$userid' LIMIT 1"; $result = Database::query($sql); - $row = Database::store_result($result); - if ($row[0]['id_coach'] == $userid) { + //if ($row = Database::fetch_array($result)) { + if (Database::num_rows($result) > 0 ) { $_courseUser['role'] = 'Professor'; $is_courseMember = true; $is_courseTutor = true; - $is_courseAdmin = false; $is_courseCoach = true; $is_sessionAdmin = false; - Session::write('_courseUser',$_courseUser); - } - elseif ($row[0]['session_admin_id'] == $userid) { - $_courseUser['role'] = 'Professor'; - $is_courseMember = false; - $is_courseTutor = false; - $is_courseAdmin = false; - $is_courseCoach = false; - $is_sessionAdmin = true; - } else { - // Check if the current user is the course coach. - $sql = "SELECT 1 - FROM $tbl_session_course - WHERE session_rel_course.course_code = '$cid' - AND session_rel_course.id_coach = '$userid' - LIMIT 1"; - - $result = Database::query($sql); - //if ($row = Database::fetch_array($result)) { - if (Database::num_rows($result) > 0 ) { - $_courseUser['role'] = 'Professor'; - $is_courseMember = true; - $is_courseTutor = true; - $is_courseCoach = true; - $is_sessionAdmin = false; + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); + $sql = "SELECT status FROM $tbl_user + WHERE user_id = $userid LIMIT 1"; - $sql = "SELECT status FROM $tbl_user - WHERE user_id = $userid LIMIT 1"; - - $result = Database::query($sql); + $result = Database::query($sql); - if (Database::result($result, 0, 0) == 1) { - $is_courseAdmin = true; - } else { - $is_courseAdmin = false; - } + if (Database::result($result, 0, 0) == 1) { + $is_courseAdmin = true; } else { - // Check if the user is a student is this session. - $sql = "SELECT id - FROM $tbl_session_course_user - WHERE id_user = '$userid' - AND course_code = '$cid' - LIMIT 1"; - - if (Database::num_rows($result) > 0) { - // This user haa got a recorded state for this course. - while ($row = Database::fetch_array($result)) { - $is_courseMember = true; - $is_courseTutor = false; - $is_courseAdmin = false; - $is_sessionAdmin = false; - } + $is_courseAdmin = false; + } + } else { + // Check if the user is a student is this session. + $sql = "SELECT id + FROM $tbl_session_course_user + WHERE id_user = '$userid' + AND course_code = '$cid' + LIMIT 1"; + + if (Database::num_rows($result) > 0) { + // This user haa got a recorded state for this course. + while ($row = Database::fetch_array($result)) { + $is_courseMember = true; + $is_courseTutor = false; + $is_courseAdmin = false; + $is_sessionAdmin = false; } } } } - } + } switch ($visibility) { case COURSE_VISIBILITY_OPEN_WORLD: diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index fbad867c56..c5a41185ab 100644 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -386,7 +386,7 @@ class SocialManager extends UserManager { */ public static function get_logged_user_course_html($my_course, $count) { global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode; - if (api_get_setting('use_session_mode')=='true' && !$nosession) { + if (!$nosession) { global $now, $date_start, $date_end; } //initialise @@ -477,7 +477,7 @@ class SocialManager extends UserManager { $result .= ''; $result .= '
    '; - if (api_get_setting('use_session_mode')=='true' && !$nosession) { + if (!$nosession) { $session = ''; $active = false; if (!empty($my_course['session_name'])) { diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 2a6ce2d533..c3f945b4e4 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -826,13 +826,13 @@ class IndexManager { if (!api_is_drh()) { $my_account_content .= '
  • '.get_lang('CourseManagement').'
  • '; - if (api_get_setting('use_session_mode') == 'true') { - if (isset($_GET['history']) && intval($_GET['history']) == 1) { - $my_account_content .= '
  • '.get_lang('DisplayTrainingList').'
  • '; - } else { - $my_account_content .= '
  • '.get_lang('HistoryTrainingSessions').'
  • '; - } - } + + if (isset($_GET['history']) && intval($_GET['history']) == 1) { + $my_account_content .= '
  • '.get_lang('DisplayTrainingList').'
  • '; + } else { + $my_account_content .= '
  • '.get_lang('HistoryTrainingSessions').'
  • '; + } + } else { $my_account_content .= '
  • '.get_lang('Dashboard').'
  • '; } diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index 79227dd52d..7eb5af0495 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -670,22 +670,22 @@ if (isset($cidReset) && $cidReset) { Session::write('_course', $_course); // if a session id has been given in url, we store the session - if (api_get_setting('use_session_mode') == 'true') { - // Database Table Definitions - $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); - $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); - $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - if (!empty($_GET['id_session'])) { - $_SESSION['id_session'] = intval($_GET['id_session']); - $sql = 'SELECT name FROM '.$tbl_session . ' WHERE id="'.intval($_SESSION['id_session']) . '"'; - $rs = Database::query($sql); - list($_SESSION['session_name']) = Database::fetch_array($rs); - } else { - Session::erase('session_name'); - Session::erase('id_session'); - } - } + + // Database Table Definitions + $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); + $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + + if (!empty($_GET['id_session'])) { + $_SESSION['id_session'] = intval($_GET['id_session']); + $sql = 'SELECT name FROM '.$tbl_session . ' WHERE id="'.intval($_SESSION['id_session']) . '"'; + $rs = Database::query($sql); + list($_SESSION['session_name']) = Database::fetch_array($rs); + } else { + Session::erase('session_name'); + Session::erase('id_session'); + } + if (!isset($_SESSION['login_as'])) { //Course login diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 0386b224d0..912a2dcd64 100644 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -385,7 +385,7 @@ if (!empty($student_id)) { $session_name = ''; $nb_login = Tracking :: count_login_per_student($user_info['user_id'], $_GET['course']); //get coach and session_name if there is one and if session_mode is activated - if (api_get_setting('use_session_mode') == 'true' && $session_id > 0) { + if ($session_id > 0) { $session_info = api_get_session_info($session_id); $course_coachs = api_get_coachs_from_course($session_id, $course_code); diff --git a/main/tracking/userLog.php b/main/tracking/userLog.php index 92044e9e46..1ff95d143a 100644 --- a/main/tracking/userLog.php +++ b/main/tracking/userLog.php @@ -78,20 +78,18 @@ $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_U $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER); -if (api_get_setting('use_session_mode') == "true") { - $sql = "SELECT 1 - FROM $tbl_session_course_user AS session_course_user - INNER JOIN $tbl_session AS session - ON session_course_user.id_session = session.id - AND ((date_start<=NOW() - AND date_end>=NOW()) - OR (date_start='0000-00-00' AND date_end='0000-00-00')) - WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'"; - //echo $sql; - $result=Database::query($sql); - if(!Database::num_rows($result)){ - $disabled = true; - } +$sql = "SELECT 1 + FROM $tbl_session_course_user AS session_course_user + INNER JOIN $tbl_session AS session + ON session_course_user.id_session = session.id + AND ((date_start<=NOW() + AND date_end>=NOW()) + OR (date_start='0000-00-00' AND date_end='0000-00-00')) + WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'"; +//echo $sql; +$result=Database::query($sql); +if(!Database::num_rows($result)){ + $disabled = true; } $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN); @@ -133,15 +131,11 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) { echo "

    ".get_lang('ListStudents')."

    "; if( $is_allowedToTrackEverybodyInCourse ) { // if user can track everybody : list user of course - if(api_get_setting('use_session_mode')) { - $sql = "SELECT count(user_id) - FROM $TABLECOURSUSER - WHERE course_code = '".Database::escape_string($_cid)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH.""; - } else { - $sql = "SELECT count(id_user) - FROM $tbl_session_course_user - WHERE course_code = '".Database::escape_string($_cid)."'"; - } + + $sql = "SELECT count(user_id) + FROM $TABLECOURSUSER + WHERE course_code = '".Database::escape_string($_cid)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH.""; + } else { // if user can only track one group : list users of this group $sql = "SELECT count(user) diff --git a/main/tracking/userlogCSV.php b/main/tracking/userlogCSV.php old mode 100755 new mode 100644 index 82ba809849..ee2b6d9c23 --- a/main/tracking/userlogCSV.php +++ b/main/tracking/userlogCSV.php @@ -68,23 +68,21 @@ $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER); - -if(api_get_setting('use_session_mode') == "true") { - $sql = "SELECT 1 - FROM $tbl_session_course_user AS session_course_user - INNER JOIN $tbl_session AS session - ON session_course_user.id_session = session.id - AND ((date_start<=NOW() - AND date_end>=NOW()) - OR (date_start='0000-00-00' AND date_end='0000-00-00')) - WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'"; - //echo $sql; - $result=Database::query($sql); - if(!Database::num_rows($result)){ - $disabled = true; - } +$sql = "SELECT 1 + FROM $tbl_session_course_user AS session_course_user + INNER JOIN $tbl_session AS session + ON session_course_user.id_session = session.id + AND ((date_start<=NOW() + AND date_end>=NOW()) + OR (date_start='0000-00-00' AND date_end='0000-00-00')) + WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'"; +//echo $sql; +$result=Database::query($sql); +if(!Database::num_rows($result)){ + $disabled = true; } + $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN); $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW); @@ -122,17 +120,11 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) if( $is_allowedToTrackEverybodyInCourse ) { - // if user can track everybody : list user of course - if(api_get_setting('use_session_mode')) { - $sql = "SELECT count(user_id) - FROM $TABLECOURSUSER - WHERE course_code = '$_cid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH.""; - } - else { - $sql = "SELECT count(id_user) - FROM $tbl_session_course_user - WHERE course_code = '$_cid'"; - } + // if user can track everybody : list user of course + $sql = "SELECT count(user_id) + FROM $TABLECOURSUSER + WHERE course_code = '$_cid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH.""; + } else { diff --git a/main/user/class.php b/main/user/class.php index b0647a7775..6d1d433cae 100644 --- a/main/user/class.php +++ b/main/user/class.php @@ -15,9 +15,7 @@ $this_section = SECTION_COURSES; */ api_protect_course_script(); -if (api_get_setting('use_session_mode')=='true') { - api_not_allowed(); -} +api_not_allowed(); $tool_name = get_lang("Classes"); //extra entries in breadcrumb diff --git a/main/user/subscribe_class.php b/main/user/subscribe_class.php index 3d8e948c14..dd17cc328f 100644 --- a/main/user/subscribe_class.php +++ b/main/user/subscribe_class.php @@ -12,9 +12,9 @@ $language_file = array('registration','admin'); include ('../inc/global.inc.php'); $this_section = SECTION_COURSES; if (!api_is_allowed_to_edit()) api_not_allowed(true); -if(api_get_setting('use_session_mode')=='true') { - api_not_allowed(true); -} + +api_not_allowed(true); + /* MAIN CODE diff --git a/main/user/user.php b/main/user/user.php index 4459d23f50..fee3efde14 100644 --- a/main/user/user.php +++ b/main/user/user.php @@ -123,58 +123,58 @@ if (api_is_allowed_to_edit(null, true)) { $a_users[0] = array_merge($a_users[0], $extra_fields); // users subscribed to the course through a session - if (api_get_setting('use_session_mode') == 'true') { - if (api_get_session_id()) { - $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", $select_email_condition phone, user.official_code, active $legal - FROM $table_session_course_user as session_course_user, $table_users as user "; - if ($_configuration['multiple_access_urls']) { - $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; - } - $sql_query .=" WHERE course_code = '$course_code' AND session_course_user.id_user = user.user_id "; - $sql_query .= ' AND id_session = '.$session_id; - - if ($_configuration['multiple_access_urls']) { - $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id "; - } - - //only users no coaches/teachers - $sql_query .= " AND session_course_user.status = 0 "; - - $sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; - - $rs = Database::query($sql_query); - $counter = 1; - - while ($user = Database:: fetch_array($rs, 'ASSOC')) { - if (isset($user['legal_agreement'])) { - if ($user['legal_agreement'] == 1) { - $user['legal_agreement'] = get_lang('Yes'); - } else { - $user['legal_agreement'] = get_lang('No'); - } + + if (api_get_session_id()) { + $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", $select_email_condition phone, user.official_code, active $legal + FROM $table_session_course_user as session_course_user, $table_users as user "; + if ($_configuration['multiple_access_urls']) { + $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; + } + $sql_query .=" WHERE course_code = '$course_code' AND session_course_user.id_user = user.user_id "; + $sql_query .= ' AND id_session = '.$session_id; + + if ($_configuration['multiple_access_urls']) { + $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id "; + } + + //only users no coaches/teachers + $sql_query .= " AND session_course_user.status = 0 "; + + $sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; + + $rs = Database::query($sql_query); + $counter = 1; + + while ($user = Database:: fetch_array($rs, 'ASSOC')) { + if (isset($user['legal_agreement'])) { + if ($user['legal_agreement'] == 1) { + $user['legal_agreement'] = get_lang('Yes'); + } else { + $user['legal_agreement'] = get_lang('No'); + } + } + $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true); + if (!empty($extra_fields)) { + foreach($extra_fields as $key => $extra_value) { + $user[$key] = $extra_value; } - $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true); - if (!empty($extra_fields)) { - foreach($extra_fields as $key => $extra_value) { - $user[$key] = $extra_value; - } - } - $data[] = $user; - if ($_GET['type'] == 'pdf') { - if ($is_western_name_order) { - $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); - } else { - $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); - } - $a_users[] = $user_pdf; - } else { - $a_users[] = $user; + } + $data[] = $user; + if ($_GET['type'] == 'pdf') { + if ($is_western_name_order) { + $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] ); + } else { + $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] ); } - $counter++; - } - } - } + $a_users[] = $user_pdf; + } else { + $a_users[] = $user; + } + $counter++; + } + } + if ($session_id == 0) { @@ -354,10 +354,6 @@ if ( api_is_allowed_to_edit(null, true)) { $actions .= ''.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).' '; $actions .= "".Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM).""; - if (api_get_setting('use_session_mode') == 'false') { - $actions .= ' '.get_lang('Classes').''; - } - // Build search-form $form = new FormValidator('search_user', 'get', '', '', null, false); $renderer = & $form->defaultRenderer(); From 8766ea60d7d74b4c7a7ff2df93e0ab3adc05d954 Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Thu, 19 Jul 2012 11:53:27 +0200 Subject: [PATCH 28/36] Adding minor fix for Safari in the LP view see #5181 --- main/newscorm/lp_view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/newscorm/lp_view.php b/main/newscorm/lp_view.php index bfe5499a4a..f1c573dc85 100644 --- a/main/newscorm/lp_view.php +++ b/main/newscorm/lp_view.php @@ -372,7 +372,7 @@ if (Database::num_rows($res_media) > 0) { -
    +
    get_html_toc(); ?> From 886c363f56e5eb54a53a0105a7006c2fd6741235 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 12:06:57 +0200 Subject: [PATCH 29/36] Fixes missing
    in top bar see #5223 --- main/template/default/layout/topbar.tpl | 149 ++++++++++++------------ 1 file changed, 73 insertions(+), 76 deletions(-) diff --git a/main/template/default/layout/topbar.tpl b/main/template/default/layout/topbar.tpl index 744f9efd1f..628365ffd6 100644 --- a/main/template/default/layout/topbar.tpl +++ b/main/template/default/layout/topbar.tpl @@ -11,85 +11,82 @@ {{"siteName"|get_setting }} {% if _u.logged %} + -
    + + +
    + {% endif %} +
    -
    +
    {% endif %} \ No newline at end of file From cabccd49ea07710517f6026f37f28a336d1dc0a1 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 13:59:17 +0200 Subject: [PATCH 30/36] Minor - Adding clean button --- main/newscorm/lp_view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/newscorm/lp_view.php b/main/newscorm/lp_view.php index f1c573dc85..d087614585 100644 --- a/main/newscorm/lp_view.php +++ b/main/newscorm/lp_view.php @@ -380,7 +380,7 @@ if (Database::num_rows($res_media) > 0) {
    -
    .
    +
    From 592fb86537f591d0952151faccfd7b45b44cf805 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 14:00:36 +0200 Subject: [PATCH 31/36] Updating lang var see #4894 --- main/newscorm/lp_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/newscorm/lp_list.php b/main/newscorm/lp_list.php index 6746f4af04..6d2e4f3051 100644 --- a/main/newscorm/lp_list.php +++ b/main/newscorm/lp_list.php @@ -438,7 +438,7 @@ if (!empty($flat_list)) { //if (api_get_setting('pdf_export_watermark_enable') == 'true') { $export_icon = ' - '.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).''; + '.Display::return_icon('pdf.png', get_lang('ExportToPDFOnlyHTMLAndImages'),'',ICON_SIZE_SMALL).''; //} /* DELETE COMMAND */ From b406a40d83eb552bb8ed7d4657a2069ec6cd1627 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 14:24:29 +0200 Subject: [PATCH 32/36] Minor - bigger inputs --- main/admin/session_add.php | 2 +- main/admin/session_edit.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/admin/session_add.php b/main/admin/session_add.php index 332c7dfbb2..9b3466b99b 100644 --- a/main/admin/session_add.php +++ b/main/admin/session_add.php @@ -155,7 +155,7 @@ echo '';
    - +
    diff --git a/main/admin/session_edit.php b/main/admin/session_edit.php index e7fbaabc3a..d9388b9a78 100644 --- a/main/admin/session_edit.php +++ b/main/admin/session_edit.php @@ -115,7 +115,7 @@ if (!empty($return)) {
    - +
    From 32fa9ae4d5bfb893efc7d1f07b2e73f766b911fb Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 14:42:08 +0200 Subject: [PATCH 33/36] Fixing reporting when loading exercise results inside a "course session" see #5176 --- main/mySpace/myStudents.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 912a2dcd64..86d8d129dd 100644 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -850,14 +850,14 @@ if (empty($_GET['details'])) { get_lang('Score'), get_lang('Attempts') ); - + $t_quiz = Database :: get_course_table(TABLE_QUIZ_TEST); $sql_exercices = "SELECT quiz.title, id FROM " . $t_quiz . " AS quiz WHERE quiz.c_id = ".$info_course['real_id']." AND active='1' AND - quiz.session_id = $session_id + (quiz.session_id = $session_id OR quiz.session_id = 0) ORDER BY quiz.title ASC "; - + $result_exercices = Database::query($sql_exercices); $i = 0; if (Database :: num_rows($result_exercices) > 0) { @@ -892,18 +892,19 @@ if (empty($_GET['details'])) { echo ''; $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' - WHERE exe_exo_id="'.$exercise_id.'" AND - exe_user_id="'.$student_id.'" AND - exe_cours_id="'.$course_code.'" AND - status = "" AND - orig_lp_id = 0 AND + WHERE exe_exo_id ="'.$exercise_id.'" AND + exe_user_id ="'.$student_id.'" AND + exe_cours_id ="'.$course_code.'" AND + session_id ="'.$session_id.'" AND + status = "" AND + orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_date DESC LIMIT 1'; $result_last_attempt = Database::query($sql_last_attempt); if (Database :: num_rows($result_last_attempt) > 0) { $id_last_attempt = Database :: result($result_last_attempt, 0, 0); if ($count_attempts > 0) - echo ' '; + echo ' '; } echo ''; @@ -977,8 +978,7 @@ if (empty($_GET['details'])) { $links = Tracking::count_student_visited_links($student_id, $course_code, $session_id); $chat_last_connection = Tracking::chat_last_connection($student_id, $course_code, $session_id); $documents = Tracking::count_student_downloaded_documents($student_id, $course_code, $session_id); - $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $session_id); - + $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $session_id); $csv_content[] = array ( get_lang('Student_publication'), @@ -1038,8 +1038,7 @@ if (empty($_GET['details'])) { Date: Thu, 19 Jul 2012 14:51:15 +0200 Subject: [PATCH 34/36] Minor - Updating lang var --- main/inc/lib/userportal.lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index c3f945b4e4..da97a684f6 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -189,7 +189,7 @@ class IndexManager { if ($show_course_link) { if (!api_is_drh() && !api_is_session_admin()) { - $html .= '
  • '.get_lang('CourseManagement').'
  • '; + $html .= '
  • '.get_lang('CourseCatalog').'
  • '; } else { $html .= '
  • '.get_lang('Dashboard').'
  • '; } @@ -824,8 +824,7 @@ class IndexManager { //Course management if ($show_course_link) { if (!api_is_drh()) { - $my_account_content .= '
  • '.get_lang('CourseManagement').'
  • '; - + $my_account_content .= '
  • '.get_lang('CourseCatalog').'
  • '; if (isset($_GET['history']) && intval($_GET['history']) == 1) { $my_account_content .= '
  • '.get_lang('DisplayTrainingList').'
  • '; From 1b2cdc193fe385a4288b179f96ed4787c71cc73f Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 15:53:19 +0200 Subject: [PATCH 35/36] Fixing bad validation see #5140 --- main/inc/lib/course.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index beb6e78b6c..fbcca277f2 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3693,7 +3693,7 @@ class CourseManager { foreach ($courses as &$my_course) { $course_info = api_get_course_info($my_course['course_code']); - if ($course_info['visibility'] = COURSE_VISIBILITY_CLOSED) { + if ($course_info['visibility'] == COURSE_VISIBILITY_CLOSED) { continue; } From d6fee94338675c97f1b6d66ff12e536e51d435cd Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 19 Jul 2012 16:09:35 +0200 Subject: [PATCH 36/36] Fixing bad validation see #5140 --- main/inc/lib/course.lib.php | 23 +++++----- main/template/default/layout/hot_courses.tpl | 45 +++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index fbcca277f2..3b7bb2aef6 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3665,7 +3665,8 @@ class CourseManager { } } - $table_course_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $table_course_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $table_course = Database::get_main_table(TABLE_MAIN_COURSE); //@todo all dates in the tracking_course_access, last_access are in the DB time (NOW) not UTC /* @@ -3678,8 +3679,11 @@ class CourseManager { //$table_course_access table uses the now() and interval ... - $sql = "SELECT COUNT(course_access_id) course_count, course_code FROM $table_course_access - WHERE login_course_date <= now() AND login_course_date > DATE_SUB(now(), INTERVAL $days DAY) + $sql = "SELECT COUNT(course_access_id) course_count, a.course_code, visibility FROM $table_course c INNER JOIN $table_course_access a + ON (c.code = a.course_code) + WHERE login_course_date <= now() AND + login_course_date > DATE_SUB(now(), INTERVAL $days DAY) AND + visibility <> '".COURSE_VISIBILITY_CLOSED."' GROUP BY course_code ORDER BY course_count DESC LIMIT $limit"; @@ -3691,12 +3695,7 @@ class CourseManager { $ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote'; foreach ($courses as &$my_course) { - $course_info = api_get_course_info($my_course['course_code']); - - if ($course_info['visibility'] == COURSE_VISIBILITY_CLOSED) { - continue; - } - + $course_info = api_get_course_info($my_course['course_code']); $my_course['extra_info'] = $course_info; $my_course['extra_info']['go_to_course_button'] = ''; @@ -3705,16 +3704,16 @@ class CourseManager { $course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM && api_user_is_login()) || in_array($course_info['real_id'], $my_course_code_list)) ) { - $my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$my_course['extra_info']['path'].'/index.php', array('class' => 'btn btn-primary')); + $my_course['extra_info']['go_to_course_button'] = Display::url(get_lang('GoToCourse'), api_get_path(WEB_COURSE_PATH).$course_info['path'].'/index.php', array('class' => 'btn btn-primary')); } //Description $my_course['extra_info']['description_button'] = ''; if ($course_info['visibility'] == COURSE_VISIBILITY_OPEN_WORLD || in_array($course_info['real_id'], $my_course_code_list) ) { - $my_course['extra_info']['description_button'] = Display::url(get_lang('Description'), api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$my_course['course_code'], array('class' => 'ajax btn')); + $my_course['extra_info']['description_button'] = Display::url(get_lang('Description'), api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=show_course_information&code='.$course_info['code'], array('class' => 'ajax btn')); } - $my_course['extra_info']['teachers'] = CourseManager::get_teacher_list_from_course_code_to_string($my_course['course_code']); + $my_course['extra_info']['teachers'] = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']); $point_info = self::get_course_ranking($course_info['real_id'], 0); $my_course['extra_info']['rating_html'] = Display::return_rating_system('star_'.$course_info['real_id'], $ajax_url.'&course_id='.$course_info['real_id'], $point_info); } diff --git a/main/template/default/layout/hot_courses.tpl b/main/template/default/layout/hot_courses.tpl index ab70aaf51b..04106f3208 100644 --- a/main/template/default/layout/hot_courses.tpl +++ b/main/template/default/layout/hot_courses.tpl @@ -27,33 +27,36 @@ $(document).ready( function() {
    {{"HottestCourses"|display_page_header}}
    - {% for hot_course in hot_courses %} -
    -
    -
    -
    -
    - - {# html_image file=$hot_course.extra_info.course_image #} + {% for hot_course in hot_courses %} + + {% if hot_course.extra_info.title %} +
    +
    +
    +
    +
    + + {# html_image file=$hot_course.extra_info.course_image #} +
    -
    -
    -
    -

    {{ hot_course.extra_info.name }}

    -
    {{ hot_course.extra_info.teachers }}
    - - {{ hot_course.extra_info.rating_html }} +
    +
    +

    {{ hot_course.extra_info.title}}

    +
    {{ hot_course.extra_info.teachers }}
    + + {{ hot_course.extra_info.rating_html }} +
    +

    + {{ hot_course.extra_info.go_to_course_button }} + {{ hot_course.extra_info.description_button }} +

    -

    - {{ hot_course.extra_info.go_to_course_button }} - {{ hot_course.extra_info.description_button }} -

    -
    - {% endfor %} + {% endif %} + {% endfor %}
    {% endif %}