Browse Source

Minor - merge from 1.11.x

jmontoyaa 7 years ago
parent
commit
f7db318ca4

+ 4 - 3
main/admin/add_users_to_usergroup.php

@@ -88,7 +88,6 @@ function change_select(val) {
 </script>';
 
 $form_sent = 0;
-
 $extra_field_list = UserManager::get_extra_fields();
 $new_field_list = [];
 if (is_array($extra_field_list)) {
@@ -124,12 +123,14 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
 
     // If "social group" you need to select a role
     if ($groupInfo['group_type'] == 1 && empty($relation)) {
-        Display::addFlash(Display::return_message(get_lang('SelectRole')));
+        Display::addFlash(Display::return_message(get_lang('SelectRole'), 'warning'));
+        header('Location: '.api_get_self().'?id='.$id);
+        exit;
     }
 
     if ($form_sent == 1) {
         Display::addFlash(Display::return_message(get_lang('Updated')));
-        //added a parameter to send emails when registering a user
+        // Added a parameter to send emails when registering a user
         $usergroup->subscribe_users_to_usergroup(
             $id,
             $elements_posted,

+ 7 - 5
main/admin/career_diagram.php

@@ -107,14 +107,16 @@ $tpl = new Template(get_lang('Diagram'));
 $html = Display::page_subheader2($careerInfo['name'].$urlToString);
 if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
     $graph = unserialize($item['value']);
-    $html .= Career::renderDiagram($careerInfo, $graph);
+    $html .= Career::renderDiagramByColumn($graph, $tpl);
 } else {
     Display::addFlash(
         Display::return_message(
-        sprintf(get_lang('CareerXDoesntHaveADiagram'), $careerInfo['name']),
-        'warning'
-    )
+            sprintf(get_lang('CareerXDoesntHaveADiagram'), $careerInfo['name']),
+            'warning'
+        )
     );
 }
+
 $tpl->assign('content', $html);
-$tpl->display_one_col_template();
+$layout = $tpl->get_template('career/diagram.tpl');
+$tpl->display($layout);

+ 3 - 3
main/admin/configure_homepage.php

@@ -1010,10 +1010,10 @@ switch ($action) {
                 <div class="col-md-3">
 
                     <!-- login block -->
-                    <div id="login_block" class="panel panel-default">
+                    <div id="login-block" class="panel panel-default">
                         <div class="panel-body">
-                            <?php echo api_display_language_form(); ?>
-                            <form id="formLogin" class="form-horizontal">
+                            <?php echo api_display_language_form(false, true); ?>
+                            <form id="form-login" class="form-horizontal">
                                 <div class="input-group">
                                     <div class="input-group-addon"><em class="fa fa-user"></em></div>
                                     <input class="form-control" type="text" id="login" value="" disabled="disabled"/>

+ 1 - 1
main/admin/example.csv

@@ -1,3 +1,3 @@
-LastName;FirstName;Email;UserName;Password;AuthSource;OfficialCode;PhoneNumber;Status;Courses
+LastName;FirstName;Email;UserName;Password;AuthSource;OfficialCode;PhoneNumber;Status;Courses
 Mcfly;Marty;marty@example.com;marty;secret;platform;12345678;001-123-456-789;user;COURSE1|COURSE2|COURSE3
 Brown;Emmert;drbrown@example.net;emmert;;platform;;;teacher;COURSE2

+ 1 - 1
main/admin/example_class.csv

@@ -1,3 +1,3 @@
-name;description;
+name;description;
 Class A4;20 students in general courses
 Class B5;20 students from technical background

+ 1 - 1
main/admin/example_session.csv

@@ -1,3 +1,3 @@
-SessionName;Coach;DateStart;DateEnd;Users;Courses
+SessionName;Coach;DateStart;DateEnd;Users;Courses
 Session1;jmontoya;2008/08/08;2020/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
 Session2;jmontoya;2008/08/08;2020/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]

+ 8 - 0
main/admin/index.php

@@ -270,9 +270,17 @@ if (api_is_platform_admin()) {
         }
     }
 
+    if (api_get_plugin_setting('dictionary', 'enable_plugin_dictionary') == 'true') {
+        $items[] = [
+            'url' => api_get_path(WEB_PLUGIN_PATH).'dictionary/terms.php',
+            'label' => get_lang('Dictionary'),
+        ];
+    }
+
     if (api_get_setting('allow_terms_conditions') == 'true') {
         $items[] = ['url' => 'legal_add.php', 'label' => get_lang('TermsAndConditions')];
     }
+
     $blocks['platform']['items'] = $items;
     $blocks['platform']['extra'] = null;
 }

