diff --git a/.gitignore b/.gitignore index e96a5c109c..439a7bdcff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Chamilo configuration main/inc/conf +<<<<<<< HEAD app/cache/* app/config/* app/data/* @@ -9,6 +10,12 @@ app/logs/* archive/* archive/.htaccess archive/index.html +======= + +# Temp directories +archive/* +!archive/.htaccess +>>>>>>> julio19x # Courses @@ -37,6 +44,10 @@ searchdb/* .idea/cssxfire.xml *.orig +<<<<<<< HEAD nbproject/* -vendor/.git \ No newline at end of file +vendor/.git +======= +nbproject/* +>>>>>>> julio19x diff --git a/documentation/changelog.html b/documentation/changelog.html index a7558e8b02..b04a1e4c09 100644 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -75,7 +75,12 @@

Mystery is a name we give new versions before we know their name.

New Features

Improvements

-

Chamilo 1.10 - Guía de Instalación

- -Esta versión no es totalmente actualizada. Por favor consultar versión en inglés. + +

Chamilo 1.9 - Guía de Instalación

Gracias por descargar Chamilo, la suite de aprendizaje de código abierto profesional.

- -

Este procedimiento creará un nuevo icono en su editor en línea de Chamilo, el cual hará posible la inserción de - fórmulas matemáticas en sus documentos.

-
+

8. Fórmulas matemáticas con ASCIIMathML

-

Las fórmulas matemáticas pueden ser renderizadas en páginas web usando el script ASCIIMathML.js (en su versión - modificada para Chamilo). Para más información sobre este script y sobre la sintaxis de fórmulas de ASCIIMath, ver - http://www1.chapman.edu/~jipsen/mathml/asciimath.html - y http://dlippman.imathas.com/asciimathtex/AMT.html. -

+

Las fórmulas matemáticas pueden ser renderizadas en páginas web usando el script ASCIIMathML.js (en su versión modificada para Chamilo). Para más información sobre este script y sobre la sintaxis de fórmulas de ASCIIMath, ver http://www1.chapman.edu/~jipsen/mathml/asciimath.html y http://dlippman.imathas.com/asciimathtex/AMT.html.

-

Para escribir fórmulas ASCIIMath en documentos, es necesario activar el plugin correspondiente del editor en línea. - Para hacerlo, ver la sección de administración de la plataforma, "Administración > Parámetros de configuración - > > Editor WYSIWYG". - Activar el parámetro "Editor matemático ASCIIMathML".

+

Para escribir fórmulas ASCIIMath en documentos, es necesario activar el plugin correspondiente del editor en línea. Para hacerlo, ver la sección de administración de la plataforma, "Administración > Parámetros de configuración > > Editor WYSIWYG". +Activar el parámetro "Editor matemático ASCIIMathML".

El script ASCIIMathML.js puede mostrar fórmulas matemáticas en los documentos de dos formas:

-

Para proveer image-based fallback en un sistema en producción, debería seleccionar e instalar en su - servidor algun software de renderización TeX, como:

+

Para proveer image-based fallback en un sistema en producción, debería seleccionar e instalar en su servidor algun software de renderización TeX, como:

Y como alternativa, puede intentar servicios públicos, como:

Abrir el fichero .../chamilo/main/inc/lib/asciimath/ASCIIMathML.js con un editor de texto. - Encuentre un lugar al inicio de la línea que inicializa la variable AMTcgiloc. - Podría necesitar modificar el ejemplo para tener algo como:

+Encuentre un lugar al inicio de la línea que inicializa la variable AMTcgiloc. +Podría necesitar modificar el ejemplo para tener algo como:

-

Para formas de probar como la variable AMTcgiloc tiene que ser configurada, existen unos ejemplos - (en comentario) dentro del script.

-
+

Para formas de probar como la variable AMTcgiloc tiene que ser configurada, existen unos ejemplos (en comentario) dentro del script.

+ +

9. Fórmulas matemáticas con WIRIS

+

Instalando este plugin obtendrá WIRIS editor y WIRIS CAS.
La activación no se realiza completamente si previamente no ha descargado el PHP plugin for FCKeditor de WIRIS y descomprimido su contenido en el directorio de Chamilo main/inc/lib/fckeditor/editor/plugins/fckeditor_wiris/
Esto es necesario debido a que Wiris es un software propietario y los servicios de Wiris son comerciales. Para realizar ajustes en el plugin edite el archivo configuration.ini o sustituya su contenido por el de configuration.ini.default que acompaña a Chamilo. +

+ +
+

10. Indexación de texto completo con Xapian

-

Instalando este plugin obtendrá WIRIS editor y WIRIS CAS.
La activación no se realiza completamente si - previamente no ha descargado el PHP plugin for FCKeditor de WIRIS y descomprimido su - contenido en el directorio de Chamilo main/inc/lib/fckeditor/editor/plugins/fckeditor_wiris/
Esto es necesario - debido a que Wiris es un software propietario y los servicios de Wiris son comerciales. Para realizar ajustes en el - plugin edite el archivo configuration.ini o sustituya su contenido por el de configuration.ini.default que acompaña - a Chamilo. +

+Nota: Este paso requiere de un servidor dedicado o servidor virtual privado (VPS) porque los paquetes involucrados no están disponibles en la mayoría de soluciones de hosting compartido. +

+

+En Debian o Ubuntu 10.04 o superior, usted simplemente puede instalar el paquete php5-xapian y reiniciar su servidor web: +

+sudo apt-get install php5-xapian
+sudo /etc/init.d/apache2 restart
+
+

+

+A continuación, vaya a la página de administración -> Ajustes de configuración -> Buscar y habilitar la herramienta de búsqueda. Siga las recomendaciones de la página para obtener la suite completa de indexación instalada. Una vez que haya terminado, todos los documentos importados en su portal Chamilo en un formato reconocido serán indexados y buscados. En formación de administradores de Chamilo ( el cual puede preguntar a cualquier Proveedor Oficial de Chamilo) incluyen una revisión completa de la función de búsqueda de texto completo. +

+ +
+

11. Chamilo Rapid - sistema conversion PPT

+

+Nota: Este paso requiere un servidor dedicado o un servidor dedicado virtual ya que los paquetes involucrados no están disponibles en la mayoría de soluciones de hosting compartido. (Consulte con su proveedor): +

+

+En Debian o Ubuntu 11.10 y superior, instale LibreOffice.org v3 e iniciarlo como un servidor en segundo plano: +

+sudo apt-get install libreoffice
+sudo soffice "--accept=socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;" --headless --nodefault --nofirststartwizard --nolockcheck --nologo --norestore
+
+

+

+A continuación, vaya a la página de administración -> Chamilo Rapid y establecer el host a "localhost" y el puerto a "2002". Guarde los cambios. Vaya a su curso, en la pantalla de herramientas de aprendizaje y verá que apareció un nuevo icono. Importar tu PPT. Esto debería funcionar. +

+

+Nota: A veces, esto no se resuelve tan fácilmente. Usted probablemente tenga que solicitar la asistencia de algún administrador de sistemas con un poco de experiencia en Java y PHP, o siempre podrá preguntar a uno de los proveedores oficiales de Chamilo para asistirle (pregunte por un contrato comercial garantizado). +

+ +
+

12. Configuración de tareas programadas

+

+Desde Chamilo 1.8.8, algunas tareas necesitan ejecutarse con regularidad con el fin de obtener lo mejor de los recursos del servidor. Una de las tareas de este tipo (y el único en todo en el momento de Chamilo 1.8.8) es el envío de notificaciones de mensajería interna por e-mail, es decir, cuando usted recibe un correo electrónico de otra persona o de un grupo dentro de la mensajería interna del sistema de Chamilo, si se envían todos los e-mails inmediatamente, puede que no llegue a recibir el correo a su ritmo, una vez al día o una vez a la semana. Para casos como este, como administrador de Chamilo, debe configurar un proceso cron en el servidor para comprobar la cola de mensajes de correo electrónico y enviarlo puntualmente. +

+

+Configurar una tarea de cron es fácil y hay varias maneras de hacerlo. Le recomendamos echar un vistazo a la documentación de Drupal para configurar el cron y definir su propio proceso de cron como: +

+35 * * * * wget -O - -q -t 1 http://campus.example.com/main/cron/run.php
+
+

+

+Asegúrese de revisar el run.php tal vez desee cambiar algunas algunas opciones de configuración. +

+ +
+

13. Cambiando el orden del nombre/apellido en el idioma

+

+Como Chamilo se hace más popular y atraviesa muchas fronteras ahora, es frecuente que los administradores quieran pedir cambiar el orden del nombre y apellido en los campos de las tablas, y también en qué campo se pondrá en primer lugar. +

+

+Esto fácilmente se puede modificar editando el archivo main/inc/lib/internationalization_database/name_order_conventions.php, buscando nuestro idioma y cambiando los campos. Es tan simple que se explica por sí mismo y se ve así: +

+'simpl_chinese' => array( 'format' => 'title last_name first_name', 'sort_by' => 'last_name' ), // Eastern order
+
+Siéntase libre de cambiar esto a +
+'simpl_chinese' => array( 'format' => 'title first_name lastname', 'sort_by' => 'last_name' ), // Eastern order
+
+por ejemplo. El efecto debería ser inmediato.

-
+

-
-
- Dirección de Contacto: Chamilo
- Correo: info@chamilo.org
+
+
+ Dirección de Contacto: Chamilo
+ Correo: info@chamilo.org

-
+
-
-Valid XHTML 1.0 Transitional - - Valid CSS - +
+ Valid XHTML 1.0 Transitional + + Valid CSS + diff --git a/home/default_platform_document/template_thumb/coursetitle.gif b/home/default_platform_document/template_thumb/coursetitle.gif index fed4d9ec00..986dd9df70 100755 Binary files a/home/default_platform_document/template_thumb/coursetitle.gif and b/home/default_platform_document/template_thumb/coursetitle.gif differ diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index cee7cbbcbe..48ecf05d29 100644 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -15,26 +15,19 @@ * This function allows easy activating and inactivating of regions * @author Julio Montoya Beeznest 2012 */ -function handle_regions() -{ +function handle_regions() { if (isset($_POST['submit_plugins'])) { store_regions(); // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); Display :: display_confirmation_message(get_lang('SettingsStored')); } $plugin_obj = new AppPlugin(); - $possible_plugins = $plugin_obj->read_plugins_from_path(); + $possible_plugins = $plugin_obj->read_plugins_from_path(); $installed_plugins = $plugin_obj->get_installed_plugins(); if (!empty($installed_plugins)) { @@ -42,9 +35,7 @@ function handle_regions() } else { $not_installed = $possible_plugins; } - echo '
'; + echo ''; echo ''; echo ''; echo ''; } } @@ -104,35 +88,26 @@ function handle_regions() echo ''; } -function handle_extensions() -{ +function handle_extensions() { echo Display::page_subheader(get_lang('ConfigureExtensions')); echo ''.get_lang('Ppt2lp').''; } - /** * This function allows easy activating and inactivating of plugins * @todo: a similar function needs to be written to activate or inactivate additional tools. * @author Patrick Cool , Ghent University * @author Julio Montoya Beeznest 2012 */ -function handle_plugins() -{ +function handle_plugins() { $plugin_obj = new AppPlugin(); - if (isset($_POST['submit_plugins'])) { + if (isset($_POST['submit_plugins'])) { store_plugins(); // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); Display :: display_confirmation_message(get_lang('SettingsStored')); } @@ -141,8 +116,7 @@ function handle_plugins() //Plugins NOT installed echo Display::page_subheader(get_lang('Plugins')); - echo '
'; + echo ''; echo '
'; @@ -88,14 +79,7 @@ function handle_regions() } else { $region_list = $plugin_region_list; } - echo Display::select( - 'plugin_'.$plugin.'[]', - $region_list, - $selected_plugins, - array('multiple' => 'multiple', 'style' => 'width:500px'), - true, - get_lang('None') - ); + echo Display::select('plugin_'.$plugin.'[]', $region_list, $selected_plugins, array('multiple' => 'multiple', 'style' => 'width:500px'), true, get_lang('None')); echo '
'; echo ''; echo ''; @@ -210,17 +176,16 @@ function handle_plugins() echo ''; echo ''; echo ''; - } /** * This function allows the platform admin to choose the default stylesheet * @author Patrick Cool , Ghent University * @author Julio Montoya , Chamilo - */ -function handle_stylesheets() -{ +*/ +function handle_stylesheets() { global $_configuration; + // Current style. $currentstyle = api_get_setting('stylesheets'); @@ -238,24 +203,14 @@ function handle_stylesheets() $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2'); //$form->addElement('header', get_lang('UploadNewStylesheet')); - $form->addElement( - 'text', - 'name_stylesheet', - get_lang('NameStylesheet'), - array('size' => '40', 'maxlength' => '40') - ); + $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40')); $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet')); $allowed_file_types = array('css', 'zip', 'jpeg', 'jpg', 'png', 'gif', 'ico','psd'); - $form->addRule( - 'new_stylesheet', - get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', - 'filetype', - $allowed_file_types - ); + $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types); $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); - $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Upload'), array('class' => 'save')); + $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Upload'), array('class'=>'save')); $show_upload_form = false; @@ -277,18 +232,12 @@ function handle_stylesheets() $values = $form->exportValues(); $picture_element = $form->getElement('new_stylesheet'); $picture = $picture_element->getValue(); - $result = upload_stylesheet($values, $picture); + $result = upload_stylesheet($values, $picture); // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); if ($result) { Display::display_confirmation_message(get_lang('StylesheetAdded')); @@ -296,11 +245,10 @@ function handle_stylesheets() } } - $form_change = new FormValidator('stylesheet_upload', 'post', api_get_self( - ).'?category=Stylesheets', null, array('id' => 'stylesheets_id')); + $form_change = new FormValidator('stylesheet_upload', 'post', api_get_self().'?category=Stylesheets', null, array('id' => 'stylesheets_id')); $list_of_styles = array(); - $list_of_names = array(); + $list_of_names = array(); $selected = null; $dirpath = ''; $safe_style_dir = ''; @@ -319,7 +267,7 @@ function handle_stylesheets() $selected = $style_dir; $safe_style_dir = $style_dir; } else { - if (!isset($_POST['style']) && ($currentstyle == $style_dir || ($style_dir == 'chamilo' && !$currentstyle))) { + if (!isset($_POST['style']) && ($currentstyle == $style_dir || ($style_dir == 'chamilo' && !$currentstyle))) { $selected = $style_dir; } else { $selected = ''; @@ -328,8 +276,8 @@ function handle_stylesheets() $show_name = ucwords(str_replace('_', ' ', $style_dir)); if ($is_style_changeable) { - $list_of_styles[$style_dir] = ""; - $list_of_names[$style_dir] = $show_name; + $list_of_styles[$style_dir] = ""; + $list_of_names[$style_dir] = $show_name; //echo ""; //echo ''.$show_name.''; } else { @@ -345,7 +293,7 @@ function handle_stylesheets() //Sort styles in alphabetical order asort($list_of_names); $select_list = array(); - foreach ($list_of_names as $style_dir => $item) { + foreach ($list_of_names as $style_dir=>$item) { $select_list[$style_dir] = strip_tags($list_of_styles[$style_dir]); } @@ -364,23 +312,15 @@ function handle_stylesheets() if (is_dir($dir)) { $zip = new PclZip($arch); // Remove path prefix except the style name and put file on disk - $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir, 0, -strlen($safe_style_dir))); + $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir,0,-strlen($safe_style_dir))); } - $str = ''.get_lang('ClickHereToDownloadTheFile').''; - Display::display_normal_message($str, false); + $str = ''.get_lang('ClickHereToDownloadTheFile').''; + Display::display_normal_message($str,false); } } + if ($is_style_changeable) { - $group[] = $form_change->createElement( - 'button', - 'save', - get_lang('SaveSettings'), - array('class' => 'btn btn-primary') - ); + $group[] = $form_change->createElement('button', 'save', get_lang('SaveSettings'), array('class' => 'btn btn-primary')); $group[] = $form_change->createElement('button', 'preview', get_lang('Preview'), array('class' => 'btn')); $group[] = $form_change->createElement('button', 'download', get_lang('Download'), array('class' => 'btn')); $form_change->addGroup($group); @@ -391,10 +331,7 @@ function handle_stylesheets() $( "#tabs" ).tabs(); }); '; - echo Display::tabs( - array(get_lang('Update'), get_lang('UploadNewStylesheet')), - array($form_change->return_form(), $form->return_form()) - ); + echo Display::tabs(array(get_lang('Update'), get_lang('UploadNewStylesheet')), array($form_change->return_form(), $form->return_form())); } else { $form_change->display(); } @@ -413,8 +350,7 @@ function handle_stylesheets() * @version May 2008 * @since Dokeos 1.8.5 */ -function upload_stylesheet($values, $picture) -{ +function upload_stylesheet($values, $picture) { $result = false; // Valid name for the stylesheet folder. $style_name = api_preg_replace('/[^A-Za-z0-9]/', '', $values['name_stylesheet']); @@ -455,10 +391,7 @@ function upload_stylesheet($values, $picture) $error_string .= '
  • '.$invalid_file.'
  • '; } $error_string .= ''; - Display::display_error_message( - get_lang('ErrorStylesheetFilesExtensionsInsideZip').$error_string, - false - ); + Display::display_error_message(get_lang('ErrorStylesheetFilesExtensionsInsideZip').$error_string, false); } else { // If the zip does not contain a single directory, extract it. if (!$single_directory) { @@ -469,9 +402,7 @@ function upload_stylesheet($values, $picture) $extraction_path = api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'; for ($i = 0; $i < $num_files; $i++) { $entry = $zip->getNameIndex($i); - if (substr($entry, -1) == '/') { - continue; - } + if (substr($entry, -1) == '/') continue; $pos_slash = strpos($entry, '/'); $entry_without_first_dir = substr($entry, $pos_slash + 1); @@ -505,13 +436,11 @@ function upload_stylesheet($values, $picture) move_uploaded_file($picture['tmp_name'], api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'.$picture['name']); $result = true; } - return $result; } -function store_regions() -{ - $plugin_obj = new AppPlugin(); +function store_regions() { + $plugin_obj = new AppPlugin(); // Get a list of all current 'Plugins' settings $installed_plugins = $plugin_obj->get_installed_plugins(); @@ -534,27 +463,23 @@ function store_regions() if (!empty($areas_to_installed)) { $plugin_obj->remove_all_regions($plugin); foreach ($areas_to_installed as $region) { - if (!empty($region) && $region != '-1') { + if (!empty($region) && $region != '-1' ) { $plugin_obj->add_to_region($plugin, $region); } } } } } - api_set_setting_last_update(); } /** * This function allows easy activating and inactivating of plugins * @author Patrick Cool , Ghent University - */ -function store_plugins() -{ - +*/ +function store_plugins() { $plugin_obj = new AppPlugin(); // Get a list of all current 'Plugins' settings - $plugin_list = $plugin_obj->read_plugins_from_path(); $installed_plugins = array(); @@ -574,23 +499,18 @@ function store_plugins() foreach ($remove_plugins as $plugin) { $plugin_obj->uninstall($plugin); } - api_set_setting_last_update(); } /** * This function allows the platform admin to choose which should be the default stylesheet * @author Patrick Cool , Ghent University - */ -function store_stylesheets() -{ +*/ +function store_stylesheets() { // Insert the stylesheet. $style = Database::escape_string($_POST['style']); - if (is_style($style)) { api_set_setting('stylesheets', $style, null, 'stylesheets', api_get_current_access_url_id()); - api_set_setting_last_update(); } - return true; } @@ -600,15 +520,13 @@ function store_stylesheets() * @param string Style * @return bool True if this style is recognized, false otherwise */ -function is_style($style) -{ +function is_style($style) { $dir = api_get_path(SYS_PATH).'main/css/'; $dirs = scandir($dir); $style = str_replace(array('/', '\\'), array('', ''), $style); // Avoid slashes or backslashes. if (in_array($style, $dirs) && is_dir($dir.$style)) { return true; } - return false; } @@ -617,45 +535,25 @@ function is_style($style) * TODO: support for multiple site. aka $_configuration['access_url'] == 1 * @author Marco Villegas */ -function handle_search() -{ +function handle_search() { global $SettingsStored, $_configuration; require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; $search_enabled = api_get_setting('search_enabled'); $form = new FormValidator('search-options', 'post', api_get_self().'?category=Search'); - - $values = api_get_settings_options('search_enabled'); $form->addElement('header', null, get_lang('SearchEnabledTitle')); - $group = array(); + $group = array (); if (is_array($values)) { foreach ($values as $key => $value) { - $element = & $form->createElement( - 'radio', - 'search_enabled', - '', - get_lang($value['display_text']), - $value['value'] - ); - /* $hide_element is not defined - if ($hide_element) { - $element->freeze(); - } - */ + $element = & $form->createElement('radio', 'search_enabled', '', get_lang($value['display_text']), $value['value']); $group[] = $element; } } //SearchEnabledComment - $form->addGroup( - $group, - 'search_enabled', - array(get_lang('SearchEnabledTitle'), get_lang('SearchEnabledComment')), - '
    ', - false - ); + $form->addGroup($group, 'search_enabled', array(get_lang('SearchEnabledTitle'), get_lang('SearchEnabledComment')), '
    ', false); $search_enabled = api_get_setting('search_enabled'); @@ -672,54 +570,25 @@ function handle_search() $specific_fields = get_specific_field_list(); if ($search_enabled == 'true') { - - // Search_show_unlinked_results. - //$form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle')); - //$form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment')); $values = api_get_settings_options('search_show_unlinked_results'); - $group = array(); + $group = array (); foreach ($values as $key => $value) { - $element = & $form->createElement( - 'radio', - 'search_show_unlinked_results', - '', - get_lang($value['display_text']), - $value['value'] - ); + $element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']); $group[] = $element; } - $form->addGroup( - $group, - 'search_show_unlinked_results', - array(get_lang('SearchShowUnlinkedResultsTitle'), get_lang('SearchShowUnlinkedResultsComment')), - '', - false - ); + $form->addGroup($group, 'search_show_unlinked_results', array(get_lang('SearchShowUnlinkedResultsTitle'),get_lang('SearchShowUnlinkedResultsComment')), '', false); $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results'); - // Search_prefilter_prefix. - //$form->addElement('header', null, get_lang('SearchPrefilterPrefix')); - //$form->addElement('label', null, get_lang('SearchPrefilterPrefixComment')); - $sf_values = array(); foreach ($specific_fields as $sf) { - $sf_values[$sf['code']] = $sf['name']; + $sf_values[$sf['code']] = $sf['name']; } $group = array(); - $url = Display::div( - Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), - array('class' => 'sectioncomment') - ); + $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment')); if (empty($sf_values)) { $form->addElement('html', get_lang('SearchPrefilterPrefix').$url); } else { - $form->addElement( - 'select', - 'search_prefilter_prefix', - array(get_lang('SearchPrefilterPrefix'), $url), - $sf_values, - '' - ); + $form->addElement('select', 'search_prefilter_prefix', array(get_lang('SearchPrefilterPrefix'), $url), $sf_values, ''); $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix'); } @@ -727,8 +596,7 @@ function handle_search() $default_values['search_enabled'] = $search_enabled; - //$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required'); - $form->addElement('style_submit_button', 'submit', get_lang('Save'), 'class="save"'); + $form->addElement('style_submit_button', 'submit', get_lang('Save'),'class="save"'); $form->setDefaults($default_values); echo '
    '; @@ -736,7 +604,8 @@ function handle_search() echo '
    '; if ($search_enabled == 'true') { - $xapian_path = api_get_path(SYS_PATH_APP).'data/searchdb'; + require_once api_get_path(LIBRARY_PATH).'sortable_table.class.php'; + $xapian_path = api_get_path(SYS_PATH).'searchdb'; /* @todo Test the Xapian connection @@ -762,9 +631,9 @@ function handle_search() } */ - $xapian_loaded = Display::return_icon('bullet_green.gif', get_lang('Ok')); - $dir_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); - $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok')); + $xapian_loaded = Display::return_icon('bullet_green.gif', get_lang('Ok')); + $dir_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); + $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok')); $specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); //Testing specific fields @@ -784,10 +653,10 @@ function handle_search() $dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error')); } - $data[] = array(get_lang('XapianModuleInstalled'), $xapian_loaded); - $data[] = array(get_lang('DirectoryExists').' - '.$xapian_path, $dir_exists); - $data[] = array(get_lang('IsWritable').' - '.$xapian_path, $dir_is_writable); - $data[] = array(get_lang('SpecificSearchFieldsAvailable'), $specific_fields_exists); + $data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded); + $data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists); + $data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable); + $data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists); echo Display::tag('h3', get_lang('Settings')); $table = new SortableTableFromArray($data); @@ -797,16 +666,16 @@ function handle_search() //@todo windows support if (api_is_windows_os() == false) { - $list_of_programs = array('pdftotext', 'ps2pdf', 'catdoc', 'html2text', 'unrtf', 'catppt', 'xls2csv'); + $list_of_programs = array('pdftotext','ps2pdf', 'catdoc','html2text','unrtf', 'catppt', 'xls2csv'); - foreach ($list_of_programs as $program) { + foreach($list_of_programs as $program) { $output = $ret_val = null; exec("which $program", $output, $ret_val); $icon = Display::return_icon('bullet_red.gif', get_lang('NotInstalled')); if (!empty($output[0])) { $icon = Display::return_icon('bullet_green.gif', get_lang('Installed')); } - $data2[] = array($program, $output[0], $icon); + $data2[]= array($program, $output[0], $icon); } echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles')); $table = new SortableTableFromArray($data2); @@ -815,11 +684,7 @@ function handle_search() $table->set_header(2, get_lang('Status'), false); echo $table->display(); } else { - Display::display_warning_message( - get_lang( - 'YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool' - ) - ); + Display::display_warning_message(get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool')); } } } @@ -831,16 +696,10 @@ function handle_search() * @version August 2008 * @since Dokeos 1.8.6 */ -function handle_templates() -{ +function handle_templates() { if ($_GET['action'] != 'add') { echo ''; } @@ -850,13 +709,7 @@ function handle_templates() // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); } else { if ($_GET['action'] == 'delete' && is_numeric($_GET['id'])) { @@ -865,13 +718,7 @@ function handle_templates() // Add event to the system log $user_id = api_get_user_id(); $category = $_GET['category']; - event_system( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); + event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); } display_templates(); } @@ -884,8 +731,7 @@ function handle_templates() * @version August 2008 * @since Dokeos 1.8.6 */ -function display_templates() -{ +function display_templates() { $table = new SortableTable('templates', 'get_number_of_templates', 'get_template_data', 1); $table->set_additional_parameters(array('category' => Security::remove_XSS($_GET['category']))); $table->set_header(0, get_lang('Image'), true, array('style' => 'width: 101px;')); @@ -905,8 +751,7 @@ function display_templates() * @version August 2008 * @since Dokeos 1.8.6 */ -function get_number_of_templates() -{ +function get_number_of_templates() { // Database table definition. $table_system_template = Database :: get_main_table('system_template'); @@ -932,8 +777,7 @@ function get_number_of_templates() * @version August 2008 * @since Dokeos 1.8.6 */ -function get_template_data($from, $number_of_items, $column, $direction) -{ +function get_template_data($from, $number_of_items, $column, $direction) { // Database table definition. $table_system_template = Database :: get_main_table('system_template'); @@ -947,7 +791,6 @@ function get_template_data($from, $number_of_items, $column, $direction) $row['1'] = get_lang($row['1']); $return[] = $row; } - // Returning all the information for the sortable table. return $return; } @@ -962,17 +805,9 @@ function get_template_data($from, $number_of_items, $column, $direction) * @version August 2008 * @since Dokeos 1.8.6 */ -function actions_filter($id) -{ - $return = ''.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).''; - $return .= ''.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).''; - +function actions_filter($id) { + $return = ''.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).''; + $return .= ''.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).''; return $return; } @@ -986,16 +821,11 @@ function actions_filter($id) * @version August 2008 * @since Dokeos 1.8.6 */ -function image_filter($image) -{ +function image_filter($image) { if (!empty($image)) { - return ''.get_lang('TemplatePreview').''; + return ''.get_lang('TemplatePreview').''; } else { - return ''.get_lang('NoTemplatePreview').''; + return ''.get_lang('NoTemplatePreview').''; } } @@ -1006,12 +836,9 @@ function image_filter($image) * @version August 2008 * @since Dokeos 1.8.6 */ -function add_edit_template() -{ +function add_edit_template() { // Initialize the object. - $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.Security::remove_XSS( - $_GET['action'] - ).'&id='.Security::remove_XSS($_GET['id'])); + $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id'])); // Settting the form elements: the header. if ($_GET['action'] == 'add') { @@ -1025,16 +852,10 @@ function add_edit_template() $form->add_textfield('title', get_lang('Title'), false); // Settting the form elements: the content of the template (wysiwyg editor). - $form->addElement( - 'html_editor', - 'template_text', - get_lang('Text'), - null, - array('ToolbarSet' => 'AdminTemplates', 'Width' => '100%', 'Height' => '400') - ); + $form->addElement('html_editor', 'template_text', get_lang('Text'), null, array('ToolbarSet' => 'AdminTemplates', 'Width' => '100%', 'Height' => '400')); // Settting the form elements: the form to upload an image to be used with the template. - $form->addElement('file', 'template_image', get_lang('Image'), ''); + $form->addElement('file','template_image',get_lang('Image'),''); // Settting the form elements: a little bit information about the template image. $form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70')); @@ -1047,42 +868,26 @@ function add_edit_template() $result = Database::query($sql); $row = Database::fetch_array($result); - $defaults['template_id'] = intval($_GET['id']); - $defaults['template_text'] = $row['content']; + $defaults['template_id'] = intval($_GET['id']); + $defaults['template_text'] = $row['content']; // Forcing get_lang(). - $defaults['title'] = get_lang($row['title']); + $defaults['title'] = get_lang($row['title']); // Adding an extra field: a hidden field with the id of the template we are editing. $form->addElement('hidden', 'template_id'); // Adding an extra field: a preview of the image that is currently used. if (!empty($row['image'])) { - $form->addElement( - 'static', - 'template_image_preview', - '', - ''.get_lang(