+ 1 - 1
main/admin/ldap_import_students_to_session.php

@@ -14,7 +14,7 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 // Access restrictions
 api_protect_admin_script();
- require('../auth/ldap/authldap.php');
+ require '../auth/ldap/authldap.php';
 
 $annee_base = date('Y');
 

+ 6 - 5
main/admin/skill.php

@@ -66,14 +66,15 @@ switch ($action) {
             $values = $form->exportValues();
 
             $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
-            $item->setProfile($profile);
-
-            $em->persist($item);
-            $em->flush();
+            if ($profile) {
+                $item->setProfile($profile);
+                $em->persist($item);
+                $em->flush();
+                Display::addFlash(Display::return_message(get_lang('Updated')));
+            }
             header('Location: '.$listAction);
             exit;
         }
-
         break;
     case 'delete':
         $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);

+ 1 - 1
main/admin/skill_example.csv

@@ -1,4 +1,4 @@
-id;parent_id;name;description
+id;parent_id;name;description
 2;1;Reflection;
 3;1;Manage learning;
 4;1;Information literacy;

+ 37 - 23
main/admin/skill_level.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\SkillBundle\Entity\Level;
+
 /**
  * Add a skill Level.
  *
@@ -27,14 +29,14 @@ $id = isset($_GET['id']) ? $_GET['id'] : '';
 
 $item = null;
 if (!empty($id)) {
-    /** @var \Chamilo\SkillBundle\Entity\Level $item */
+    /** @var Level $item */
     $item = $em->getRepository('ChamiloSkillBundle:Level')->find($id);
     if (!$item) {
         api_not_allowed();
     }
 }
 
-$form = new FormValidator('Level', 'GET', api_get_self().'?action='.$action.'&id='.$id);
+$form = new FormValidator('level', 'GET', api_get_self().'?action='.$action.'&id='.$id);
 $form->addText('name', get_lang('Name'));
 $form->addText('short_name', get_lang('ShortName'));
 $form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles);
@@ -49,29 +51,37 @@ if (!empty($item)) {
         'profile_id' => $item->getProfile()->getId(),
     ]);
 }
-$formToDisplay = $form->returnForm();
+
+$formToDisplay = '';
 
 $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
-$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('SkillProfile')];
+$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/skill.php', 'name' => get_lang('ManageSkillsLevels')];
+$interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('SkillLevel')];
 
-$tpl = new Template($action);
 switch ($action) {
     case 'add':
-        $tpl->assign('form', $formToDisplay);
+        $formToDisplay = $form->returnForm();
         if ($form->validate()) {
             $values = $form->exportValues();
-            $item = new \Chamilo\SkillBundle\Entity\Level();
-            $item->setName($values['name']);
-            $item->setShortName($values['short_name']);
-            $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
-            $item->setProfile($profile);
-
-            $em->persist($item);
-            $em->flush();
+            if (isset($values['profile_id']) && !empty($values['profile_id'])) {
+                $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
+                if ($profile) {
+                    $item = new Level();
+                    $item->setName($values['name']);
+                    $item->setShortName($values['short_name']);
+                    $item->setProfile($profile);
+                    $em->persist($item);
+                    $em->flush();
+                    Display::addFlash(Display::return_message(get_lang('Added')));
+                } else {
+                    Display::addFlash(Display::return_message(get_lang('Added')));
+                }
+            } else {
+                Display::addFlash(Display::return_message(get_lang('YouNeedToCreateASkillProfile')));
+            }
             header('Location: '.$listAction);
             exit;
         }
-
         $toolbarAction = Display::url(
             Display::return_icon(
                 'list_badges.png',
@@ -84,7 +94,7 @@ switch ($action) {
         );
         break;
     case 'edit':
-        $tpl->assign('form', $formToDisplay);
+        $formToDisplay = $form->returnForm();
         $toolbarAction = Display::url(
             Display::return_icon(
                 'list_badges.png',
@@ -102,7 +112,9 @@ switch ($action) {
             $item->setName($values['name']);
             $item->setShortName($values['short_name']);
             $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
-            $item->setProfile($profile);
+            if ($profile) {
+                $item->setProfile($profile);
+            }
 
             $em->persist($item);
             $em->flush();
@@ -121,8 +133,11 @@ switch ($action) {
             $listAction,
             ['title' => get_lang('List')]
         );
-        $em->remove($item);
-        $em->flush();
+        if ($item) {
+            $em->remove($item);
+            $em->flush();
+            Display::addFlash(Display::return_message(get_lang('Deleted')));
+        }
         header('Location: '.$listAction);
         exit;
 
@@ -140,12 +155,11 @@ switch ($action) {
         );
 }
 
+$tpl = new Template($action);
+$tpl->assign('form', $formToDisplay);
 $tpl->assign('list', $list);
 $templateName = $tpl->get_template('admin/skill_level.tpl');
 $contentTemplate = $tpl->fetch($templateName);
-$tpl->assign(
-    'actions',
-    Display::toolbarAction('toolbar', [$toolbarAction])
-);
+$tpl->assign('actions', Display::toolbarAction('toolbar', [$toolbarAction]));
 $tpl->assign('content', $contentTemplate);
 $tpl->display_one_col_template();

+ 34 - 20
main/admin/skill_profile.php

@@ -1,6 +1,9 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use Chamilo\SkillBundle\Entity\Level;
+use Chamilo\SkillBundle\Entity\Profile;
+
 /**
  * Add a skill Profile.
  *
@@ -42,7 +45,7 @@ if (!empty($item)) {
 $formToDisplay = $form->returnForm();
 
 $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
-$interbreadcrumb[] = ['url' => 'skill.php', 'name' => get_lang('ManageSkillsLevels')];
+$interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin/skill.php', 'name' => get_lang('ManageSkillsLevels')];
 $interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('SkillProfile')];
 
 $toolbar = null;
@@ -50,29 +53,32 @@ $toolbar = null;
 $tpl = new Template($action);
 switch ($action) {
     case 'move_up':
-        /** @var \Chamilo\SkillBundle\Entity\Level $item */
+        /** @var Level $item */
         $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
-
-        $position = $item->getPosition();
-
-        if (!empty($position)) {
-            $item->setPosition($position - 1);
+        if ($item) {
+            $position = $item->getPosition();
+            if (!empty($position)) {
+                $item->setPosition($position - 1);
+            }
+            $em->persist($item);
+            $em->flush();
+            Display::addFlash(Display::return_message(get_lang('Updated')));
         }
-        $em->persist($item);
-        $em->flush();
+
         header('Location: '.$listAction);
         exit;
         break;
     case 'move_down':
-        /** @var \Chamilo\SkillBundle\Entity\Level $item */
+        /** @var Level $item */
         $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
+        if ($item) {
+            $position = $item->getPosition();
+            $item->setPosition($position + 1);
+            $em->persist($item);
+            $em->flush();
+            Display::addFlash(Display::return_message(get_lang('Updated')));
+        }
 
-        $position = $item->getPosition();
-
-        $item->setPosition($position + 1);
-
-        $em->persist($item);
-        $em->flush();
         header('Location: '.$listAction);
         exit;
         break;
@@ -80,10 +86,12 @@ switch ($action) {
         $tpl->assign('form', $formToDisplay);
         if ($form->validate()) {
             $values = $form->exportValues();
-            $item = new \Chamilo\SkillBundle\Entity\Profile();
+            $item = new Profile();
             $item->setName($values['name']);
             $em->persist($item);
             $em->flush();
+
+            Display::addFlash(Display::return_message(get_lang('Added')));
             header('Location: '.$listAction);
             exit;
         }
@@ -116,6 +124,7 @@ switch ($action) {
             $item->setName($values['name']);
             $em->persist($item);
             $em->flush();
+            Display::addFlash(Display::return_message(get_lang('Updated')));
             header('Location: '.$listAction);
             exit;
         }
@@ -132,11 +141,16 @@ switch ($action) {
             $listAction,
             ['title' => get_lang('List')]
         );
-        $em->remove($item);
-        $em->flush();
+
+        try {
+            $em->remove($item);
+            $em->flush();
+            Display::addFlash(Display::return_message(get_lang('Deleted')));
+        } catch (Exception $e) {
+            Display::addFlash(Display::return_message(get_lang('DeleteError'), 'error'));
+        }
         header('Location: '.$listAction);
         exit;
-
         break;
     default:
         $toolbar = Display::url(

+ 1 - 1
main/admin/user_edit.php

@@ -399,7 +399,7 @@ if ($form->validate()) {
         $language = $user['language'];
         $address = isset($user['address']) ? $user['address'] : null;
 
-        if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
+        if (!$user_data['platform_admin'] && $user['radio_expiration_date'] == '1') {
             $expiration_date = $user['expiration_date'];
         } else {
             $expiration_date = null;

+ 18 - 5
main/admin/user_import.php

@@ -54,13 +54,13 @@ function validate_data($users, $checkUniqueEmail = false)
                 $errors[] = $user;
             }
             // 2.2. Check whether the username was used twice in import file.
-            if (isset($usernames[$user['UserName']])) {
+            if (isset($usernames[$username])) {
                 $user['error'] = get_lang('UserNameUsedTwice');
                 $errors[] = $user;
             }
-            $usernames[$user['UserName']] = 1;
+            $usernames[$username] = 1;
             // 2.3. Check whether username is already occupied.
-            if (!UserManager::is_username_available($user['UserName'])) {
+            if (!UserManager::is_username_available($username)) {
                 $user['error'] = get_lang('UserNameNotAvailable');
                 $errors[] = $user;
             }
@@ -264,8 +264,21 @@ function save_data($users)
  */
 function parse_csv_data($file)
 {
-    $users = Import :: csvToArray($file);
+    $users = Import::csvToArray($file);
+    $allowRandom = api_get_configuration_value('generate_random_login');
+    if ($allowRandom) {
+        $factory = new RandomLib\Factory();
+        $generator = $factory->getLowStrengthGenerator();
+        $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    }
+
     foreach ($users as $index => $user) {
+        if (isset($user['UserName'])) {
+            if ($allowRandom) {
+                $username = $generator->generateString(10, $chars);
+                $user['UserName'] = $username;
+            }
+        }
         if (isset($user['Courses'])) {
             $user['Courses'] = explode('|', trim($user['Courses']));
         }
@@ -493,7 +506,7 @@ if (isset($_POST['formSent']) && $_POST['formSent'] && $_FILES['import_file']['s
     }
 }
 
-Display :: display_header($tool_name);
+Display::display_header($tool_name);
 
 $form = new FormValidator('user_import', 'post', api_get_self());
 $form->addElement('header', '', $tool_name);

+ 9 - 9
main/announcements/announcements.php

@@ -64,19 +64,19 @@ $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
 $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
 $isTutor = false;
 if (!empty($group_id)) {
-    $group_properties = GroupManager:: get_group_properties($group_id);
+    $groupProperties = GroupManager:: get_group_properties($group_id);
     $interbreadcrumb[] = [
         "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
         "name" => get_lang('Groups'),
     ];
     $interbreadcrumb[] = [
         "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
-        "name" => get_lang('GroupSpace').' '.$group_properties['name'],
+        "name" => get_lang('GroupSpace').' '.$groupProperties['name'],
     ];
 
     if ($allowToEdit === false) {
         // Check if user is tutor group
-        $isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties, $courseId);
+        $isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupProperties, $courseId);
         if ($isTutor) {
             $allowToEdit = true;
         }
@@ -119,8 +119,8 @@ switch ($action) {
                     FROM $tbl_announcement announcement,
                     $tbl_item_property itemproperty
                     WHERE
-                        announcement.c_id =  $courseId AND
-                        itemproperty.c_id =  $courseId AND
+                        announcement.c_id = $courseId AND
+                        itemproperty.c_id = $courseId AND
                         itemproperty.ref = announcement.id AND
                         itemproperty.tool = '".TOOL_ANNOUNCEMENT."'  AND
                         itemproperty.visibility <> 2
@@ -455,7 +455,7 @@ switch ($action) {
             }
             $element = CourseManager::addUserGroupMultiSelect($form, []);
         } else {
-            $element = CourseManager::addGroupMultiSelect($form, $group_properties, []);
+            $element = CourseManager::addGroupMultiSelect($form, $groupProperties, []);
         }
 
         $form->addHtml('</div>');
@@ -567,7 +567,7 @@ switch ($action) {
                         $sendToUsersInSession
                     );
 
-                    /*		MAIL FUNCTION	*/
+                    // Send mail
                     if (isset($_POST['email_ann']) && empty($_POST['onlyThoseMails'])) {
                         AnnouncementManager::sendEmail(
                             api_get_course_info(),
@@ -624,7 +624,7 @@ switch ($action) {
                         )
                     );
 
-                    /* MAIL FUNCTION */
+                    // Send mail
                     if (isset($data['email_ann']) && $data['email_ann']) {
                         AnnouncementManager::sendEmail(
                             api_get_course_info(),
@@ -647,7 +647,7 @@ if (!empty($_GET['remind_inactive'])) {
 }
 
 if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
-    //we are not in the learning path
+    // We are not in the learning path
     Display::display_header($nameTools, get_lang('Announcements'));
 }