-                    'TemplatePreview'
-                ).'' - ); + $form->addElement('static', 'template_image_preview', '', ''.get_lang('TemplatePreview').''); } else { - $form->addElement( - 'static', - 'template_image_preview', - '', - ''.get_lang('NoTemplatePreview').'' - ); + $form->addElement('static', 'template_image_preview', '', ''.get_lang('NoTemplatePreview').''); } // Setting the information of the template that we are editing. $form->setDefaults($defaults); } // Settting the form elements: the submit button. - $form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="save"'); + $form->addElement('style_submit_button' , 'submit', get_lang('Ok') ,'class="save"'); // Setting the rules: the required fields. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); @@ -1097,14 +902,12 @@ function add_edit_template() $values = $form->exportValues(); // Upload the file. if (!empty($_FILES['template_image']['name'])) { - $upload_ok = FileManager::process_uploaded_file($_FILES['template_image']); + require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; + $upload_ok = process_uploaded_file($_FILES['template_image']); if ($upload_ok) { // Try to add an extension to the file if it hasn't one. - $new_file_name = FileManager::add_ext_on_mime( - stripslashes($_FILES['template_image']['name']), - $_FILES['template_image']['type'] - ); + $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']); // The upload directory. $upload_dir = api_get_path(SYS_PATH).'home/default_platform_document/template_thumb/'; @@ -1130,52 +933,39 @@ function add_edit_template() } $temp->send_image($upload_dir.$new_file_name); } - } - - // Store the information in the database (as insert or as update). - $table_system_template = Database :: get_main_table('system_template'); - if ($_GET['action'] == 'add') { - $content_template = '{CSS}'.Database::escape_string( - $values['template_text'] - ).''; - $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string( - $values['title'] - )."','".$content_template."','".Database::escape_string($new_file_name)."')"; - $result = Database::query($sql); - - // Display a feedback message. - Display::display_confirmation_message(get_lang('TemplateAdded')); - echo ''.Display::return_icon( - 'new_template.png', - get_lang('AddTemplate'), - '', - ICON_SIZE_MEDIUM - ).''; - } else { - $content_template = '{CSS}'.Database::escape_string( - $values['template_text'] - ).''; - $sql = "UPDATE $table_system_template set title = '".Database::escape_string( - $values['title'] - )."', content = '".$content_template."'"; - if (!empty($new_file_name)) { - $sql .= ", image = '".Database::escape_string($new_file_name)."'"; - } - $sql .= " WHERE id='".Database::escape_string($_GET['id'])."'"; - $result = Database::query($sql); - - // Display a feedback message. - Display::display_confirmation_message(get_lang('TemplateEdited')); - } + } + + // Store the information in the database (as insert or as update). + $table_system_template = Database :: get_main_table('system_template'); + if ($_GET['action'] == 'add') { + $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; + $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')"; + $result = Database::query($sql); + + // Display a feedback message. + Display::display_confirmation_message(get_lang('TemplateAdded')); + echo ''.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).''; + } else { + $content_template = '{CSS}'.Database::escape_string($values['template_text']).''; + $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'"; + if (!empty($new_file_name)) { + $sql .= ", image = '".Database::escape_string($new_file_name)."'"; + } + $sql .= " WHERE id='".Database::escape_string($_GET['id'])."'"; + $result = Database::query($sql); + + // Display a feedback message. + Display::display_confirmation_message(get_lang('TemplateEdited')); + } } - Security::clear_token(); - display_templates(); + Security::clear_token(); + display_templates(); } else { $token = Security::get_token(); - $form->addElement('hidden', 'sec_token'); + $form->addElement('hidden','sec_token'); $form->setConstants(array('sec_token' => $token)); // Display the form. $form->display(); @@ -1191,8 +981,7 @@ function add_edit_template() * @version August 2008 * @since Dokeos 1.8.6 */ -function delete_template($id) -{ +function delete_template($id) { // First we remove the image. $table_system_template = Database :: get_main_table('system_template'); $sql = "SELECT * FROM $table_system_template WHERE id = '".Database::escape_string($id)."'"; @@ -1218,8 +1007,7 @@ function delete_template($id) * @author Guillaume Viguier * @since Chamilo 1.8.7 */ -function select_timezone_value() -{ +function select_timezone_value() { return api_get_timezones(); } @@ -1230,13 +1018,11 @@ function select_timezone_value() * * @author Guillaume Viguier */ -function select_gradebook_number_decimals() -{ +function select_gradebook_number_decimals() { return array('0', '1', '2'); } -function select_gradebook_default_grade_model_id() -{ +function select_gradebook_default_grade_model_id() { $grade_model = new GradeModel(); $models = $grade_model->get_all(); $options = array(); @@ -1246,7 +1032,6 @@ function select_gradebook_default_grade_model_id() $options[$model['id']] = $model['name']; } } - return $options; } @@ -1258,8 +1043,7 @@ function select_gradebook_default_grade_model_id() * * @author Guillaume Viguier */ -function update_gradebook_score_display_custom_values($values) -{ +function update_gradebook_score_display_custom_values($values) { require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/scoredisplay.class.php'; $scoredisplay = ScoreDisplay::instance(); $scores = $values['gradebook_score_display_custom_values_endscore']; @@ -1275,18 +1059,13 @@ function update_gradebook_score_display_custom_values($values) $scoredisplay->update_custom_score_display_settings($final); } -function generate_settings_form($settings, $settings_by_access_list) -{ +function generate_settings_form($settings, $settings_by_access_list) { global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list; $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $form = new FormValidator('settings', 'post', 'settings.php?category='.Security::remove_XSS($_GET['category'])); - $form->addElement( - 'hidden', - 'search_field', - (!empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null) - ); + $form->addElement('hidden', 'search_field', (!empty($_GET['search_field'])?Security::remove_XSS($_GET['search_field']):null)); $url_id = api_get_current_access_url_id(); @@ -1303,49 +1082,26 @@ function generate_settings_form($settings, $settings_by_access_list) $i = 0; foreach ($settings as $row) { - if (in_array($row['variable'], array_keys($settings_to_avoid))) { - continue; - } + if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } if (!empty($_configuration['multiple_access_urls'])) { if (api_is_global_platform_admin()) { if ($row['access_url_locked'] == 0) { if ($url_id == 1) { if ($row['access_url_changeable'] == '1') { - $form->addElement( - 'html', - '' - ); + $form->addElement('html', ''); } else { - $form->addElement( - 'html', - '' - ); + $form->addElement('html', ''); } } else { if ($row['access_url_changeable'] == '1') { - $form->addElement( - 'html', - '
    '. - Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'
    ' - ); + $form->addElement('html', '
    '. + Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')).'
    '); } else { - $form->addElement( - 'html', - '
    '. - Display::return_icon( - 'shared_setting_na.png', - get_lang('ChangeSharedSetting') - ).'
    ' - ); + $form->addElement('html', '
    '. + Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')).'
    '); } } } @@ -1362,21 +1118,17 @@ function generate_settings_form($settings, $settings_by_access_list) $hideme = array('disabled'); } elseif ($url_info['active'] == 1) { // We show the elements. - if (empty($row['variable'])) { + if (empty($row['variable'])) $row['variable'] = 0; - } - if (empty($row['subkey'])) { + if (empty($row['subkey'])) $row['subkey'] = 0; - } - if (empty($row['category'])) { + if (empty($row['category'])) $row['category'] = 0; - } - if (is_array($settings_by_access_list[$row['variable']] [$row['subkey']] [$row['category']])) { + if (is_array($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ])) { // We are sure that the other site have a selected value. - if ($settings_by_access_list[$row['variable']] [$row['subkey']] [$row['category']]['selected_value'] != '') { - $row['selected_value'] = $settings_by_access_list[$row['variable']] [$row['subkey']] [$row['category']]['selected_value']; - } + if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ]['selected_value'] != '') + $row['selected_value'] =$settings_by_access_list[$row['variable']] [$row['subkey']] [ $row['category'] ]['selected_value']; } // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site. } @@ -1385,21 +1137,11 @@ function generate_settings_form($settings, $settings_by_access_list) switch ($row['type']) { case 'textfield': if (in_array($row['variable'], $convert_byte_to_mega_list)) { - $form->addElement( - 'text', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), - array('class' => 'span1', 'maxlength' => '8') - ); + $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('class' => 'span1', 'maxlength' => '8')); $form->applyFilter($row['variable'], 'html_filter'); - $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1); + $default_values[$row['variable']] = round($row['selected_value']/1024/1024, 1); } elseif ($row['variable'] == 'account_valid_duration') { - $form->addElement( - 'text', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - array('maxlength' => '5') - ); + $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; @@ -1427,90 +1169,50 @@ function generate_settings_form($settings, $settings_by_access_list) unset($valid_encodings[$key]); } } - $form->addElement( - 'select', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - $valid_encodings - ); + $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $valid_encodings); $default_values[$row['variable']] = $current_system_encoding; } else { $hideme['class'] = 'span4'; - $form->addElement( - 'text', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - $hideme - ); - $form->applyFilter($row['variable'], 'html_filter'); + $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme); + $form->applyFilter($row['variable'],'html_filter'); $default_values[$row['variable']] = $row['selected_value']; } break; case 'textarea': if ($row['variable'] == 'header_extra_content') { - $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; + $file = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } - $form->addElement( - 'textarea', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - array('class' => 'span6', 'rows' => '10'), - $hideme - ); - $default_values[$row['variable']] = $value; + $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('class'=>'span6','rows'=>'10'), $hideme); + $default_values[$row['variable']] = $value; } elseif ($row['variable'] == 'footer_extra_content') { - $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt'; - $value = ''; - if (file_exists($file)) { - $value = file_get_contents($file); - } - $form->addElement( - 'textarea', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - array('rows' => '10', 'class' => 'span6'), - $hideme - ); - $default_values[$row['variable']] = $value; - } else { - $form->addElement( - 'textarea', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - array('rows' => '10', 'class' => 'span6'), - $hideme - ); - $default_values[$row['variable']] = $row['selected_value']; - } + $file = api_get_path(SYS_PATH).api_get_home_path().'footer_extra_content.txt'; + $value = ''; + if (file_exists($file)) { + $value = file_get_contents($file); + } + $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10', 'class'=>'span6'), $hideme); + $default_values[$row['variable']] = $value; + } else { + $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])) , array('rows'=>'10','class'=>'span6'), $hideme); + $default_values[$row['variable']] = $row['selected_value']; + } break; case 'radio': $values = api_get_settings_options($row['variable']); - $group = array(); - if (is_array($values)) { + $group = array (); + if (is_array($values )) { foreach ($values as $key => $value) { - $element = & $form->createElement( - 'radio', - $row['variable'], - '', - get_lang($value['display_text']), - $value['value'] - ); + $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']); if ($hide_element) { $element->freeze(); } $group[] = $element; } } - $form->addGroup( - $group, - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - '', - false - ); //julio + $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false); //julio $default_values[$row['variable']] = $row['selected_value']; break; case 'checkbox'; @@ -1518,34 +1220,23 @@ function generate_settings_form($settings, $settings_by_access_list) $sql = "SELECT * FROM $table_settings_current WHERE variable='".$row['variable']."' AND access_url = 1"; $result = Database::query($sql); - $group = array(); + $group = array (); while ($rowkeys = Database::fetch_array($result)) { - //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; } + //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; } - // Profile tab option should be hidden when the social tool is enabled. - if (api_get_setting('allow_social_tool') == 'true') { - if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { - continue; - } - } + // Profile tab option should be hidden when the social tool is enabled. + if (api_get_setting('allow_social_tool') == 'true') { + if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; } + } - // Hiding the gradebook option. - if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { - continue; - } + // Hiding the gradebook option. + if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; } - $element = & $form->createElement( - 'checkbox', - $rowkeys['subkey'], - '', - get_lang($rowkeys['subkeytext']) - ); + $element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext'])); if ($row['access_url_changeable'] == 1) { // 2. We look into the DB if there is a setting for a specific access_url. $access_url = $_configuration['access_url']; - if (empty($access_url)) { - $access_url = 1; - } + if (empty($access_url )) $access_url = 1; $sql = "SELECT selected_value FROM $table_settings_current WHERE variable='".$rowkeys['variable']."' AND subkey='".$rowkeys['subkey']."' AND subkeytext='".$rowkeys['subkeytext']."' AND access_url = $access_url"; $result_access = Database::query($sql); $row_access = Database::fetch_array($result_access); @@ -1562,60 +1253,35 @@ function generate_settings_form($settings, $settings_by_access_list) } $group[] = $element; } - $form->addGroup( - $group, - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - '' - ); + $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])),''); break; case 'link': - $form->addElement( - 'static', - null, - array(get_lang($row['title']), get_lang($row['comment'])), - get_lang('CurrentValue').' : '.$row['selected_value'], - $hideme - ); + $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue').' : '.$row['selected_value'], $hideme); break; case 'select': /* * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed. * The functions being called must be added to the file settings.lib.php. */ - $form->addElement( - 'select', - $row['variable'], - array(get_lang($row['title']), get_lang($row['comment'])), - call_user_func('select_'.$row['variable']), - $hideme - ); + $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_'.$row['variable']), $hideme); $default_values[$row['variable']] = $row['selected_value']; break; case 'custom': - break; + break; } switch ($row['variable']) { case 'pdf_export_watermark_enable': - $url = PDF::get_watermark(null); + $url = PDF::get_watermark(null); $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark')); if ($url != false) { - $delete_url = ''.Display::return_icon( - 'delete.png', - get_lang('DelImage') - ).''; + $delete_url = ''.Display::return_icon('delete.png',get_lang('DelImage')).''; $form->addElement('html', ''.$url.' '.$delete_url.''); } - $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); - $form->addRule( - 'pdf_export_watermark_path', - get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', - 'filetype', - $allowed_picture_types - ); + $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); + $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); break; case 'timezone_value': @@ -1623,10 +1289,7 @@ function generate_settings_form($settings, $settings_by_access_list) if (empty($timezone)) { $timezone = _api_get_timezone(); } - $form->addElement( - 'html', - sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time()) - ); + $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time())); break; } } // end for @@ -1635,7 +1298,6 @@ function generate_settings_form($settings, $settings_by_access_list) $form->setDefaults($default_values); } $form->addElement('button', 'submit_fixed_in_bottom', get_lang('SaveSettings'), 'class="save"'); - return $form; } @@ -1644,8 +1306,7 @@ function generate_settings_form($settings, $settings_by_access_list) * @param string $search * @return array */ -function search_setting($search) -{ +function search_setting($search) { if (empty($search)) { return array(); } @@ -1684,6 +1345,5 @@ function search_setting($search) } } } - return $settings; } diff --git a/main/css/base.css b/main/css/base.css index 40e38903f8..a2f0111986 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -262,9 +262,25 @@ form .formw input { margin-top: 2px; } +<<<<<<< HEAD #accept_licence, #checkbox { margin-right: 5px; margin-top: -1px; +======= +/* end chamilo forms fixes */ + +#top_main_content .span3 { + float: left; +} +#top_main_content .control-group .span3 { + float: none; +} +#top_main_content .span9 { + float: left; +} +#top_main_content .span6 { + width: 460px; +>>>>>>> julio19x } /* end chamilo forms fixes */ diff --git a/main/default_course_document/images/logo_chamilo.png b/main/default_course_document/images/logo_chamilo.png new file mode 100644 index 0000000000..b2404dc6b2 Binary files /dev/null and b/main/default_course_document/images/logo_chamilo.png differ diff --git a/main/default_course_document/images/logo_dokeos.png b/main/default_course_document/images/logo_dokeos.png old mode 100755 new mode 100644 index b5a87206dc..b2404dc6b2 Binary files a/main/default_course_document/images/logo_dokeos.png and b/main/default_course_document/images/logo_dokeos.png differ diff --git a/main/document/document.php b/main/document/document.php index a90a51423b..deb4615d43 100644 --- a/main/document/document.php +++ b/main/document/document.php @@ -1268,6 +1268,7 @@ $table_footer = ''; $total_size = 0; if (isset($docs_and_folders) && is_array($docs_and_folders)) { +<<<<<<< HEAD if (api_get_group_id() == 0 || (api_is_allowed_to_edit() || GroupManager::is_subscribed( api_get_user_id(), api_get_group_id() @@ -1275,6 +1276,9 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) { api_get_user_id() )) ) { +======= + if (api_get_group_id() == 0 || ( api_is_allowed_to_edit() || GroupManager::is_subscribed(api_get_user_id(), api_get_group_id()) || GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id()))) { +>>>>>>> julio19x // Create a sortable table with our data $sortable_data = array(); @@ -1583,4 +1587,4 @@ if (!empty($table_footer)) { } // Footer -Display::display_footer(); \ No newline at end of file +Display::display_footer(); diff --git a/main/gradebook/gradebook_flatview.php b/main/gradebook/gradebook_flatview.php index 006f9ec069..a991a11626 100644 --- a/main/gradebook/gradebook_flatview.php +++ b/main/gradebook/gradebook_flatview.php @@ -210,4 +210,4 @@ if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') { echo ''; } -Display :: display_footer(); \ No newline at end of file +Display :: display_footer(); diff --git a/main/gradebook/gradebook_view_result.php b/main/gradebook/gradebook_view_result.php index 3ad8ccb010..38a8978c67 100644 --- a/main/gradebook/gradebook_view_result.php +++ b/main/gradebook/gradebook_view_result.php @@ -538,6 +538,7 @@ if ($file_type == null) { //show the result header } DisplayGradebook :: display_header_result($eval[0], $currentcat[0]->get_id(), 1); } + // Letter-based scores are built from lib/results_data_generator.class.php::get_score_display() $resulttable->display(); Display :: display_footer(); } diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index 54324cdc9d..c893f3b73c 100644 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -20,15 +20,15 @@ class Category implements GradebookItem { // PROPERTIES - private $id; - private $name; - private $description; - private $user_id; - private $course_code; - private $parent; - private $weight; - private $visible; - private $certificate_min_score; + private $id; + private $name; + private $description; + private $user_id; + private $course_code; + private $parent; + private $weight; + private $visible; + private $certificate_min_score; private $session_id; private $skills = array(); private $grade_model_id; @@ -38,105 +38,105 @@ class Category implements GradebookItem // GETTERS AND SETTERS - public function get_id() { - return $this->id; - } + public function get_id() { + return $this->id; + } - public function get_name() { - return $this->name; - } + public function get_name() { + return $this->name; + } - public function get_description() { - return $this->description; - } + public function get_description() { + return $this->description; + } - public function get_user_id() { - return $this->user_id; - } + public function get_user_id() { + return $this->user_id; + } - public function get_certificate_min_score () { - if(!empty($this->certificate_min_score)) { - return $this->certificate_min_score; - } else { - return null; - } - } + public function get_certificate_min_score () { + if(!empty($this->certificate_min_score)) { + return $this->certificate_min_score; + } else { + return null; + } + } - public function get_course_code() { - return $this->course_code; - } + public function get_course_code() { + return $this->course_code; + } - public function get_parent_id() { - return $this->parent; - } + public function get_parent_id() { + return $this->parent; + } - public function get_weight() { - return $this->weight; - } + public function get_weight() { + return $this->weight; + } public function is_locked() { - return isset($this->locked) && $this->locked == 1 ? true : false ; - } + return isset($this->locked) && $this->locked == 1 ? true : false ; + } - public function is_visible() { - return $this->visible; - } + public function is_visible() { + return $this->visible; + } - public function set_id ($id) { - $this->id = $id; - } + public function set_id ($id) { + $this->id = $id; + } - public function set_name ($name) { - $this->name = $name; - } + public function set_name ($name) { + $this->name = $name; + } - public function set_description ($description) { - $this->description = $description; - } + public function set_description ($description) { + $this->description = $description; + } - public function set_user_id ($user_id) { - $this->user_id = $user_id; - } + public function set_user_id ($user_id) { + $this->user_id = $user_id; + } - public function set_course_code ($course_code) { - $this->course_code = $course_code; - } + public function set_course_code ($course_code) { + $this->course_code = $course_code; + } - public function set_certificate_min_score ($min_score=null) { - $this->certificate_min_score = $min_score; - } + public function set_certificate_min_score ($min_score=null) { + $this->certificate_min_score = $min_score; + } - public function set_parent_id ($parent) { - $this->parent = intval($parent); - } - /** + public function set_parent_id ($parent) { + $this->parent = intval($parent); + } + /** * Filters to int and sets the session ID * @param int The session ID from the Dokeos course session - */ + */ public function set_session_id ($session_id = 0) { $this->session_id = (int)$session_id; } - public function set_weight ($weight) { - $this->weight = $weight; - } + public function set_weight ($weight) { + $this->weight = $weight; + } - public function set_visible ($visible) { - $this->visible = $visible; - } + public function set_visible ($visible) { + $this->visible = $visible; + } public function set_grade_model_id ($id) { - $this->grade_model_id = $id; - } + $this->grade_model_id = $id; + } public function set_locked ($locked) { - $this->locked = $locked; - } + $this->locked = $locked; + } public function get_grade_model_id () { - return $this->grade_model_id; - } + return $this->grade_model_id; + } - public function get_type() { - return 'category'; - } + public function get_type() { + return 'category'; + } public function get_skills($from_db = true) { if ($from_db) { @@ -163,55 +163,55 @@ class Category implements GradebookItem // CRUD FUNCTIONS - /** - * Retrieve categories and return them as an array of Category objects - * @param int category id - * @param int user id (category owner) - * @param string course code - * @param int parent category - * @param bool visible + /** + * Retrieve categories and return them as an array of Category objects + * @param int category id + * @param int user id (category owner) + * @param string course code + * @param int parent category + * @param bool visible * @param int session id (in case we are in a session) * @param bool Whether to show all "session" categories (true) or hide them (false) in case there is no session id - */ + */ - public static function load($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session_id = null, $order_by = null) { + public static function load($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session_id = null, $order_by = null) { //if the category given is explicitly 0 (not null), then create // a root category object (in memory) - if ( isset($id) && (int)$id === 0 ) { - $cats = array(); - $cats[] = Category::create_root_category(); - return $cats; - } + if ( isset($id) && (int)$id === 0 ) { + $cats = array(); + $cats[] = Category::create_root_category(); + return $cats; + } - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'SELECT * FROM '.$tbl_grade_categories; - $paramcount = 0; - if (isset($id)) { - $id = Database::escape_string($id); - $sql.= ' WHERE id = '.intval($id); - $paramcount ++; - } - if (isset($user_id)) { - $user_id = intval($user_id); - if ($paramcount != 0) { + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'SELECT * FROM '.$tbl_grade_categories; + $paramcount = 0; + if (isset($id)) { + $id = Database::escape_string($id); + $sql.= ' WHERE id = '.intval($id); + $paramcount ++; + } + if (isset($user_id)) { + $user_id = intval($user_id); + if ($paramcount != 0) { $sql .= ' AND'; - } else { + } else { $sql .= ' WHERE'; - } - $sql .= ' user_id = '.intval($user_id); - $paramcount ++; - } + } + $sql .= ' user_id = '.intval($user_id); + $paramcount ++; + } - if (isset($course_code)) { - $course_code = Database::escape_string($course_code); - if ($paramcount != 0) { + if (isset($course_code)) { + $course_code = Database::escape_string($course_code); + if ($paramcount != 0) { $sql .= ' AND'; } else { $sql .= ' WHERE'; } - if ($course_code == '0') { + if ($course_code == '0') { $sql .= ' course_code is null '; } else { $sql .= " course_code = '".Database::escape_string($course_code)."'"; @@ -230,99 +230,99 @@ class Category implements GradebookItem $sql .= ' AND session_id = '.(int) $session_id.' '; } //} - $paramcount ++; - } + $paramcount ++; + } - if (isset($parent_id)) { - $parent_id = Database::escape_string($parent_id); - if ($paramcount != 0) { + if (isset($parent_id)) { + $parent_id = Database::escape_string($parent_id); + if ($paramcount != 0) { $sql .= ' AND '; - } else { + } else { $sql .= ' WHERE '; - } - $sql .= ' parent_id = '.intval($parent_id); - $paramcount ++; - } - if (isset($visible)) { - $visible = Database::escape_string($visible); - if ($paramcount != 0) { - $sql .= ' AND'; - } else { - $sql .= ' WHERE'; - } - $sql .= ' visible = '.intval($visible); - $paramcount ++; - } + } + $sql .= ' parent_id = '.intval($parent_id); + $paramcount ++; + } + if (isset($visible)) { + $visible = Database::escape_string($visible); + if ($paramcount != 0) { + $sql .= ' AND'; + } else { + $sql .= ' WHERE'; + } + $sql .= ' visible = '.intval($visible); + $paramcount ++; + } if (!empty($order_by)) { if (!empty($order_by) && $order_by != '') { $sql .= ' '.$order_by; } } - $result = Database::query($sql); + $result = Database::query($sql); $allcat = array(); - if (Database::num_rows($result) > 0) { - $allcat = Category::create_category_objects_from_sql_result($result); - } - return $allcat; - } - - private function create_root_category() { - $cat= new Category(); - $cat->set_id(0); - $cat->set_name(get_lang('RootCat')); - $cat->set_description(null); - $cat->set_user_id(0); - $cat->set_course_code(null); - $cat->set_parent_id(null); - $cat->set_weight(0); - $cat->set_visible(1); - return $cat; - } - - private static function create_category_objects_from_sql_result($result) { - $allcat=array(); - while ($data=Database::fetch_array($result)) { - $cat= new Category(); - $cat->set_id($data['id']); - $cat->set_name($data['name']); - $cat->set_description($data['description']); - $cat->set_user_id($data['user_id']); - $cat->set_course_code($data['course_code']); - $cat->set_parent_id($data['parent_id']); - $cat->set_weight($data['weight']); - $cat->set_visible($data['visible']); + if (Database::num_rows($result) > 0) { + $allcat = Category::create_category_objects_from_sql_result($result); + } + return $allcat; + } + + private function create_root_category() { + $cat= new Category(); + $cat->set_id(0); + $cat->set_name(get_lang('RootCat')); + $cat->set_description(null); + $cat->set_user_id(0); + $cat->set_course_code(null); + $cat->set_parent_id(null); + $cat->set_weight(0); + $cat->set_visible(1); + return $cat; + } + + private static function create_category_objects_from_sql_result($result) { + $allcat=array(); + while ($data=Database::fetch_array($result)) { + $cat= new Category(); + $cat->set_id($data['id']); + $cat->set_name($data['name']); + $cat->set_description($data['description']); + $cat->set_user_id($data['user_id']); + $cat->set_course_code($data['course_code']); + $cat->set_parent_id($data['parent_id']); + $cat->set_weight($data['weight']); + $cat->set_visible($data['visible']); $cat->set_session_id($data['session_id']); - $cat->set_certificate_min_score($data['certif_min_score']); + $cat->set_certificate_min_score($data['certif_min_score']); $cat->set_grade_model_id($data['grade_model_id']); $cat->set_locked($data['locked']); - $allcat[]=$cat; - } - return $allcat; - } + $allcat[]=$cat; + } + return $allcat; + } /** * Insert this category into the database */ - public function add() { - if ( isset($this->name) && '-1'==$this->name) { - return false; - } + public function add() { + if ( isset($this->name) && '-1'==$this->name) { + return false; + } - if (isset($this->name) && isset($this->user_id)) { - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'INSERT INTO '.$tbl_grade_categories.' (name,user_id,weight,visible'; - if (isset($this->description)) { - $sql .= ',description'; - } - if (isset($this->course_code)) { - $sql .= ',course_code'; - } - if (isset($this->parent)) { - $sql .= ',parent_id'; - } + if (isset($this->name) && isset($this->user_id)) { + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'INSERT INTO '.$tbl_grade_categories.' (name,user_id,weight,visible'; + if (isset($this->description)) { + $sql .= ',description'; + } + if (isset($this->course_code)) { + $sql .= ',course_code'; + } + if (isset($this->parent)) { + $sql .= ',parent_id'; + } if (!empty($this->session_id)) { - $sql .= ', session_id'; + $sql .= ', session_id'; } if (isset($this->grade_model_id)) { @@ -344,19 +344,19 @@ class Category implements GradebookItem $visible = intval($this->is_visible()); - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" - .','.intval($this->get_user_id()) - .','.Database::escape_string($this->get_weight()) - .','.$visible; - if (isset($this->description)) { - $sql .= ",'".Database::escape_string($this->get_description())."'"; - } - if (isset($this->course_code)) { - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; - } - if (isset($this->parent)) { - $sql .= ','.intval($this->get_parent_id()); - } + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" + .','.intval($this->get_user_id()) + .','.Database::escape_string($this->get_weight()) + .','.$visible; + if (isset($this->description)) { + $sql .= ",'".Database::escape_string($this->get_description())."'"; + } + if (isset($this->course_code)) { + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; + } + if (isset($this->parent)) { + $sql .= ','.intval($this->get_parent_id()); + } if (!empty($this->session_id)) { $sql .= ', '.intval($this->get_session_id()); } @@ -366,10 +366,10 @@ class Category implements GradebookItem if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) { $sql .= ', '.Database::escape_string($this->get_certificate_min_score()); } - $sql .= ')'; - Database::query($sql); - $id = Database::insert_id(); - $this->set_id($id); + $sql .= ')'; + Database::query($sql); + $id = Database::insert_id(); + $this->set_id($id); if (!empty($id)) { @@ -406,50 +406,50 @@ class Category implements GradebookItem $gradebook= new Gradebook(); $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false)); - return $id; - } - } + return $id; + } + } - /** - * Update the properties of this category in the database + /** + * Update the properties of this category in the database * @todo fix me - */ - public function save() { - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + */ + public function save() { + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'UPDATE '.$tbl_grade_categories." SET name = '".Database::escape_string($this->get_name())."'".', description = '; - if (isset($this->description)) { - $sql .= "'".Database::escape_string($this->get_description())."'"; - } else { - $sql .= 'null'; - } - $sql .= ', user_id = '.intval($this->get_user_id()) - .', course_code = '; - if (isset($this->course_code)) { - $sql .= "'".Database::escape_string($this->get_course_code())."'"; - } else { - $sql .= 'null'; - } - $sql .= ', parent_id = '; - if (isset($this->parent)) { - $sql .= intval($this->get_parent_id()); - } else { - $sql .= 'null'; - } - $sql .= ', certif_min_score = '; - if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) { - $sql .= Database::escape_string($this->get_certificate_min_score()); - } else { - $sql .= 'null'; - } + $sql = 'UPDATE '.$tbl_grade_categories." SET name = '".Database::escape_string($this->get_name())."'".', description = '; + if (isset($this->description)) { + $sql .= "'".Database::escape_string($this->get_description())."'"; + } else { + $sql .= 'null'; + } + $sql .= ', user_id = '.intval($this->get_user_id()) + .', course_code = '; + if (isset($this->course_code)) { + $sql .= "'".Database::escape_string($this->get_course_code())."'"; + } else { + $sql .= 'null'; + } + $sql .= ', parent_id = '; + if (isset($this->parent)) { + $sql .= intval($this->get_parent_id()); + } else { + $sql .= 'null'; + } + $sql .= ', certif_min_score = '; + if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) { + $sql .= Database::escape_string($this->get_certificate_min_score()); + } else { + $sql .= 'null'; + } if (isset($this->grade_model_id)) { $sql .= ', grade_model_id = '.intval($this->get_grade_model_id()); } - $sql .= ', weight = '.Database::escape_string($this->get_weight()) - .', visible = '.intval($this->is_visible()) - .' WHERE id = '.intval($this->id); + $sql .= ', weight = '.Database::escape_string($this->get_weight()) + .', visible = '.intval($this->is_visible()) + .' WHERE id = '.intval($this->id); - Database::query($sql); + Database::query($sql); if (!empty($this->id)) { $parent_id = $this->get_parent_id(); @@ -492,7 +492,7 @@ class Category implements GradebookItem $gradebook= new Gradebook(); $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false)); - } + } /** * Update link weights see #5168 @@ -516,117 +516,118 @@ class Category implements GradebookItem } - /** - * Delete this evaluation from the database - */ - public function delete() { - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'DELETE FROM '.$tbl_grade_categories.' WHERE id = '.intval($this->id); - Database::query($sql); - } - /** - * Not delete this category from the database,when visible=3 is category eliminated - */ - public function update_category_delete($course_id){ - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'UPDATE '.$tbl_grade_categories.' SET visible=3 WHERE course_code ="'.Database::escape_string($course_id).'"'; - Database::query($sql); - } - /** - * Show message resource delete - */ - public function show_message_resource_delete($course_id) { - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'SELECT count(*) AS num from '.$tbl_grade_categories.' WHERE course_code ="'.Database::escape_string($course_id).'" AND visible=3'; - $res=Database::query($sql); - $option=Database::fetch_array($res,'ASSOC'); - if ($option['num']>=1) { - return '  ( '.get_lang('ResourceDeleted').' )'; - } else { - return false; - } - } + /** + * Delete this evaluation from the database + */ + public function delete() { + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'DELETE FROM '.$tbl_grade_categories.' WHERE id = '.intval($this->id); + Database::query($sql); + } + /** + * Not delete this category from the database,when visible=3 is category eliminated + */ + public function update_category_delete($course_id){ + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'UPDATE '.$tbl_grade_categories.' SET visible=3 WHERE course_code ="'.Database::escape_string($course_id).'"'; + Database::query($sql); + } + /** + * Show message resource delete + */ + public function show_message_resource_delete($course_id) { + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'SELECT count(*) AS num from '.$tbl_grade_categories.' WHERE course_code ="'.Database::escape_string($course_id).'" AND visible=3'; + $res=Database::query($sql); + $option=Database::fetch_array($res,'ASSOC'); + if ($option['num']>=1) { + return '  ( '.get_lang('ResourceDeleted').' )'; + } else { + return false; + } + } - /** - * Shows all information of an category - */ - public function shows_all_information_an_category ($selectcat='') { - if($selectcat=='') { - return null; - } else { - $tbl_category=Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql='SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id FROM '.$tbl_category.' c WHERE c.id='.intval($selectcat); - $result=Database::query($sql); - $row=Database::fetch_array($result,'ASSOC'); - return $row; - } - } + /** + * Shows all information of an category + */ + public function shows_all_information_an_category ($selectcat='') { + if($selectcat=='') { + return null; + } else { + $tbl_category=Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql='SELECT name,description,user_id,course_code,parent_id,weight,visible,certif_min_score,session_id FROM '.$tbl_category.' c WHERE c.id='.intval($selectcat); + $result=Database::query($sql); + $row=Database::fetch_array($result,'ASSOC'); + return $row; + } + } // OTHER FUNCTIONS - /** - * Check if a category name (with the same parent category) already exists - * @param $name name to check (if not given, the name property of this object will be checked) - * @param $parent parent category - */ - public function does_name_exist($name, $parent) { - if (!isset ($name)) { - $name = $this->name; - $parent = $this->parent; - } - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'SELECT count(id) AS number' - .' FROM '.$tbl_grade_categories - ." WHERE name = '".Database::escape_string($name)."'"; - - if (api_is_allowed_to_edit()) { - $parent = Category::load($parent); - $code = $parent[0]->get_course_code(); - if (isset($code) && $code != '0') { - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $sql .= ' AND user_id IN (' - .' SELECT user_id FROM '.$main_course_user_table - ." WHERE course_code = '".Database::escape_string($code)."'" - .' AND status = '.COURSEMANAGER - .')'; - } else { - $sql .= ' AND user_id = '.api_get_user_id(); - } + /** + * Check if a category name (with the same parent category) already exists + * @param $name name to check (if not given, the name property of this object will be checked) + * @param $parent parent category + */ + public function does_name_exist($name, $parent) { + if (!isset ($name)) { + $name = $this->name; + $parent = $this->parent; + } + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = 'SELECT count(id) AS number' + .' FROM '.$tbl_grade_categories + ." WHERE name = '".Database::escape_string($name)."'"; + + if (api_is_allowed_to_edit()) { + $parent = Category::load($parent); + $code = $parent[0]->get_course_code(); + if (isset($code) && $code != '0') { + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $sql .= ' AND user_id IN (' + .' SELECT user_id FROM '.$main_course_user_table + ." WHERE course_code = '".Database::escape_string($code)."'" + .' AND status = '.COURSEMANAGER + .')'; + } else { + $sql .= ' AND user_id = '.api_get_user_id(); + } - } else { - $sql .= ' AND user_id = '.api_get_user_id(); - } - if (!isset ($parent)) { - $sql.= ' AND parent_id is null'; - } else { - $sql.= ' AND parent_id = '.intval($parent); - } + } else { + $sql .= ' AND user_id = '.api_get_user_id(); + } + if (!isset ($parent)) { + $sql.= ' AND parent_id is null'; + } else { + $sql.= ' AND parent_id = '.intval($parent); + } - $result = Database::query($sql); - $number = Database::fetch_row($result); - return ($number[0] != 0); - } + $result = Database::query($sql); + $number = Database::fetch_row($result); + return ($number[0] != 0); + } - /** - * Checks if the certificate is available for the given user in this category - * @param integer User ID - * @return boolean True if conditions match, false if fails - */ - public function is_certificate_available($user_id) { - $score = $this->calc_score($user_id, $this->course_code); + /** + * Checks if the certificate is available for the given user in this category + * @param integer User ID + * @return boolean True if conditions match, false if fails + */ + public function is_certificate_available($user_id) { + $score = $this->calc_score($user_id, $this->course_code); if (isset($score)) { $certification_score = ($score[0]/$score[1])*100; //get a percentage score to compare to minimum certificate score - if ($certification_score >= $this->certificate_min_score) { - return true; - } + if ($certification_score >= $this->certificate_min_score) { + return true; + } } - return false; - } + return false; + } - /** - * Is this category a course ? - * A category is a course if it has a course code and no parent category. - */ + /** + * Is this category a course ? + * A category is a course if it has a course code and no parent category. + */ public function is_course() { +<<<<<<< HEAD return (isset($this->course_code) && !empty($this->course_code) && (!isset($this->parent) || $this->parent == 0)); } @@ -653,18 +654,53 @@ class Category implements GradebookItem $rescount = 0; $ressum = 0; $weightsum = 0; +======= + return (isset($this->course_code) && !empty($this->course_code) + && (!isset($this->parent) || $this->parent == 0)); + } - if (!empty($cats)) { - foreach ($cats as $cat) { - $catres = $cat->calc_score($stud_id, $course_code, $session_id); // recursive call - if ($cat->get_weight() != 0) { - $catweight = $cat->get_weight(); - $rescount++; - $weightsum += $catweight; - } + /** + * Calculate the score of this category + * @param $stud_id student id (default: all students - then the average is returned) + * @return array (score sum, weight sum) + * or null if no scores available + */ + public function calc_score ($stud_id = null, $course_code = '', $session_id = null) { + // get appropriate subcategories, evaluations and links + if (!empty($course_code)) { + $cats = $this->get_subcategories($stud_id, $course_code, $session_id); + $evals = $this->get_evaluations($stud_id, false, $course_code); + $links = $this->get_links($stud_id, false, $course_code); + } else { + $cats = $this->get_subcategories($stud_id); + $evals = $this->get_evaluations($stud_id); + $links = $this->get_links($stud_id); + } + + // calculate score + $rescount = 0; + $ressum = 0; + $weightsum = 0; + /*$debug = false; + + if ($stud_id == 11) { + $debug = true; + } + if ($debug) var_dump($links);*/ +>>>>>>> julio19x + + if (!empty($cats)) { + foreach ($cats as $cat) { + $catres = $cat->calc_score($stud_id, $course_code, $session_id); // recursive call + if ($cat->get_weight() != 0) { + $catweight = $cat->get_weight(); + $rescount++; + $weightsum += $catweight; + } if (isset($catres)) { $ressum += (($catres[0]/$catres[1]) * $catweight); } +<<<<<<< HEAD } } @@ -685,74 +721,97 @@ class Category implements GradebookItem if (!empty($links)) { foreach ($links as $link) { $linkres = $link->calc_score($stud_id); +======= + } + } - if (isset($linkres) && $link->get_weight() != 0) { - $linkweight = $link->get_weight(); - $link_res_denom = ($linkres[1]==0) ? 1 : $linkres[1]; - $rescount++; - $weightsum += $linkweight; - $ressum += (($linkres[0]/$link_res_denom) * $linkweight); - } else { + if (!empty($evals)) { + foreach ($evals as $eval) { + $evalres = $eval->calc_score($stud_id); + if (isset($evalres) && $eval->get_weight() != 0) { + $evalweight = $eval->get_weight(); + $rescount++; + $weightsum += $evalweight; + $ressum += (($evalres[0]/$evalres[1]) * $evalweight); + } else { + + } + } + } + + if (!empty($links)) { + foreach ($links as $link) { + $linkres = $link->calc_score($stud_id); + //if ($debug) var_dump($linkres); +>>>>>>> julio19x + + if (isset($linkres) && $link->get_weight() != 0) { + $linkweight = $link->get_weight(); + $link_res_denom = ($linkres[1]==0) ? 1 : $linkres[1]; + $rescount++; + $weightsum += $linkweight; + $ressum += (($linkres[0]/$link_res_denom) * $linkweight); + } else { //adding if result does not exists if ($link->get_weight() != 0) { $linkweight = $link->get_weight(); $weightsum += $linkweight; } } - } - } + } + } - if ($rescount == 0) { - return null; - } else { - return array ($ressum, $weightsum); - } - } + if ($rescount == 0) { + return null; + } else { + return array ($ressum, $weightsum); + } + } - /** - * Delete this category and every subcategory, evaluation and result inside - */ - public function delete_all () { - $cats = Category::load(null, null, $this->course_code, $this->id, null); - $evals = Evaluation::load(null, null, $this->course_code, $this->id, null); - $links = LinkFactory::load(null,null,null,null,$this->course_code,$this->id,null); - if (!empty($cats)) { - foreach ($cats as $cat) { - $cat->delete_all(); - $cat->delete(); - } - } - if (!empty($evals)) { - foreach ($evals as $eval) { - $eval->delete_with_results(); - } - } - if (!empty($links)) { - foreach ($links as $link) { - $link->delete(); - } - } - $this->delete(); - } + /** + * Delete this category and every subcategory, evaluation and result inside + */ + public function delete_all () { + $cats = Category::load(null, null, $this->course_code, $this->id, null); + $evals = Evaluation::load(null, null, $this->course_code, $this->id, null); + $links = LinkFactory::load(null,null,null,null,$this->course_code,$this->id,null); + if (!empty($cats)) { + foreach ($cats as $cat) { + $cat->delete_all(); + $cat->delete(); + } + } + if (!empty($evals)) { + foreach ($evals as $eval) { + $eval->delete_with_results(); + } + } + if (!empty($links)) { + foreach ($links as $link) { + $link->delete(); + } + } + $this->delete(); + } - /** - * Return array of Category objects where a student is subscribed to. - * @param int student id + /** + * Return array of Category objects where a student is subscribed to. + * @param int student id * @param string Course code * @param int Session id - */ - public function get_root_categories_for_student ($stud_id, $course_code = null, $session_id = null) { - // courses + */ + public function get_root_categories_for_student ($stud_id, $course_code = null, $session_id = null) { + // courses - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'SELECT *' - .' FROM '.$tbl_grade_categories - .' WHERE parent_id = 0'; - if (!api_is_allowed_to_edit()) { - $sql .= ' AND visible = 1'; + $sql = 'SELECT *' + .' FROM '.$tbl_grade_categories + .' WHERE parent_id = 0'; + if (!api_is_allowed_to_edit()) { + $sql .= ' AND visible = 1'; //proceed with checks on optional parameters course & session if (!empty($course_code)) { // TODO: considering it highly improbable that a user would get here @@ -785,371 +844,371 @@ class Category implements GradebookItem if (!empty($session_id)) { $sql .= " AND session_id = ".(int)$session_id; } else { - $sql .="AND session_id IS NULL OR session_id=0"; + $sql .="AND session_id IS NULL OR session_id=0"; } } else { - $sql .= ' AND course_code in' - .' (SELECT course_code' - .' FROM '.$main_course_user_table - .' WHERE user_id = '.api_get_user_id() - .' AND status = '.COURSEMANAGER - .')'; + $sql .= ' AND course_code in' + .' (SELECT course_code' + .' FROM '.$main_course_user_table + .' WHERE user_id = '.api_get_user_id() + .' AND status = '.COURSEMANAGER + .')'; } }elseif (api_is_platform_admin()) { - if (isset($session_id) && $session_id!=0) { - $sql.=' AND session_id='.intval($session_id); - } else { - $sql.=' AND coalesce(session_id,0)=0'; - } + if (isset($session_id) && $session_id!=0) { + $sql.=' AND session_id='.intval($session_id); + } else { + $sql.=' AND coalesce(session_id,0)=0'; + } } - $result = Database::query($sql); - $cats = Category::create_category_objects_from_sql_result($result); + $result = Database::query($sql); + $cats = Category::create_category_objects_from_sql_result($result); - // course independent categories + // course independent categories if (empty($course_code)) { - $cats = Category::get_independent_categories_with_result_for_student (0, $stud_id, $cats); + $cats = Category::get_independent_categories_with_result_for_student (0, $stud_id, $cats); } - return $cats; + return $cats; - } + } - /** - * Return array of Category objects where a teacher is admin for. - * @param int user id (to return everything, use 'null' here) + /** + * Return array of Category objects where a teacher is admin for. + * @param int user id (to return everything, use 'null' here) * @param string course code (optional) * @param int session id (optional) - */ - public function get_root_categories_for_teacher ($user_id, $course_code = null, $session_id = null) { - if ($user_id == null) { - return Category::load(null,null,$course_code,0,null,$session_id); + */ + public function get_root_categories_for_teacher ($user_id, $course_code = null, $session_id = null) { + if ($user_id == null) { + return Category::load(null,null,$course_code,0,null,$session_id); } - // courses + // courses - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = 'SELECT *' - .' FROM '.$tbl_grade_categories - .' WHERE parent_id = 0'; + $sql = 'SELECT *' + .' FROM '.$tbl_grade_categories + .' WHERE parent_id = 0'; if (!empty($course_code)) { $sql .= " AND course_code = '".Database::escape_string($course_code)."' "; if (!empty($session_id)) { - $sql .= " AND session_id = ".(int)$session_id; + $sql .= " AND session_id = ".(int)$session_id; } } else { - $sql .= ' AND course_code in' - .' (SELECT course_code' - .' FROM '.$main_course_user_table - .' WHERE user_id = '.intval($user_id) - .')'; - } - $result = Database::query($sql); - $cats = Category::create_category_objects_from_sql_result($result); - // course independent categories - if (isset($course_code)) { - $indcats = Category::load(null,$user_id,$course_code,0,null,$session_id); - $cats = array_merge($cats, $indcats); - } - return $cats; - } + $sql .= ' AND course_code in' + .' (SELECT course_code' + .' FROM '.$main_course_user_table + .' WHERE user_id = '.intval($user_id) + .')'; + } + $result = Database::query($sql); + $cats = Category::create_category_objects_from_sql_result($result); + // course independent categories + if (isset($course_code)) { + $indcats = Category::load(null,$user_id,$course_code,0,null,$session_id); + $cats = array_merge($cats, $indcats); + } + return $cats; + } - /** - * Can this category be moved to somewhere else ? - * The root and courses cannot be moved. - */ - public function is_movable () { - return (!(!isset ($this->id) || $this->id == 0 || $this->is_course())); - } + /** + * Can this category be moved to somewhere else ? + * The root and courses cannot be moved. + */ + public function is_movable () { + return (!(!isset ($this->id) || $this->id == 0 || $this->is_course())); + } - /** - * Generate an array of possible categories where this category can be moved to. - * Notice: its own parent will be included in the list: it's up to the frontend - * to disable this element. - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) - */ - public function get_target_categories() { - // the root or a course -> not movable - if (!$this->is_movable()) { - return null; - } - // otherwise: - // - course independent category - // -> movable to root or other independent categories - // - category inside a course - // -> movable to root, independent categories or categories inside the course - else { - $user = (api_is_platform_admin() ? null : api_get_user_id()); - $targets = array(); - $level = 0; - - $root = array(0, get_lang('RootCat'), $level); - $targets[] = $root; - - if (isset($this->course_code) && !empty($this->course_code)) { - $crscats = Category::load(null,null,$this->course_code,0); - foreach ($crscats as $cat) { - if ($this->can_be_moved_to_cat($cat)) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); - } - } - } + /** + * Generate an array of possible categories where this category can be moved to. + * Notice: its own parent will be included in the list: it's up to the frontend + * to disable this element. + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) + */ + public function get_target_categories() { + // the root or a course -> not movable + if (!$this->is_movable()) { + return null; + } + // otherwise: + // - course independent category + // -> movable to root or other independent categories + // - category inside a course + // -> movable to root, independent categories or categories inside the course + else { + $user = (api_is_platform_admin() ? null : api_get_user_id()); + $targets = array(); + $level = 0; + + $root = array(0, get_lang('RootCat'), $level); + $targets[] = $root; + + if (isset($this->course_code) && !empty($this->course_code)) { + $crscats = Category::load(null,null,$this->course_code,0); + foreach ($crscats as $cat) { + if ($this->can_be_moved_to_cat($cat)) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); + } + } + } - $indcats = Category::load(null,$user,0,0); - foreach ($indcats as $cat) { - if ($this->can_be_moved_to_cat($cat)) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); - } - } + $indcats = Category::load(null,$user,0,0); + foreach ($indcats as $cat) { + if ($this->can_be_moved_to_cat($cat)) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); + } + } - return $targets; - } - } + return $targets; + } + } - /** - * Internal function used by get_target_categories() - */ - private function add_target_subcategories($targets, $level, $catid) { - $subcats = Category::load(null,null,null,$catid); - foreach ($subcats as $cat) { - if ($this->can_be_moved_to_cat($cat)) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); - } - } - return $targets; - } + /** + * Internal function used by get_target_categories() + */ + private function add_target_subcategories($targets, $level, $catid) { + $subcats = Category::load(null,null,null,$catid); + foreach ($subcats as $cat) { + if ($this->can_be_moved_to_cat($cat)) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); + } + } + return $targets; + } - /** - * Internal function used by get_target_categories() and add_target_subcategories() - * Can this category be moved to the given category ? - * Impossible when origin and target are the same... children won't be processed - * either. (a category can't be moved to one of its own children) - */ - private function can_be_moved_to_cat ($cat) { - return ($cat->get_id() != $this->get_id()); - } + /** + * Internal function used by get_target_categories() and add_target_subcategories() + * Can this category be moved to the given category ? + * Impossible when origin and target are the same... children won't be processed + * either. (a category can't be moved to one of its own children) + */ + private function can_be_moved_to_cat ($cat) { + return ($cat->get_id() != $this->get_id()); + } - /** - * Move this category to the given category. - * If this category moves from inside a course to outside, - * its course code must be changed, as well as the course code - * of all underlying categories and evaluations. All links will - * be deleted as well ! - */ - public function move_to_cat ($cat) { - $this->set_parent_id($cat->get_id()); - if ($this->get_course_code() != $cat->get_course_code()) { - $this->set_course_code($cat->get_course_code()); - $this->apply_course_code_to_children(); - } - $this->save(); - } + /** + * Move this category to the given category. + * If this category moves from inside a course to outside, + * its course code must be changed, as well as the course code + * of all underlying categories and evaluations. All links will + * be deleted as well ! + */ + public function move_to_cat ($cat) { + $this->set_parent_id($cat->get_id()); + if ($this->get_course_code() != $cat->get_course_code()) { + $this->set_course_code($cat->get_course_code()); + $this->apply_course_code_to_children(); + } + $this->save(); + } - /** - * Internal function used by move_to_cat() - */ - private function apply_course_code_to_children () { - $cats = Category::load(null, null, null, $this->id, null); - $evals = Evaluation::load(null, null, null, $this->id, null); - $links = LinkFactory::load(null,null,null,null,null,$this->id,null); - - foreach ($cats as $cat) { - $cat->set_course_code($this->get_course_code()); - $cat->save(); - $cat->apply_course_code_to_children(); - } + /** + * Internal function used by move_to_cat() + */ + private function apply_course_code_to_children () { + $cats = Category::load(null, null, null, $this->id, null); + $evals = Evaluation::load(null, null, null, $this->id, null); + $links = LinkFactory::load(null,null,null,null,null,$this->id,null); + + foreach ($cats as $cat) { + $cat->set_course_code($this->get_course_code()); + $cat->save(); + $cat->apply_course_code_to_children(); + } - foreach ($evals as $eval) { - $eval->set_course_code($this->get_course_code()); - $eval->save(); - } + foreach ($evals as $eval) { + $eval->set_course_code($this->get_course_code()); + $eval->save(); + } - foreach ($links as $link) { - $link->delete(); - } + foreach ($links as $link) { + $link->delete(); + } - } + } - /** - * Generate an array of all categories the user can navigate to - */ - public function get_tree () { - $targets = array(); - $level = 0; + /** + * Generate an array of all categories the user can navigate to + */ + public function get_tree () { + $targets = array(); + $level = 0; - $root = array(0, get_lang('RootCat'), $level); - $targets[] = $root; + $root = array(0, get_lang('RootCat'), $level); + $targets[] = $root; - // course or platform admin - if (api_is_allowed_to_edit()) { - $user = (api_is_platform_admin() ? null : api_get_user_id()); + // course or platform admin + if (api_is_allowed_to_edit()) { + $user = (api_is_platform_admin() ? null : api_get_user_id()); - $cats = Category::get_root_categories_for_teacher($user); - foreach ($cats as $cat) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),null); - } - } - else { // student - $cats = Category::get_root_categories_for_student(api_get_user_id()); - foreach ($cats as $cat) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(), 1); - } - } + $cats = Category::get_root_categories_for_teacher($user); + foreach ($cats as $cat) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),null); + } + } + else { // student + $cats = Category::get_root_categories_for_student(api_get_user_id()); + foreach ($cats as $cat) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = Category::add_subtree($targets, $level+1, $cat->get_id(), 1); + } + } - return $targets; - } + return $targets; + } - /** - * Internal function used by get_tree() - */ - private function add_subtree ($targets, $level, $catid, $visible) { - $subcats = Category::load(null,null,null,$catid,$visible); + /** + * Internal function used by get_tree() + */ + private function add_subtree ($targets, $level, $catid, $visible) { + $subcats = Category::load(null,null,null,$catid,$visible); - if (!empty($subcats)) { - foreach ($subcats as $cat) { - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); - $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),$visible); - } - } - return $targets; - } + if (!empty($subcats)) { + foreach ($subcats as $cat) { + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); + $targets = Category::add_subtree($targets, $level+1, $cat->get_id(),$visible); + } + } + return $targets; + } - /** - * Generate an array of courses that a teacher hasn't created a category for. - * @return array 2-dimensional array - every element contains 2 subelements (code, title) - */ - public function get_not_created_course_categories ($user_id) { - $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); - $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - - $sql = 'SELECT DISTINCT(code), title FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu' - .' WHERE cc.code = cu.course_code' - .' AND cu.status = '.COURSEMANAGER; - if (!api_is_platform_admin()) { - $sql .= ' AND cu.user_id = '.$user_id; - } - $sql .= ' AND cc.code NOT IN' - .' (SELECT course_code FROM '.$tbl_grade_categories - .' WHERE parent_id = 0' -// .' AND user_id = '.$user_id - .' AND course_code IS NOT null)'; - $result = Database::query($sql); - - $cats=array(); - while ($data=Database::fetch_array($result)) { - $cats[] = array ($data['code'], $data['title']); - } - return $cats; + /** + * Generate an array of courses that a teacher hasn't created a category for. + * @return array 2-dimensional array - every element contains 2 subelements (code, title) + */ + public function get_not_created_course_categories ($user_id) { + $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); + $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + + $sql = 'SELECT DISTINCT(code), title FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu' + .' WHERE cc.code = cu.course_code' + .' AND cu.status = '.COURSEMANAGER; + if (!api_is_platform_admin()) { + $sql .= ' AND cu.user_id = '.$user_id; + } + $sql .= ' AND cc.code NOT IN' + .' (SELECT course_code FROM '.$tbl_grade_categories + .' WHERE parent_id = 0' +// .' AND user_id = '.$user_id + .' AND course_code IS NOT null)'; + $result = Database::query($sql); + + $cats=array(); + while ($data=Database::fetch_array($result)) { + $cats[] = array ($data['code'], $data['title']); + } + return $cats; - } + } - /** - * Generate an array of all courses that a teacher is admin of. - * @return array 2-dimensional array - every element contains 2 subelements (code, title) - */ - public function get_all_courses ($user_id) { - $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); - $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - - $sql = 'SELECT DISTINCT(code), title FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu' - .' WHERE cc.code = cu.course_code' - .' AND cu.status = '.COURSEMANAGER; - if (!api_is_platform_admin()) { - $sql .= ' AND cu.user_id = '.intval($user_id); - } + /** + * Generate an array of all courses that a teacher is admin of. + * @return array 2-dimensional array - every element contains 2 subelements (code, title) + */ + public function get_all_courses ($user_id) { + $tbl_main_courses = Database :: get_main_table(TABLE_MAIN_COURSE); + $tbl_main_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + + $sql = 'SELECT DISTINCT(code), title FROM '.$tbl_main_courses.' cc, '.$tbl_main_course_user.' cu' + .' WHERE cc.code = cu.course_code' + .' AND cu.status = '.COURSEMANAGER; + if (!api_is_platform_admin()) { + $sql .= ' AND cu.user_id = '.intval($user_id); + } - $result = Database::query($sql); + $result = Database::query($sql); - $cats=array(); - while ($data=Database::fetch_array($result)) { - $cats[] = array ($data['code'], $data['title']); - } - return $cats; + $cats=array(); + while ($data=Database::fetch_array($result)) { + $cats[] = array ($data['code'], $data['title']); + } + return $cats; - } + } - /** - * Apply the same visibility to every subcategory, evaluation and link - */ - public function apply_visibility_to_children () { - $cats = Category::load(null, null, null, $this->id, null); - $evals = Evaluation::load(null, null, null, $this->id, null); - $links = LinkFactory::load(null,null,null,null,null,$this->id,null); - if (!empty($cats)) { - foreach ($cats as $cat) { - $cat->set_visible($this->is_visible()); - $cat->save(); - $cat->apply_visibility_to_children(); - } - } - if (!empty($evals)) { - foreach ($evals as $eval) { - $eval->set_visible($this->is_visible()); - $eval->save(); - } - } - if (!empty($links)) { - foreach ($links as $link) { - $link->set_visible($this->is_visible()); - $link->save(); - } - } - } + /** + * Apply the same visibility to every subcategory, evaluation and link + */ + public function apply_visibility_to_children () { + $cats = Category::load(null, null, null, $this->id, null); + $evals = Evaluation::load(null, null, null, $this->id, null); + $links = LinkFactory::load(null,null,null,null,null,$this->id,null); + if (!empty($cats)) { + foreach ($cats as $cat) { + $cat->set_visible($this->is_visible()); + $cat->save(); + $cat->apply_visibility_to_children(); + } + } + if (!empty($evals)) { + foreach ($evals as $eval) { + $eval->set_visible($this->is_visible()); + $eval->save(); + } + } + if (!empty($links)) { + foreach ($links as $link) { + $link->set_visible($this->is_visible()); + $link->save(); + } + } + } - /** - * Check if a category contains evaluations with a result for a given student - */ - public function has_evaluations_with_results_for_student ($stud_id) { - $evals = Evaluation::get_evaluations_with_result_for_student($this->id, $stud_id); - if (count($evals) != 0) { - return true; - } else { - $cats = Category::load(null, null, null, $this->id, - api_is_allowed_to_edit() ? null : 1); - foreach ($cats as $cat) { - if ($cat->has_evaluations_with_results_for_student ($stud_id)) { - return true; - } + /** + * Check if a category contains evaluations with a result for a given student + */ + public function has_evaluations_with_results_for_student ($stud_id) { + $evals = Evaluation::get_evaluations_with_result_for_student($this->id, $stud_id); + if (count($evals) != 0) { + return true; + } else { + $cats = Category::load(null, null, null, $this->id, + api_is_allowed_to_edit() ? null : 1); + foreach ($cats as $cat) { + if ($cat->has_evaluations_with_results_for_student ($stud_id)) { + return true; + } - } - return false; - } - } + } + return false; + } + } - /** - * Retrieve all categories inside a course independent category - * that should be visible to a student. - * @param $cat_id parent category - * @param $stud_id student id - * @param $cats optional: if defined, the categories will be added to this array - */ + /** + * Retrieve all categories inside a course independent category + * that should be visible to a student. + * @param $cat_id parent category + * @param $stud_id student id + * @param $cats optional: if defined, the categories will be added to this array + */ public function get_independent_categories_with_result_for_student ($cat_id, $stud_id, $cats = array()) { - $creator = (api_is_allowed_to_edit() && !api_is_platform_admin()) ? api_get_user_id() : null; + $creator = (api_is_allowed_to_edit() && !api_is_platform_admin()) ? api_get_user_id() : null; - $crsindcats = Category::load(null,$creator,'0',$cat_id, - api_is_allowed_to_edit() ? null : 1); + $crsindcats = Category::load(null,$creator,'0',$cat_id, + api_is_allowed_to_edit() ? null : 1); - if (!empty($crsindcats)) { - foreach ($crsindcats as $crsindcat) { - if ($crsindcat->has_evaluations_with_results_for_student($stud_id)) { - $cats[] = $crsindcat; - } - } - } - return $cats; + if (!empty($crsindcats)) { + foreach ($crsindcats as $crsindcat) { + if ($crsindcat->has_evaluations_with_results_for_student($stud_id)) { + $cats[] = $crsindcat; + } + } + } + return $cats; } /** @@ -1161,181 +1220,181 @@ class Category implements GradebookItem } - /** - * Get appropriate subcategories visible for the user (and optionally the course and session) - * @param int $stud_id student id (default: all students) + /** + * Get appropriate subcategories visible for the user (and optionally the course and session) + * @param int $stud_id student id (default: all students) * @param string Course code (optional) * @param int Session ID (optional) * @return array Array of subcategories - */ - public function get_subcategories ($stud_id = null, $course_code = null, $session_id = null, $order = null) { - // 1 student - if (isset($stud_id)) { - // special case: this is the root - if ($this->id == 0) { - return Category::get_root_categories_for_student ($stud_id, $course_code, $session_id); - } else { - return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order); - } - } else {// all students - // course admin - if (api_is_allowed_to_edit() && !api_is_platform_admin()) { - // root - if ($this->id == 0) { - return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false); - // inside a course + */ + public function get_subcategories ($stud_id = null, $course_code = null, $session_id = null, $order = null) { + // 1 student + if (isset($stud_id)) { + // special case: this is the root + if ($this->id == 0) { + return Category::get_root_categories_for_student ($stud_id, $course_code, $session_id); + } else { + return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order); + } + } else {// all students + // course admin + if (api_is_allowed_to_edit() && !api_is_platform_admin()) { + // root + if ($this->id == 0) { + return $this->get_root_categories_for_teacher(api_get_user_id(), $course_code, $session_id, false); + // inside a course } elseif (!empty($this->course_code)) { - return Category::load(null, null, $this->course_code, $this->id, null, $session_id, $order); + return Category::load(null, null, $this->course_code, $this->id, null, $session_id, $order); } elseif (!empty($course_code)) { return Category::load(null, null, $course_code, $this->id, null, $session_id, $order); - // course independent + // course independent } else { - return Category::load(null, api_get_user_id(), 0, $this->id, null); + return Category::load(null, api_get_user_id(), 0, $this->id, null); } - } elseif (api_is_platform_admin()) { + } elseif (api_is_platform_admin()) { // platform admin //we explicitly avoid listing subcats from another session - return Category::load(null, null, $course_code, $this->id, null, $session_id, $order); + return Category::load(null, null, $course_code, $this->id, null, $session_id, $order); } - } - return array(); - } + } + return array(); + } - /** - * Get appropriate evaluations visible for the user - * @param int $stud_id student id (default: all students) - * @param boolean $recursive process subcategories (default: no recursion) - */ - public function get_evaluations ($stud_id = null, $recursive = false, $course_code = '') { - $evals = array(); + /** + * Get appropriate evaluations visible for the user + * @param int $stud_id student id (default: all students) + * @param boolean $recursive process subcategories (default: no recursion) + */ + public function get_evaluations ($stud_id = null, $recursive = false, $course_code = '') { + $evals = array(); - if (empty($course_code)) { - $course_code = api_get_course_id(); - } + if (empty($course_code)) { + $course_code = api_get_course_id(); + } - // 1 student - if (isset($stud_id) && !empty($stud_id)) { - // special case: this is the root - if ($this->id == 0) { - $evals = Evaluation::get_evaluations_with_result_for_student(0,$stud_id); - } else { + // 1 student + if (isset($stud_id) && !empty($stud_id)) { + // special case: this is the root + if ($this->id == 0) { + $evals = Evaluation::get_evaluations_with_result_for_student(0,$stud_id); + } else { $evals = Evaluation::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1); - } - } else {// all students - // course admin - if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && !api_is_platform_admin()) { - // root - if ($this->id == 0) { - $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); - } elseif (isset($this->course_code) && !empty($this->course_code)) { + } + } else {// all students + // course admin + if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && !api_is_platform_admin()) { + // root + if ($this->id == 0) { + $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); + } elseif (isset($this->course_code) && !empty($this->course_code)) { // inside a course - $evals = Evaluation::load(null, null, $course_code, $this->id, null); - } else { + $evals = Evaluation::load(null, null, $course_code, $this->id, null); + } else { // course independent - $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); - } - } elseif (api_is_platform_admin()) { + $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); + } + } elseif (api_is_platform_admin()) { //platform admin - $evals = Evaluation::load(null, null, $course_code, $this->id, null); - } - } + $evals = Evaluation::load(null, null, $course_code, $this->id, null); + } + } - if ($recursive) { - $subcats = $this->get_subcategories($stud_id, $course_code); - if (!empty($subcats)) { - foreach ($subcats as $subcat) { - $subevals = $subcat->get_evaluations($stud_id, true, $course_code); - //$this->debugprint($subevals); - $evals = array_merge($evals, $subevals); - } - } - } - return $evals; + if ($recursive) { + $subcats = $this->get_subcategories($stud_id, $course_code); + if (!empty($subcats)) { + foreach ($subcats as $subcat) { + $subevals = $subcat->get_evaluations($stud_id, true, $course_code); + //$this->debugprint($subevals); + $evals = array_merge($evals, $subevals); + } + } + } + return $evals; - } + } - /** - * Get appropriate links visible for the user - * @param int $stud_id student id (default: all students) - * @param boolean $recursive process subcategories (default: no recursion) - */ - public function get_links ($stud_id = null, $recursive = false, $course_code = '') { - $links = array(); + /** + * Get appropriate links visible for the user + * @param int $stud_id student id (default: all students) + * @param boolean $recursive process subcategories (default: no recursion) + */ + public function get_links ($stud_id = null, $recursive = false, $course_code = '') { + $links = array(); - if (empty($course_code)) { - $course_code = api_get_course_id(); - } + if (empty($course_code)) { + $course_code = api_get_course_id(); + } - // no links in root or course independent categories - if ($this->id == 0) { + // no links in root or course independent categories + if ($this->id == 0) { - } elseif (isset($stud_id)) { + } elseif (isset($stud_id)) { // 1 student $stud_id - $links = LinkFactory::load(null,null,null,null,empty($this->course_code)?null:$course_code, $this->id, - api_is_allowed_to_edit() ? null : 1); - } elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) { + $links = LinkFactory::load(null,null,null,null,empty($this->course_code)?null:$course_code, $this->id, + api_is_allowed_to_edit() ? null : 1); + } elseif (api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) { // all students -> only for course/platform admin - $links = LinkFactory::load(null,null,null,null,empty($this->course_code)?null:$this->course_code,$this->id, null); - } + $links = LinkFactory::load(null,null,null,null,empty($this->course_code)?null:$this->course_code,$this->id, null); + } - if ($recursive) { - $subcats = $this->get_subcategories($stud_id, $course_code); - if (!empty($subcats)) { - foreach ($subcats as $subcat) { - $sublinks = $subcat->get_links($stud_id, false, $course_code); - $links = array_merge($links, $sublinks); - } - } - } - return $links; + if ($recursive) { + $subcats = $this->get_subcategories($stud_id, $course_code); + if (!empty($subcats)) { + foreach ($subcats as $subcat) { + $sublinks = $subcat->get_links($stud_id, false, $course_code); + $links = array_merge($links, $sublinks); + } + } + } + return $links; - } + } // Other methods implementing GradebookItem - public function get_item_type() { - return 'C'; - } + public function get_item_type() { + return 'C'; + } public function set_skills($skills) { $this->skills = $skills; } - public function get_date() { - return null; - } + public function get_date() { + return null; + } - public function get_icon_name() { - return 'cat'; - } - /** + public function get_icon_name() { + return 'cat'; + } + /** * Find category by name * @param string $name_mask search string * @return array category objects matching the search criterium */ public function find_category ($name_mask,$allcat) { - $foundcats = array(); - foreach ($allcat as $search_cat) { - if (!(strpos(strtolower($search_cat->get_name()), strtolower($name_mask)) === false)) { - $foundcats[] = $search_cat; - } - } - return $foundcats; + $foundcats = array(); + foreach ($allcat as $search_cat) { + if (!(strpos(strtolower($search_cat->get_name()), strtolower($name_mask)) === false)) { + $foundcats[] = $search_cat; + } + } + return $foundcats; } /** - * This function, locks a category , only one who can unlock it is the platform administrator. - * @param int locked 1 or unlocked 0 - * @return bool - * - * */ - function lock($locked) { - $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; - Database::query($sql); - } + * This function, locks a category , only one who can unlock it is the platform administrator. + * @param int locked 1 or unlocked 0 + * @return bool + * + * */ + function lock($locked) { + $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; + Database::query($sql); + } function lock_all_items($locked) { if (api_get_setting('gradebook_locking_enabled') == 'true') { @@ -1396,10 +1455,10 @@ class Category implements GradebookItem for ($count=0; $count < count($evals_links); $count++) { $item = $evals_links[$count]; $score = $item->calc_score($user_id); - $divide = ( ($score[1])==0 ) ? 1 : $score[1]; + $divide = ( ($score[1])==0 ) ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; - $item_value = $score[0]/$divide*$item->get_weight()*$sub_cat_percentage/$main_weight; - $item_total_value += $item_value; + $item_value = $score[0]/$divide*$item->get_weight()*$sub_cat_percentage/$main_weight; + $item_total_value += $item_value; } $item_total_value = (float)$item_total_value; diff --git a/main/gradebook/lib/fe/evalform.class.php b/main/gradebook/lib/fe/evalform.class.php index 704beaddc9..1fcd552880 100644 --- a/main/gradebook/lib/fe/evalform.class.php +++ b/main/gradebook/lib/fe/evalform.class.php @@ -466,6 +466,7 @@ class EvalForm extends FormValidator } } } +<<<<<<< HEAD $this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. '.$all_categories[0]->get_weight().'] '), true, array ( 'size' => '4', @@ -473,13 +474,28 @@ class EvalForm extends FormValidator 'class' => 'span1' )); +======= + + $this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. '.$all_categories[0]->get_weight().'] '), true, array ( + 'size' => '4', + 'maxlength' => '5', + 'class' => 'span1' + )); + +>>>>>>> julio19x /*$this->add_textfield('weight', array(null, null, '/ '.$default_weight.''), true, array ( - 'size' => '4', - 'maxlength' => '5', + 'size' => '4', + 'maxlength' => '5', 'class' => 'span1' +<<<<<<< HEAD ));*/ +======= + ));*/ + + +>>>>>>> julio19x if ($edit) { if (!$this->evaluation_object->has_results()) { $this->add_textfield('max', get_lang('QualificationNumeric'), true, array ( diff --git a/main/gradebook/lib/fe/flatviewtable.class.php b/main/gradebook/lib/fe/flatviewtable.class.php index 5fe102abe0..9c20a5416f 100644 --- a/main/gradebook/lib/fe/flatviewtable.class.php +++ b/main/gradebook/lib/fe/flatviewtable.class.php @@ -30,15 +30,15 @@ class FlatViewTable extends SortableTable */ function FlatViewTable ($selectcat, $users= array (), $evals= array (), $links= array (), $limit_enabled = false, $offset = 0, $addparams = null) { parent :: __construct ('flatviewlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 1 : 0); - $this->datagen = new FlatViewDataGenerator($users, $evals, $links); - - $this->selectcat = $selectcat; + $this->selectcat = $selectcat; + $this->datagen = new FlatViewDataGenerator($users, $evals, $links, array('only_subcat'=>$this->selectcat->get_id())); + $this->limit_enabled = $limit_enabled; $this->offset = $offset; if (isset ($addparams)) { $this->set_additional_parameters($addparams); } - + // step 2: generate rows: students $this->datagen->category = $this->selectcat; } @@ -47,23 +47,26 @@ class FlatViewTable extends SortableTable * Display the graph of the total results of all students * */ function display_graph() { + include_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; + include_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; + include_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; $header_name = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); - + $img_file = ''; - + if ($this->datagen->get_total_items_count()>0 && $total_users > 0 ) { //Removing user names and total array_shift($header_name); array_shift($header_name); array_pop($header_name); - + $user_results = $this->datagen->get_data_to_graph(); - + $pre_result = $new_result = array(); $DataSet = new pData(); - + //$pre_result total score of students //filling the Dataset foreach($user_results as $result) { @@ -73,15 +76,15 @@ class FlatViewTable extends SortableTable } $i = 1; $show_draw = false; - if ($total_users >0 ) { + if ($total_users >0 ) { foreach($pre_result as $res) { - $total = $res / ($total_users); + $total = $res / ($total_users); if ($total != 0) { $show_draw = true; } $DataSet->AddPoint($total, "Serie".$i); $DataSet->SetSerieName(strip_tags($header_name[$i-1]),"Serie".$i); - + // Dataset definition $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(); @@ -90,12 +93,12 @@ class FlatViewTable extends SortableTable } // Cache definition - $Cache = new pCache(api_get_path(SYS_ARCHIVE_PATH)); + $Cache = new pCache(); // the graph id $gradebook_id = intval($_GET['selectcat']); $graph_id = api_get_user_id().'AverageResultsVsResource'.$gradebook_id.api_get_course_id(); $data = $DataSet->GetData(); - + if ($show_draw) { if ($Cache->IsInCache($graph_id, $DataSet->GetData())) { //if (0) { @@ -127,7 +130,7 @@ class FlatViewTable extends SortableTable //background color area & stripe or not $Test->drawGraphArea(255,255,255,TRUE); $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0 ,150,150,150,TRUE,0,1, FALSE); - + //background grid $Test->drawGrid(4,TRUE,230,230,230,50); @@ -160,6 +163,9 @@ class FlatViewTable extends SortableTable } function display_graph_by_resource() { + require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; + require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; + require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; $header_name = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); @@ -170,13 +176,13 @@ class FlatViewTable extends SortableTable array_shift($header_name); //Removing last name array_shift($header_name); - + $displayscore = ScoreDisplay :: instance(); - $customdisplays = $displayscore->get_custom_score_display_settings(); - + $customdisplays = $displayscore->get_custom_score_display_settings(); + if (is_array($customdisplays) && count(($customdisplays))) { - - $user_results = $this->datagen->get_data_to_graph2(); + + $user_results = $this->datagen->get_data_to_graph2(); $pre_result = $new_result = array(); $DataSet = new pData(); //filling the Dataset @@ -186,7 +192,7 @@ class FlatViewTable extends SortableTable $pre_result[$i+3][]= $result[$i+1]; } } - + $i=0; $show_draw = false; $resource_list = array(); @@ -196,11 +202,11 @@ class FlatViewTable extends SortableTable rsort($res_array); $pre_result2[] = $res_array; } - + //@todo when a display custom does not exist the order of the color does not match //filling all the answer that are not responded with 0 rsort($customdisplays); - + if ($total_users > 0) { foreach($pre_result2 as $key=>$res_array) { $key_list = array(); @@ -208,22 +214,22 @@ class FlatViewTable extends SortableTable $resource_list[$key][$user_result[1]] += 1; $key_list[] = $user_result[1]; } - + foreach ($customdisplays as $display) { if (!in_array($display['display'], $key_list)) $resource_list[$key][$display['display']] = 0; } $i++; } - } - - //fixing $resource_list - $max = 0; + } + + //fixing $resource_list + $max = 0; $new_list = array(); foreach($resource_list as $key=>$value) { $new_value = array(); - - foreach($customdisplays as $item) { + + foreach($customdisplays as $item) { if ($value[$item['display']] > $max) { $max = $value[$item['display']]; } @@ -231,8 +237,8 @@ class FlatViewTable extends SortableTable } $new_list[] = $new_value; } - $resource_list = $new_list; - + $resource_list = $new_list; + $i = 1; $j = 0; @@ -252,7 +258,7 @@ class FlatViewTable extends SortableTable $DataSet->SetYAxisName(get_lang('Students')); $show_draw = true; // Cache definition - $Cache = new pCache(api_get_path(SYS_ARCHIVE_PATH)); + $Cache = new pCache(); // the graph id $gradebook_id = intval($_GET['selectcat']); $graph_id = api_get_user_id().'ByResource'.$gradebook_id.api_get_course_id().api_get_session_id(); @@ -284,12 +290,12 @@ class FlatViewTable extends SortableTable //background color area & stripe or not $Test->drawGraphArea(255,255,255,TRUE); - + //Setting max height by default see #3296 if (!empty($max)) { - $Test->setFixedScale(0, $max); + $Test->setFixedScale(0, $max); } - + $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150,150,150, TRUE, 0, 0, FALSE); //background grid @@ -427,7 +433,7 @@ class FlatViewTable extends SortableTable .'?selectcat='.Security::remove_XSS($_GET['selectcat']) .'&offset='.(($this->offset)-LIMIT) .(isset($_GET['search'])?'&search='.Security::remove_XSS($_GET['search']):'').'">' - .Display::return_icon('action_prev.png', get_lang('PreviousPage'), array(), 32) + .Display::return_icon('action_prev.png', get_lang('PreviousPage'), array(), 32) .''; } else { $header .= Display::return_icon('action_prev_na.png', get_lang('PreviousPage'), array(), 32); @@ -436,7 +442,7 @@ class FlatViewTable extends SortableTable // next X $calcnext = (($this->offset+(2*LIMIT)) > $totalitems) ? ($totalitems-(LIMIT+$this->offset)) : LIMIT; - + if ($calcnext > 0) { $header .= '' : ''; - $invisibility_span_close = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '' : ''; - - if (api_is_allowed_to_edit(null, true)) { + $row = array(); + $item = $item_category = $data[0]; + + $id = $item->get_id(); + + //if the item is invisible, wrap it in a span with class invisible + $invisibility_span_open = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '' : ''; + + if (api_is_allowed_to_edit(null, true)) { //id - $row[] = $this->build_id_column($item); - } + $row[] = $this->build_id_column($item); + } //Type - $row[] = $this->build_type_column($item); - - //Name - if (get_class($item) == 'Category') { - $row[] = $invisibility_span_open.'

    '.$item->get_name().'

    '.$invisibility_span_close; + $row[] = $this->build_type_column($item); + + //Name + if (get_class($item) == 'Category') { + $row[] = $invisibility_span_open.'

    '.$item->get_name().'

    '.$invisibility_span_close; $main_categories[$item->get_id()]['name'] = $item->get_name(); - } else { - $row[] = $invisibility_span_open.$this->build_name_link($item) . $invisibility_span_close; + } else { + $row[] = $invisibility_span_open.$this->build_name_link($item) . $invisibility_span_close; $main_categories[$item->get_id()]['name'] = $this->build_name_link($item); - } + } $main_categories[$item->get_id()]['weight']= $item->get_weight(); $total_categories_weight += $item->get_weight(); - //Description - $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; - - //Weight - //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close; + //Description + $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; + + //Weight + //$row[] = $invisibility_span_open .Display::tag('h4', $data['3'] .' / '.$this->currentcat->get_weight()).$invisibility_span_close; //$average = $data['3']/$this->currentcat->get_weight()*100; $average = $scoredisplay->display_score(array($data['3'], $this->currentcat->get_weight()), SCORE_SIMPLE, SCORE_BOTH, true); if (api_is_allowed_to_edit(null, true)) { - $row[] = $invisibility_span_open .Display::tag('h4', $average).$invisibility_span_close; + $row[] = $invisibility_span_open .Display::tag('h4', $average).$invisibility_span_close; } else { - $row[] = $invisibility_span_open .$average.$invisibility_span_close; + $row[] = $invisibility_span_open .$average.$invisibility_span_close; } $category_weight = $item->get_weight(); - - if (api_is_allowed_to_edit(null, true)) { - $weight_total_links += $data[3]; - } else { - $cattotal = Category :: load($_GET['selectcat']); + + if (api_is_allowed_to_edit(null, true)) { + $weight_total_links += $data[3]; + } else { + $cattotal = Category :: load($_GET['selectcat']); $scoretotal = $cattotal[0]->calc_score(api_get_user_id()); $item_value = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); - } - - //Date - //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; + } + + //Date + //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; - //Edit (for admins) - if (api_is_allowed_to_edit(null, true)) { - $cat = new Category(); - $show_message = $cat->show_message_resource_delete($item->get_course_code()); - if ($show_message === false) { - $row[] = $this->build_edit_column($item); - } - } else { - //students get the results and certificates columns - if (count($this->evals_links) > 0 && $status_user != 1) { - $value_data = isset($data[4]) ? $data[4] : null; - if (!is_null($value_data)) { - $row[] = Display::tag('h4', $value_data); - } else { + //Edit (for admins) + if (api_is_allowed_to_edit(null, true)) { + $cat = new Category(); + $show_message = $cat->show_message_resource_delete($item->get_course_code()); + if ($show_message === false) { + $row[] = $this->build_edit_column($item); + } + } else { + //students get the results and certificates columns + if (count($this->evals_links) > 0 && $status_user != 1) { + $value_data = isset($data[4]) ? $data[4] : null; + if (!is_null($value_data)) { + $row[] = Display::tag('h4', $value_data); + } else { $row[] = $this->build_edit_column($item); } - } else { + } else { $score = $item->calc_score(api_get_user_id()); if (!empty($score[1])) { $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); @@ -252,58 +252,58 @@ class GradebookTable extends SortableTable { $row[] = $this->build_edit_column($item); } } - } + } //Category added - $sortable_data[] = $row; - - // Loading childrens - - if (get_class($item) == 'Category') { - - $stud_id = api_get_user_id(); - $course_code = api_get_course_id(); - $session_id = api_get_session_id(); - $parent_id = $item->get_id(); + $sortable_data[] = $row; + + // Loading childrens + + if (get_class($item) == 'Category') { - $cats = Category :: load ($parent_id, null, null, null, null, null); - - $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id); - $alleval = $cats[0]->get_evaluations($stud_id); - $alllink = $cats[0]->get_links($stud_id); - - $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); - $data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page); + $stud_id = api_get_user_id(); + $course_code = api_get_course_id(); + $session_id = api_get_session_id(); + $parent_id = $item->get_id(); - $total_weight = 0; + $cats = Category :: load ($parent_id, null, null, null, null, null); + + $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id); + $alleval = $cats[0]->get_evaluations($stud_id); + $alllink = $cats[0]->get_links($stud_id); + + $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); + $data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page); + + $total_weight = 0; //Links - foreach ($data_array as $data) { - $row = array(); - $item = $data[0]; - $id = $item->get_id(); - - //if the item is invisible, wrap it in a span with class invisible - $invisibility_span_open = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '' : ''; + foreach ($data_array as $data) { + $row = array(); + $item = $data[0]; + $id = $item->get_id(); + + //if the item is invisible, wrap it in a span with class invisible + $invisibility_span_open = (api_is_allowed_to_edit() && $item->is_visible() == '0') ? '' : ''; $main_categories[$parent_id]['children'][$item->get_id()]['name'] = $item->get_name(); $main_categories[$parent_id]['children'][$item->get_id()]['weight'] = $item->get_weight(); - if (api_is_allowed_to_edit(null, true)) { - $row[] = $this->build_id_column($item); - } + if (api_is_allowed_to_edit(null, true)) { + $row[] = $this->build_id_column($item); + } + + $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); - $row[] = $this->build_type_column($item, array('style' => 'padding-left:5px')); - - //Name - $row[] = $invisibility_span_open."    ".$this->build_name_link($item) . $invisibility_span_close; - - //Description - $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; - - //Weight + //Name + $row[] = $invisibility_span_open."    ".$this->build_name_link($item) . $invisibility_span_close; + + //Description + $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; + + //Weight //$weight = $data[3]/$category_weight*$main_cat[0]->get_weight(); /*$weight = $category_weight * $data[3] / $main_cat[0]->get_weight(); $weight = $main_cat[0]->get_weight()*$weight/$category_weight;*/ @@ -315,157 +315,157 @@ class GradebookTable extends SortableTable { $total_weight += $weight; $row[] = $invisibility_span_open.$weight.$extra.$invisibility_span_close; - - if (api_is_allowed_to_edit(null, true)) { - //$weight_total_links += intval($data[3]); - } else { - $cattotal = Category :: load($_GET['selectcat']); - $scoretotal = $cattotal[0]->calc_score(api_get_user_id()); - $item_value = $scoretotal[0]; - } - - //Date - //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; - - //Admins get an edit column - if (api_is_allowed_to_edit(null, true)) { - $cat = new Category(); - $show_message = $cat->show_message_resource_delete($item->get_course_code()); - if ($show_message === false) { - $row[] = $this->build_edit_column($item); - } - } else { - //students get the results and certificates columns - $eval_n_links = array_merge($alleval, $alllink); - - if (count($eval_n_links)> 0 && $status_user!=1 ) { - $value_data = isset($data[4]) ? $data[4] : null; - if (!is_null($value_data)) { - $score = $item->calc_score(api_get_user_id()); - $new_score = $data[3]* $score[0] / $score[1]; + + if (api_is_allowed_to_edit(null, true)) { + //$weight_total_links += intval($data[3]); + } else { + $cattotal = Category :: load($_GET['selectcat']); + $scoretotal = $cattotal[0]->calc_score(api_get_user_id()); + $item_value = $scoretotal[0]; + } + + //Date + //$row[] = $invisibility_span_open.$data[4].$invisibility_span_close; + + //Admins get an edit column + if (api_is_allowed_to_edit(null, true)) { + $cat = new Category(); + $show_message = $cat->show_message_resource_delete($item->get_course_code()); + if ($show_message === false) { + $row[] = $this->build_edit_column($item); + } + } else { + //students get the results and certificates columns + $eval_n_links = array_merge($alleval, $alllink); + + if (count($eval_n_links)> 0 && $status_user!=1 ) { + $value_data = isset($data[4]) ? $data[4] : null; + if (!is_null($value_data)) { + $score = $item->calc_score(api_get_user_id()); + $new_score = $data[3]* $score[0] / $score[1]; $row[] = Display::tip($new_score, $data[4]); - } - } + } + } if (!empty($cats)) { $row[] = null; } - } + } $row['child_of'] = $parent_id; - - $sortable_data[] = $row; - } - + + $sortable_data[] = $row; + } + //"Warning row" if (!empty($data_array)) { if (api_is_allowed_to_edit()) { - $main_weight = intval($main_cat[0]->get_weight()); - if (intval($total_weight) == $main_weight) { + // Compare the category weight to the sum of all weights inside the category + if (intval($total_weight) == $category_weight) { $label = null; - $total = score_badges(array($total_weight.' / '.$main_weight, '100')); - } else { - $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $main_weight) ); - $total = Display::badge($total_weight.' / '.$main_weight, 'warning'); + $total = score_badges(array($total_weight.' / '.$category_weight, '100')); + } else { + $label = Display::return_icon('warning.png', sprintf(get_lang('TotalWeightMustBeX'), $category_weight) ); + $total = Display::badge($total_weight.' / '.$category_weight, 'warning'); } $row = array(null, null, "     
    ".get_lang('SubTotal').'
    ',null, $total.' '.$label, 'child_of' =>$parent_id); $sortable_data[] = $row; } - } - } - } //end looping categories - - if (api_is_allowed_to_edit()) { + } + } + } //end looping categories + + if (api_is_allowed_to_edit()) { if (count($main_cat) > 1) { - $main_weight = intval($main_cat[0]->get_weight()); - if (intval($total_categories_weight) == $main_weight) { + $main_weight = intval($main_cat[0]->get_weight()); + if (intval($total_categories_weight) == $main_weight) { $total = score_badges(array($total_categories_weight.' / '.$main_weight, '100')); - } else { - $total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning'); + } else { + $total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning'); } $row = array(null, null, '

    '.get_lang('Total').'

    ', null, $total); $sortable_data[] = $row; } } - // warning messages - $view = isset($_GET['view']) ? $_GET['view']: null; - if (api_is_allowed_to_edit()) { - - if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view <> 'presence') { - $id_cat = intval($_GET['selectcat']); - $category = Category :: load($id_cat); - //$weight_category = intval($this->build_weight($category[0])); - $weight_category = intval($this->build_weight($category[0])); - $course_code = $this->build_course_code($category[0]); + // warning messages + $view = isset($_GET['view']) ? $_GET['view']: null; + if (api_is_allowed_to_edit()) { + + if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view <> 'presence') { + $id_cat = intval($_GET['selectcat']); + $category = Category :: load($id_cat); + //$weight_category = intval($this->build_weight($category[0])); + $weight_category = intval($this->build_weight($category[0])); + $course_code = $this->build_course_code($category[0]); $weight_total_links = round($weight_total_links); - if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) { - $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); - $modify_icons = '
    '.Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL).''; - $warning_message .= $modify_icons; - Display::display_warning_message($warning_message,false); - } + if ($weight_total_links > $weight_category || $weight_total_links < $weight_category || $weight_total_links > $weight_category) { + $warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category); + $modify_icons = ''.Display::return_icon('edit.png', $warning_message, array(), ICON_SIZE_SMALL).''; + $warning_message .= $modify_icons; + Display::display_warning_message($warning_message,false); + } - $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code); - if (!empty($content_html)) { - $new_content = explode('',$content_html['content']); + $content_html = DocumentManager::replace_user_info_into_html(api_get_user_id(), $course_code); + if (!empty($content_html)) { + $new_content = explode('',$content_html['content']); } - if (empty($new_content[0])) { - $warning_message = get_lang('ThereIsNotACertificateAvailableByDefault'); - $cert_icon = ''.Display::return_icon('certificate.png', get_lang('AttachCertificate'), array(), ICON_SIZE_SMALL).''; + if (empty($new_content[0])) { + $warning_message = get_lang('ThereIsNotACertificateAvailableByDefault'); + $cert_icon = ''.Display::return_icon('certificate.png', get_lang('AttachCertificate'), array(), ICON_SIZE_SMALL).''; - Display::display_warning_message($warning_message.$cert_icon,false); - } - } - - if (empty($_GET['selectcat'])) { - $categories = Category :: load(); - $weight_categories = $certificate_min_scores = $course_codes = array(); - foreach ($categories as $category) { - $course_code_category = $this->build_course_code($category); - if (!empty($course_code)) { - if ($course_code_category == $course_code) { - $weight_categories[] = intval($this->build_weight($category)); - $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); - $course_codes[] = $course_code; - break; - } - } else { - $weight_categories[] = intval($this->build_weight($category)); - $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); - $course_codes[] = $course_code_category; - } - } + Display::display_warning_message($warning_message.$cert_icon,false); + } + } - if (is_array($weight_categories) && is_array($certificate_min_scores) && is_array($course_codes)) { - $warning_message = ''; - for ($x = 0; $xbuild_course_code($category); + if (!empty($course_code)) { + if ($course_code_category == $course_code) { + $weight_categories[] = intval($this->build_weight($category)); + $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); + $course_codes[] = $course_code; + break; + } + } else { + $weight_categories[] = intval($this->build_weight($category)); + $certificate_min_scores[] = intval($this->build_certificate_min_score($category)); + $course_codes[] = $course_code_category; + } + } - if (empty($certificate_min_score) || ($certificate_min_score > $weight_category)) { - $warning_message .= $course_code .' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').' '.$weight_category.'
    '; - } - } + if (is_array($weight_categories) && is_array($certificate_min_scores) && is_array($course_codes)) { + $warning_message = ''; + for ($x = 0; $x $weight_category)) { + $warning_message .= $course_code .' - '.get_lang('CertificateMinimunScoreIsRequiredAndMustNotBeMoreThan').' '.$weight_category.'
    '; + } + } + + if (!empty($warning_message)) { + Display::display_warning_message($warning_message,false); + } + } + } + } + return $sortable_data; + } // Other functions private function build_certificate_min_score ($item) { - return $item->get_certificate_min_score(); + return $item->get_certificate_min_score(); } private function build_weight ($item) { - return $item->get_weight(); + return $item->get_weight(); } private function build_course_code ($item) { diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index 3a4f0d805d..90b9afb28a 100644 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -21,7 +21,7 @@ class FlatViewDataGenerator private $users; private $evals; private $links; - private $evals_links; + private $evals_links; public $params; public $category = array(); @@ -52,101 +52,105 @@ class FlatViewDataGenerator /** * Get array containing column header names (incl user columns) + * @param int Start item offset + * @param int Number of items to get + * @param bool whether to show the details or not + * @return array List of headers */ public function get_header_names($items_start = 0, $items_count = null , $show_detail = false) { - $headers = array(); - + $headers = array(); + if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { $headers[] = get_lang('OfficialCode'); - } + } if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) { if (api_is_western_name_order()) { - $headers[] = get_lang('FirstnameAndLastname'); + $headers[] = get_lang('FirstnameAndLastname'); } else { - $headers[] = get_lang('LastnameAndFirstname'); + $headers[] = get_lang('LastnameAndFirstname'); } } else { if (api_is_western_name_order()) { $headers[] = get_lang('FirstName'); - $headers[] = get_lang('LastName'); + $headers[] = get_lang('LastName'); } else { $headers[] = get_lang('LastName'); - $headers[] = get_lang('FirstName'); + $headers[] = get_lang('FirstName'); } } if (!isset($items_count)) { $items_count = count($this->evals_links) - $items_start; } - + $parent_id = $this->category->get_parent_id(); - - if ($parent_id == 0) { + + if ($parent_id == 0 or $this->params['only_subcat'] == $this->category->get_id()) { $main_weight = $this->category->get_weight(); $grade_model_id = $this->category->get_grade_model_id(); } else { $main_cat = Category::load($parent_id, null, null); $main_weight = $main_cat[0]->get_weight(); $grade_model_id = $main_cat[0]->get_grade_model_id(); - } - + } + $use_grade_model = true; if (empty($grade_model_id) || $grade_model_id == -1) { - $use_grade_model = false; + $use_grade_model = false; } - + //@todo move these in a function $sum_categories_weight_array = array(); if (isset($this->category) && !empty($this->category)) { - $categories = Category::load(null, null, null, $this->category->get_id()); + $categories = Category::load(null, null, null, $this->category->get_id()); if (!empty($categories)) { - foreach ($categories as $category) { + foreach ($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); } } else { - $sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight(); + $sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight(); } } - + //No category was added - - $course_code = api_get_course_id(); + + $course_code = api_get_course_id(); $session_id = api_get_session_id(); $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); - - if ($parent_id == 0 && !empty($allcat)) { - + + if ($parent_id == 0 && !empty($allcat)) { + //Means there are any subcategory foreach ($allcat as $sub_cat) { - $sub_cat_weight = 100*$sub_cat->get_weight()/$main_weight; + $sub_cat_weight = round(100*$sub_cat->get_weight()/$main_weight,1); $add_weight = " $sub_cat_weight %"; if (isset($this->params['export_pdf']) && $this->params['export_pdf']) { $add_weight = null; } - $headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).$add_weight; + $headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).$add_weight; } } else { if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { - $item = $this->evals_links[$count + $items_start]; - $weight = 100*$item->get_weight()/$main_weight; - $headers[] = $item->get_name().' '.$weight.' % '; + $item = $this->evals_links[$count + $items_start]; + $weight = round(100*$item->get_weight()/$main_weight,1); + $headers[] = $item->get_name().' '.$weight.' % '; } - } + } } $headers[] = api_strtoupper(get_lang('GradebookQualificationTotal')); return $headers; } - - function get_max_result_by_link($id) { + + function get_max_result_by_link($id) { $max = 0; foreach ($this->users as $user) { - $item = $this->evals_links [$id]; - $score = $item->calc_score($user[0]); + $item = $this->evals_links [$id]; + $score = $item->calc_score($user[0]); if ($score[0] > $max) { $max = $score[0]; - } - } + } + } return $max ; } @@ -163,7 +167,7 @@ class FlatViewDataGenerator $headers[] = $item->get_name(); } return $headers; - } + } /** * Get actual array data @@ -176,28 +180,28 @@ class FlatViewDataGenerator public function get_data ($users_sorting = 0, $users_start = 0, $users_count = null, $items_start = 0, $items_count = null, $ignore_score_color = false, $show_all = false) { - + // do some checks on users/items counts, redefine if invalid values if (!isset($users_count)) { $users_count = count ($this->users) - $users_start; } if ($users_count < 0) { $users_count = 0; - } + } if (!isset($items_count)) { $items_count = count ($this->evals) + count ($this->links) - $items_start; } if ($items_count < 0) { $items_count = 0; } - + // copy users to a new array that we will sort // TODO - needed ? $usertable = array (); foreach ($this->users as $user) { $usertable[] = $user; } - + // sort users array if ($users_sorting & self :: FVDG_SORT_LASTNAME) { usort($usertable, array ('FlatViewDataGenerator','sort_by_last_name')); @@ -211,7 +215,7 @@ class FlatViewDataGenerator // select the requested users $selected_users = array_slice($usertable, $users_start, $users_count); - + // generate actual data array $scoredisplay = ScoreDisplay :: instance(); @@ -221,192 +225,194 @@ class FlatViewDataGenerator $displaytype |= SCORE_IGNORE_SPLIT; } //@todo move these in a function - $sum_categories_weight_array = array(); - - if (isset($this->category) && !empty($this->category)) { + $sum_categories_weight_array = array(); + + if (isset($this->category) && !empty($this->category)) { $categories = Category::load(null, null, null, $this->category->get_id()); if (!empty($categories)) { - foreach($categories as $category) { + foreach($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); } } else { $sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight(); } } - + $parent_id = $this->category->get_parent_id(); - - if ($parent_id == 0) { + + if ($parent_id == 0 or $this->params['only_subcat'] == $this->category->get_id()) { $main_weight = $this->category->get_weight(); $grade_model_id = $this->category->get_grade_model_id(); } else { $main_cat = Category::load($parent_id, null, null); $main_weight = $main_cat[0]->get_weight(); $grade_model_id = $main_cat[0]->get_grade_model_id(); - } - + } + $use_grade_model = true; if (empty($grade_model_id) || $grade_model_id == -1) { - $use_grade_model = false; - } - + $use_grade_model = false; + } + $export_to_pdf = false; - if (isset($this->params['export_pdf']) && $this->params['export_pdf']) { + if (isset($this->params['export_pdf']) && $this->params['export_pdf']) { $export_to_pdf = true; } - - foreach ($selected_users as $user) { - $row = array(); + + foreach ($selected_users as $user) { + $row = array(); if ($export_to_pdf) { $row['user_id'] = $user_id = $user[0]; //user id } else { $row[] = $user_id = $user[0]; //user id } - - if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { + + if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { if ($export_to_pdf) { $row['official_code'] = $user[4]; //official code } else { $row[] = $user[4]; //official code } } - - if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) { + + if (isset($this->params['join_firstname_lastname']) && $this->params['join_firstname_lastname']) { if ($export_to_pdf) { - $row['name'] = api_get_person_name($user[3], $user[2]); //last name + $row['name'] = api_get_person_name($user[3], $user[2]); //last name } else { - $row[] = api_get_person_name($user[3], $user[2]); //last name + $row[] = api_get_person_name($user[3], $user[2]); //last name } } else { if ($export_to_pdf) { if (api_is_western_name_order()) { $row['firstname'] = $user[3]; - $row['lastname'] = $user[2]; + $row['lastname'] = $user[2]; } else { $row['lastname'] = $user[2]; $row['firstname'] = $user[3]; } } else { if (api_is_western_name_order()) { - $row[] = $user[3]; //first name - $row[] = $user[2]; //last name + $row[] = $user[3]; //first name + $row[] = $user[2]; //last name } else { $row[] = $user[2]; //last name - $row[] = $user[3]; //first name + $row[] = $user[3]; //first name } } } - + $item_value = 0; $item_value_total = 0; $item_total = 0; - + $convert_using_the_global_weight = true; - - $course_code = api_get_course_id(); + + $course_code = api_get_course_id(); $session_id = api_get_session_id(); $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); if ($parent_id == 0 && !empty($allcat)) { - + foreach ($allcat as $sub_cat) { $score = $sub_cat->calc_score($user_id); $real_score = $score; - $divide = ( ($score[1])==0 ) ? 1 : $score[1]; - + $divide = ( ($score[1])==0 ) ? 1 : $score[1]; + $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; $item_value = $score[0]/$divide*$main_weight; - //Fixing total when using one or multiple gradebooks + //Fixing total when using one or multiple gradebooks $percentage = $sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(); - $item_value = $percentage*$item_value; + $item_value = $percentage*$item_value; $item_total += $sub_cat->get_weight(); - - if ($convert_using_the_global_weight) { - $score[0] = $score[0]/$main_weight*$sub_cat->get_weight(); + +/* + if ($convert_using_the_global_weight) { + $score[0] = $score[0]/$main_weight*$sub_cat->get_weight(); $score[1] = $main_weight ; - } - + } + +*/ if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') { //if (true) { - $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE); - $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); + $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE); + $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = Display::tip($real_score, $temp_score); - } else { - $real_score = $scoredisplay->display_score($real_score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); + } else { + $real_score = $scoredisplay->display_score($real_score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = Display::tip($temp_score, $real_score); - } - + } + if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { if (!$show_all) { - $row[] = $temp_score.' '; - } else { + $row[] = $temp_score.' '; + } else { $row[] = $temp_score; - } + } } - $item_value_total +=$item_value; + $item_value_total +=$item_value; } if ($convert_using_the_global_weight) { //$item_total = $main_weight; } } else { for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { - $item = $this->evals_links[$count + $items_start]; + $item = $this->evals_links[$count + $items_start]; $score = $item->calc_score($user_id); $real_score = $score; $divide = ( ($score[1])==0 ) ? 1 : $score[1]; - + //sub cat weight $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $item_value = $score[0]/$divide; - - //Fixing total when using one or multiple gradebooks - if ($this->category->get_parent_id() == 0 ) { + + //Fixing total when using one or multiple gradebooks + if ($this->category->get_parent_id() == 0 ) { $item_value = $score[0]/$divide*$item->get_weight(); } else { - $item_value = $item_value*$item->get_weight(); + $item_value = $item_value*$item->get_weight(); } - - $item_total += $item->get_weight(); + + $item_total += $item->get_weight(); /* - $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); - $temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM); + $complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE); + $temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = Display::tip($temp_score, $complete_score);*/ - + //if (true) { if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') { - $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE); - $temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM); + $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE); + $temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = Display::tip($real_score, $temp_score); - } else { - $temp_score = $scoredisplay->display_score(array($item_value, null), SCORE_DIV_SIMPLE_WITH_CUSTOM); + } else { + $temp_score = $scoredisplay->display_score($real_score, SCORE_DIV_PERCENT_WITH_CUSTOM); $temp_score = Display::tip($temp_score, $complete_score); } - + if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { - if (!$show_all) { - if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, + if (!$show_all) { + if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) { if (!empty($score[0])) { - $row[] = $temp_score.' '; + $row[] = $temp_score.' '; } else { $row[] = ''; } - } else { + } else { $row[] = $temp_score.' '; - } - } else { - $row[] = $temp_score; - } - } + } + } else { + $row[] = $temp_score; + } + } $item_value_total +=$item_value; } $item_total = $main_weight; - } - $total_score = array($item_value_total, $item_total); - + } + $total_score = array($item_value_total, $item_total); + if (!$show_all) { if ($export_to_pdf) { $row['total'] = $scoredisplay->display_score($total_score); @@ -420,10 +426,10 @@ class FlatViewDataGenerator $row[] = $scoredisplay->display_score($total_score, SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS); } } - unset($score); - + unset($score); + //var_dump($row);exit; $data[] = $row; - } + } return $data; } @@ -443,7 +449,7 @@ class FlatViewDataGenerator $row = array (); for ($count=0;$count < count($this->evals_links); $count++) { $item = $this->evals_links [$count]; - $score = $item->calc_score($user[0]); + $score = $item->calc_score($user[0]); $porcent_score = isset($score[1]) && $score[1] > 0 ? ($score[0]*100)/$score[1] :0; $row[$item->get_name()] = $porcent_score; } @@ -487,7 +493,7 @@ class FlatViewDataGenerator usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name')); $data = array (); - + $selected_users = $usertable; foreach ($selected_users as $user) { $row = array (); @@ -498,19 +504,19 @@ class FlatViewDataGenerator for ($count=0;$count < count($this->evals_links); $count++) { $item = $this->evals_links[$count]; $score = $item->calc_score($user[0]); - + $divide =( ($score[1])==0 ) ? 1 : $score[1]; $item_value += $score[0]/$divide*$item->get_weight(); $item_total += $item->get_weight(); - - + + $score_denom = ($score[1]==0) ? 1 : $score[1]; $score_final = ($score[0] / $score_denom) * 100; $row[] = $score_final; } $total_score = array($item_value, $item_total); $score_final = ($item_value / $item_total) * 100; - + $row[] = $score_final; $data[] = $row; } diff --git a/main/gradebook/lib/results_data_generator.class.php b/main/gradebook/lib/results_data_generator.class.php index 07290eec96..80bb0d7a88 100644 --- a/main/gradebook/lib/results_data_generator.class.php +++ b/main/gradebook/lib/results_data_generator.class.php @@ -73,7 +73,7 @@ class ResultsDataGenerator $table = array(); foreach($this->results as $result) { $user = array(); - $info = api_get_user_info($result->get_user_id()); + $info = get_user_info_from_id($result->get_user_id()); $user['id'] = $result->get_user_id(); if ($pdf){ $user['username'] = $info['username']; @@ -87,12 +87,12 @@ class ResultsDataGenerator $user['score'] = $this->get_score_display($result->get_score(),true, $ignore_score_color); } $user['percentage_score'] = intval($scoredisplay->display_score(array($result->get_score(), $this->evaluation->get_max()), SCORE_PERCENT, SCORE_BOTH, true)); - if ($pdf && $number_decimals == null){ + if ($pdf && $number_decimals == null){ $user['scoreletter'] = $result->get_score(); - } - if ($scoredisplay->is_custom()) { - $user['display'] = $this->get_score_display($result->get_score(), false, $ignore_score_color); - } + } + if ($scoredisplay->is_custom()) { + $user['display'] = $this->get_score_display($result->get_score(), false, $ignore_score_color); + } $table[] = $user; } @@ -102,7 +102,7 @@ class ResultsDataGenerator usort($table, array('ResultsDataGenerator', 'sort_by_last_name')); } elseif ($sorting & self :: RDG_SORT_FIRSTNAME) { usort($table, array('ResultsDataGenerator', 'sort_by_first_name')); - } elseif ($sorting & self :: RDG_SORT_SCORE) { + } elseif ($sorting & self :: RDG_SORT_SCORE) { usort($table, array('ResultsDataGenerator', 'sort_by_score')); } elseif ($sorting & self :: RDG_SORT_MASK) { usort($table, array('ResultsDataGenerator', 'sort_by_mask')); @@ -110,21 +110,28 @@ class ResultsDataGenerator if ($sorting & self :: RDG_SORT_DESC) { $table = array_reverse($table); } - $return = array_slice($table, $start, $count); + $return = array_slice($table, $start, $count); return $return; } - private function get_score_display ($score, $realscore, $ignore_score_color) { + /** + * Re-formats the score to show percentage ("2/4 (50 %)") or letters ("A") + * @param float Current absolute score (max score is taken from $this->evaluation->get_max() + * @param bool Whether we want the real score (2/4 (50 %)) or the transformation (A, B, C, etc) + * @param bool Whether we want to ignore the score color + * @result string The score as we want to show it + */ + private function get_score_display ($score, $realscore, $ignore_score_color = false) { if ($score != null) { $scoredisplay = ScoreDisplay :: instance(); $type = SCORE_CUSTOM; if ($realscore === true) { - $type = SCORE_DIV_PERCENT ; - } + $type = SCORE_DIV_PERCENT ; + } return $scoredisplay->display_score(array($score, $this->evaluation->get_max()), $type, SCORE_BOTH, $ignore_score_color); } - return ''; + return ''; } // Sort functions - used internally diff --git a/main/gradebook/lib/scoredisplay.class.php b/main/gradebook/lib/scoredisplay.class.php index f6c1f96113..98154af5c3 100644 --- a/main/gradebook/lib/scoredisplay.class.php +++ b/main/gradebook/lib/scoredisplay.class.php @@ -17,7 +17,6 @@ define('SCORE_DECIMAL', 5); // 0.50 (X/Y) define('SCORE_BAR', 6); // Uses the Display::bar_progress function define('SCORE_SIMPLE', 7); // X - //@todo where is number 6? define('SCORE_IGNORE_SPLIT', 8); // ?? @@ -31,8 +30,6 @@ define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS', 12); // X - Good! define('SCORE_BOTH',1); define('SCORE_ONLY_DEFAULT',2); define('SCORE_ONLY_CUSTOM',3); -define('SCORE_ONLY_SCORE', 4); - /** * Class to display scores according to the settings made by the platform admin. @@ -78,7 +75,7 @@ class ScoreDisplay } } - + private $coloring_enabled; private $color_split_value; private $custom_enabled; @@ -93,29 +90,29 @@ class ScoreDisplay if (!empty($category_id)) { $this->category_id = $category_id; } - + //Loading portal settings + using standard functions - + $value = api_get_setting('gradebook_score_display_coloring'); - $value = $value['my_display_coloring']; - + $value = $value['my_display_coloring']; + //Settting coloring $this->coloring_enabled = $value == 'true' ? true : false; if ($this->coloring_enabled) { $value = api_get_setting('gradebook_score_display_colorsplit'); - if (isset($value)) { + if (isset($value)) { $this->color_split_value = $value; } } - + //Setting custom enabled - $value = api_get_setting('gradebook_score_display_custom'); - $value = $value['my_display_custom']; + $value = api_get_setting('gradebook_score_display_custom'); + $value = $value['my_display_custom']; $this->custom_enabled = $value == 'true' ? true : false; - - if ($this->custom_enabled) { - + + if ($this->custom_enabled) { + $params = array('category = ? AND subkey = ?' => array('Gradebook', 'ranking')); $displays = api_get_settings_params($params); $portal_displays = array(); @@ -125,48 +122,48 @@ class ScoreDisplay $portal_displays[$data[0]] = array('score' => $data[0], 'display' =>$data[1]); } sort($portal_displays); - } + } $this->custom_display = $portal_displays; - + if (count($this->custom_display)>0) { $value = api_get_setting('gradebook_score_display_upperlimit'); - $value = $value['my_display_upperlimit']; - $this->upperlimit_included = $value == 'true' ? true : false; - $this->custom_display_conv = $this->convert_displays($this->custom_display); + $value = $value['my_display_upperlimit']; + $this->upperlimit_included = $value == 'true' ? true : false; + $this->custom_display_conv = $this->convert_displays($this->custom_display); } } - + //If teachers can override the portal parameters - + if (api_get_setting('teachers_can_change_score_settings') == 'true') { //Load course settings if ($this->custom_enabled) { - $this->custom_display = $this->get_custom_displays(); - if (count($this->custom_display)> 0) { - $this->custom_display_conv = $this->convert_displays($this->custom_display); - } + $this->custom_display = $this->get_custom_displays(); + if (count($this->custom_display)> 0) { + $this->custom_display_conv = $this->convert_displays($this->custom_display); + } } - + if ($this->coloring_enabled) { $this->color_split_value = $this->get_score_color_percent(); } } } - + /** * Is coloring enabled ? */ public function is_coloring_enabled () { return $this->coloring_enabled; } - + /** * Is custom score display enabled ? */ public function is_custom() { return $this->custom_enabled; } - + /** * Is upperlimit included ? */ @@ -248,15 +245,15 @@ class ScoreDisplay } $sql .= "(NULL, '".$display['score']."', '".Database::escape_string($display['display'])."', ".$category_id.", ".intval($scorecolpercent).")"; $count++; - } + } Database::query($sql); } - + public function insert_defaults($category_id) { if (empty($category_id)) { return false; } - + //Get this from DB settings $display = array( 50 => get_lang('GradebookFailed'), @@ -264,9 +261,9 @@ class ScoreDisplay 70 => get_lang('GradebookFair'), 80 => get_lang('GradebookGood'), 90 => get_lang('GradebookOutstanding'), - 100 => get_lang('GradebookExcellent') + 100 => get_lang('GradebookExcellent') ); - + $tbl_display = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY); foreach($display as $value => $text) { $params = array( @@ -275,26 +272,26 @@ class ScoreDisplay 'category_id' => $category_id, 'score_color_percent' => 0, ); - Database::insert($tbl_display, $params); + Database::insert($tbl_display, $params); } - Database::query($sql); + Database::query($sql); } - + public function get_number_decimals() { - $number_decimals = api_get_setting('gradebook_number_decimals'); + $number_decimals = api_get_setting('gradebook_number_decimals'); if (!isset($number_decimals)) { $number_decimals = 0; - } + } return $number_decimals; } - + /** * Formats a number depending of the number of decimals - * + * * @param float a score * @return float the score formatted */ - public function format_score($score) { + public function format_score($score) { return floatval(number_format($score, $this->get_number_decimals())); } @@ -306,38 +303,38 @@ class ScoreDisplay * @param int $what one of the following constants: SCORE_BOTH, SCORE_ONLY_DEFAULT, SCORE_ONLY_CUSTOM (default: SCORE_BOTH) * (only taken into account if custom score display is enabled and for course/platform admin) */ - public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false) { - $my_score = $score == 0 ? 1 : $score; - + public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false) { + $my_score = $score == 0 ? 1 : $score; + if ($type == SCORE_BAR) { - $percentage = $my_score[0]/$my_score[1]*100; - return Display::bar_progress($percentage, null, null, true); + $percentage = $my_score[0]/$my_score[1]*100; + return Display::bar_progress($percentage); } - - if ($type == SCORE_SIMPLE) { + + if ($type == SCORE_SIMPLE) { $simple_score = $this->format_score($my_score[0]); return $simple_score; } - - if ($this->custom_enabled && isset($this->custom_display_conv)) { - $display = $this->display_default($my_score, $type); + + if ($this->custom_enabled && isset($this->custom_display_conv)) { + $display = $this->display_default($my_score, $type); } else { // if no custom display set, use default display $display = $this->display_default($my_score, $type); - } - + } + if ($this->coloring_enabled && $no_color == false) { - $my_score_denom = ($score[1]==0)?1:$score[1]; + $my_score_denom = ($score[1]==0)?1:$score[1]; if (($score[0] / $my_score_denom) < ($this->color_split_value / 100)) { - $display = Display::tag('font', $display, array('color'=>'red')); + $display = Display::tag('font', $display, array('color'=>'red')); //$display = Display::label($display, 'important'); - } + } } return $display; } - + // Internal functions - private function display_default ($score, $type) { + private function display_default ($score, $type) { switch ($type) { case SCORE_DIV : // X / Y return $this->display_as_div($score); @@ -348,7 +345,7 @@ class ScoreDisplay case SCORE_AVERAGE : // XX % return $this->display_as_percent($score); case SCORE_DECIMAL : // 0.50 (X/Y) - return $this->display_as_decimal($score); + return $this->display_as_decimal($score); case SCORE_DIV_PERCENT_WITH_CUSTOM : // X / Y (XX %) - Good! $custom = $this->display_custom($score); if (!empty($custom)) { @@ -360,7 +357,7 @@ class ScoreDisplay if (!empty($custom)) { $custom = ' - '.$custom; } - return $this->display_simple_score($score).$custom; + return $this->display_simple_score($score).$custom; break; case SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS: $custom = $this->display_custom($score); @@ -368,7 +365,7 @@ class ScoreDisplay $custom = ' - '.$custom; } $score = $this->display_simple_score($score); - + //needs sudo apt-get install php5-intl if (class_exists(NumberFormatter)) { $iso = api_get_language_isocode(); @@ -377,21 +374,21 @@ class ScoreDisplay $letters = api_strtoupper($letters); $letters = " ($letters) "; } - - return $score.$letters.$custom; + + return $score.$letters.$custom; break; case SCORE_CUSTOM: // Good! return $this->display_custom($score); } } - + private function display_simple_score($score) { if (isset($score[0])) { return $this->format_score($score[0]); } return ''; } - + /** * Returns "1" for array("100", "100"); */ @@ -399,20 +396,20 @@ class ScoreDisplay $score_denom = ($score[1]==0) ? 1 : $score[1]; return $this->format_score($score[0]/$score_denom); } - + /** * Returns "100 %" for array("100", "100"); */ - private function display_as_percent($score) { - $score_denom = ($score[1]==0) ? 1 : $score[1]; + private function display_as_percent($score) { + $score_denom = ($score[1]==0) ? 1 : $score[1]; return $this->format_score($score[0]/$score_denom*100) . ' %'; } - + /** - * + * * Returns 10.00 / 10.00 for array("100", "100"); * @param array $score - */ + */ private function display_as_div($score) { if ($score == 1) { return '0/0'; @@ -422,12 +419,11 @@ class ScoreDisplay return $score[0] . ' / ' . $score[1]; } } - + /** - * - * Depends in the user selections [0 50] Bad [50:100] Good + * Depends on the teacher's configuration of thresholds. i.e. [0 50] "Bad", [50:100] "Good" * @param array $score - */ + */ private function display_custom ($score) { $my_score_denom= ($score[1]==0) ? 1 : $score[1]; $scaledscore = $score[0] / $my_score_denom; @@ -447,7 +443,7 @@ class ScoreDisplay } } } - + /** * Get score color percent by category @@ -487,8 +483,8 @@ class ScoreDisplay $sql = 'SELECT * FROM '.$tbl_display.' WHERE category_id = '.$category_id.' ORDER BY score'; $result = Database::query($sql); return Database::store_result($result,'ASSOC'); - } - + } + /** * Convert display settings to internally used values diff --git a/main/img/mascot.png b/main/img/mascot.png index be44ae5b43..6bf1987e52 100644 Binary files a/main/img/mascot.png and b/main/img/mascot.png differ diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 4f797d5b39..2febd7f3f1 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -567,6 +567,16 @@ class MessageManager )." AND id='".intval($message_id)."'"; $result = Database::query($query); } + + public static function update_message_status($user_id, $message_id) + { + if ($message_id != strval(intval($message_id)) || $user_id != strval(intval($user_id))) { + return false; + } + $table_message = Database::get_main_table(TABLE_MESSAGE); + $query = "UPDATE $table_message SET msg_status = 1 WHERE user_receiver_id=".intval($user_id)." AND id='".intval($message_id)."'"; + $result = Database::query($query); + } /** * get messages by user id and message id @@ -1430,6 +1440,15 @@ class MessageManager if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { + case 'mark_as_selected' : + $number_of_selected_messages = count($_POST['id']); + if (is_array($_POST['id'])) { + foreach ($_POST['id'] as $index => $message_id) { + MessageManager::update_message_status(api_get_user_id(), $message_id); + } + } + $html .= Display::return_message(api_xml_http_response_encode($success), 'normal', false); + break; case 'delete' : $number_of_selected_messages = count($_POST['id']); foreach ($_POST['id'] as $index => $message_id) { @@ -1462,7 +1481,7 @@ class MessageManager $parameters['f'] = 'social'; $table->set_additional_parameters($parameters); } - $table->set_form_actions(array('delete' => get_lang('DeleteSelectedMessages'))); + $table->set_form_actions(array('delete' => get_lang('DeleteSelectedMessages'),'mark_as_selected' => get_lang('MailMarkSelectedAsRead'))); $html .= $table->return_table(); return $html; diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 054f233642..471eec00fd 100644 --- a/main/inc/lib/sortable_table.class.php +++ b/main/inc/lib/sortable_table.class.php @@ -22,6 +22,7 @@ require_once 'pear/Pager/Pager.php'; * @package chamilo.library */ class SortableTable extends HTML_Table { +<<<<<<< HEAD /** * A name for this table */ @@ -94,31 +95,106 @@ class SortableTable extends HTML_Table { public $other_tables; /** * Activates the odd even rows +======= + /** + * A name for this table + */ + public $table_name; + /** + * The page to display + */ + public $page_nr; + /** + * The column to sort the data + */ + public $column; + /** + * The sorting direction (ASC or DESC) + */ + public $direction; + /** + * Number of items to display per page + */ + public $per_page; + /** + * The default number of items to display per page + */ + public $default_items_per_page; + /** + * A prefix for the URL-parameters, can be used on pages with multiple + * SortableTables + */ + public $param_prefix; + /** + * The pager object to split the data in several pages + */ + public $pager; + /** + * The total number of items in the table + */ + public $total_number_of_items; + /** + * The function to get the total number of items + */ + public $get_total_number_function; + /** + * The function to the the data to display + */ + public $get_data_function; + /** + * An array with defined column-filters + */ + public $column_filters; + /** + * A list of actions which will be available through a select list + */ + public $form_actions; + /** + * Additional parameters to pass in the URL + */ + public $additional_parameters; + /** + * Additional attributes for the th-tags + */ + public $th_attributes; + /** + * Additional attributes for the td-tags + */ + public $td_attributes; + /** + * Array with names of the other tables defined on the same page of this + * table + */ + public $other_tables; + /** + * Activates the odd even rows +>>>>>>> julio19x * **/ public $odd_even_rows_enabled = true; public $use_jqgrid = false; public $table_id = null; public $headers = array(); - /** - * Create a new SortableTable - * @param string $table_name A name for the table (default = 'table') - * @param string $get_total_number_function A user defined function to get - * the total number of items in the table - * @param string $get_data_function A function to get the data to display on - * the current page - * @param int $default_column The default column on which the data should be - * sorted - * @param int $default_items_per_page The default number of items to show - * on one page - * @param string $default_order_direction The default order direction; - * either the constant 'ASC' or 'DESC' - */ - public function __construct($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC', $table_id = null) { + /** + * Create a new SortableTable + * @param string $table_name A name for the table (default = 'table') + * @param string $get_total_number_function A user defined function to get + * the total number of items in the table + * @param string $get_data_function A function to get the data to display on + * the current page + * @param int $default_column The default column on which the data should be + * sorted + * @param int $default_items_per_page The default number of items to show + * on one page + * @param string $default_order_direction The default order direction; + * either the constant 'ASC' or 'DESC' + */ + public function __construct($table_name = 'table', $get_total_number_function = null, $get_data_function = null, $default_column = 1, $default_items_per_page = 20, $default_order_direction = 'ASC', $table_id = null) { if (empty($table_id)) { $table_id = $table_name.uniqid(); } $this->table_id = $table_id; +<<<<<<< HEAD parent :: __construct (array('class' => 'data_table', 'id' => $table_id)); $this->table_name = $table_name; $this->additional_parameters = array (); @@ -129,11 +205,25 @@ class SortableTable extends HTML_Table { $this->column = isset ($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column; $this->column = isset ($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column; +======= + + parent :: __construct (array ('class' => 'data_table', 'id' => $table_id)); + $this->table_name = $table_name; + $this->additional_parameters = array (); + $this->param_prefix = $table_name.'_'; + + $this->page_nr = isset ($_SESSION[$this->param_prefix.'page_nr']) ? intval($_SESSION[$this->param_prefix.'page_nr']) : 1; + $this->page_nr = isset ($_GET[$this->param_prefix.'page_nr']) ? intval($_GET[$this->param_prefix.'page_nr']) : $this->page_nr; + $this->column = isset ($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column; + $this->column = isset ($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column; + +>>>>>>> julio19x //Default direction if (in_array(strtoupper($default_order_direction), array('ASC', 'DESC'))) { $this->direction = $default_order_direction; } +<<<<<<< HEAD if (isset($_SESSION[$this->param_prefix.'direction'])) { $my_session_direction = $_SESSION[$this->param_prefix.'direction']; @@ -245,21 +335,135 @@ class SortableTable extends HTML_Table { //Only show pagination info when there are items to paginate +======= + + if (isset($_SESSION[$this->param_prefix.'direction'])) { + $my_session_direction = $_SESSION[$this->param_prefix.'direction']; + if (!in_array($my_session_direction, array('ASC', 'DESC'))) { + $this->direction = 'ASC'; + } else { + if ($my_session_direction == 'ASC') { + $this->direction = 'ASC'; + } elseif ($my_session_direction == 'DESC') { + $this->direction = 'DESC'; + } + } + } + + if (isset($_GET[$this->param_prefix.'direction'])) { + $my_get_direction = $_GET[$this->param_prefix.'direction']; + if (!in_array($my_get_direction, array('ASC', 'DESC'))){ + $this->direction = 'ASC'; + } else { + if ($my_get_direction == 'ASC') { + $this->direction = 'ASC'; + } elseif ($my_get_direction == 'DESC') { + $this->direction = 'DESC'; + } + } + } + + + // Allow to change paginate in multiples tabs + unset($_SESSION[$this->param_prefix.'per_page']); + + $this->per_page = isset ($_SESSION[$this->param_prefix.'per_page']) ? intval($_SESSION[$this->param_prefix.'per_page']) : $default_items_per_page; + $this->per_page = isset ($_GET[$this->param_prefix.'per_page']) ? intval($_GET[$this->param_prefix.'per_page']) : $this->per_page; + + $_SESSION[$this->param_prefix.'per_page'] = $this->per_page; + $_SESSION[$this->param_prefix.'direction'] = $this->direction ; + $_SESSION[$this->param_prefix.'page_nr'] = $this->page_nr; + $_SESSION[$this->param_prefix.'column'] = $this->column; + $this->pager = null; + $this->default_items_per_page = $default_items_per_page; + $this->total_number_of_items = -1; + $this->get_total_number_function = $get_total_number_function; + $this->get_data_function = $get_data_function; + $this->column_filters = array(); + $this->form_actions = array(); + $this->checkbox_name = null; + $this->td_attributes = array(); + $this->th_attributes = array(); + $this->other_tables = array(); + } + + /** + * Get the Pager object to split the showed data in several pages + */ + public function get_pager() { + if (is_null($this->pager)) { + $total_number_of_items = $this->get_total_number_of_items(); + $params['mode'] = 'Sliding'; + $params['perPage'] = $this->per_page; + $params['totalItems'] = $total_number_of_items; + $params['urlVar'] = $this->param_prefix.'page_nr'; + $params['currentPage'] = $this->page_nr; + $icon_attributes = array('style' => 'vertical-align: middle;'); + $params['prevImg'] = Display :: return_icon('action_prev.png', get_lang('PreviousPage'), $icon_attributes); + $params['nextImg'] = Display :: return_icon('action_next.png', get_lang('NextPage'), $icon_attributes); + $params['firstPageText'] = Display :: return_icon('action_first.png', get_lang('FirstPage'), $icon_attributes); + $params['lastPageText'] = Display :: return_icon('action_last.png', get_lang('LastPage'), $icon_attributes); + $params['firstPagePre'] = ''; + $params['lastPagePre'] = ''; + $params['firstPagePost'] = ''; + $params['lastPagePost'] = ''; + $params['spacesBeforeSeparator'] = ''; + $params['spacesAfterSeparator'] = ''; + $query_vars = array_keys($_GET); + $query_vars_needed = array ($this->param_prefix.'column', $this->param_prefix.'direction', $this->param_prefix.'per_page'); + if (count($this->additional_parameters) > 0) { + $query_vars_needed = array_merge($query_vars_needed, array_keys($this->additional_parameters)); + } + $query_vars_exclude = array_diff($query_vars, $query_vars_needed); + $params['excludeVars'] = $query_vars_exclude; + $this->pager = & Pager::factory($params); + } + return $this->pager; + } + + public function display() { + echo $this->return_table(); + } + /** + * Displays the table, complete with navigation buttons to browse through + * the data-pages. + */ + public function return_table() { + $empty_table = false; + $content = $this->get_table_html(); + + if ($this->get_total_number_of_items() == 0) { + $cols = $this->getColCount(); + $this->setCellAttributes(1, 0, 'style="font-style: italic;text-align:center;" colspan='.$cols); + $message_empty = api_xml_http_response_encode(get_lang('TheListIsEmpty')); + $this->setCellContents(1, 0, $message_empty); + $empty_table = true; + } + $html = ''; + if (!$empty_table) { + $table_id = 'form_'.$this->table_name.'_id'; + $form = $this->get_page_select_form(); + $nav = $this->get_navigation_html(); + + //Only show pagination info when there are items to paginate + +>>>>>>> julio19x if ($this->get_total_number_of_items() > $this->default_items_per_page) { - $html = '
    '; @@ -154,7 +128,7 @@ function handle_plugins() $plugin_list = array(); $my_plugin_list = $plugin_obj->get_plugin_regions(); - foreach ($my_plugin_list as $plugin_item) { + foreach($my_plugin_list as $plugin_item) { $plugin_list[$plugin_item] = $plugin_item; } @@ -185,20 +159,12 @@ function handle_plugins() echo '
    '; if (in_array($plugin, $installed_plugins)) { - echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn')); - echo Display::url( - get_lang('Regions'), - 'settings.php?category=Regions&name='.$plugin, - array('class' => 'btn') - ); + echo Display::url(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn')); + echo Display::url(get_lang('Regions'), 'settings.php?category=Regions&name='.$plugin, array('class' => 'btn')); } if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) { - echo Display::url( - "readme.txt", - api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", - array('class' => 'btn ajax', '_target' => '_blank') - ); + echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank')); } echo '
    '; echo '
    '; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= '
    '; - $html .= $form; - $html .= ''; - $html .= $this->get_table_title(); - $html .= ''; - $html .= $nav; - $html .= '
    '; + $html = ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
    '; + $html .= $form; + $html .= ''; + $html .= $this->get_table_title(); + $html .= ''; + $html .= $nav; + $html .= '
    '; } +<<<<<<< HEAD if (count($this->form_actions) > 0) { @@ -271,12 +475,25 @@ class SortableTable extends HTML_Table { $html .= $content; if (!$empty_table) { +======= + + if (count($this->form_actions) > 0) { + $params = $this->get_sortable_table_param_string().'&'.$this->get_additional_url_paramstring(); + $html .= '