Browse Source

Minor - Code conventions - refs BT#10139

Angel Fernando Quiroz Campos 9 years ago
parent
commit
11686d26c5
1 changed files with 150 additions and 47 deletions
  1. 150 47
      main/create_course/add_course.php

+ 150 - 47
main/create_course/add_course.php

@@ -39,14 +39,20 @@ $htmlHeadXtra[] = '<script type="text/javascript">
     });
 </script>';
 
-$interbreadcrumb[] = array('url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('MyCourses'));
+$interbreadcrumb[] = array(
+    'url' => api_get_path(WEB_PATH) . 'user_portal.php',
+    'name' => get_lang('MyCourses')
+);
 
 // Displaying the header.
 $tool_name = $course_validation_feature ? get_lang('CreateCourseRequest') : get_lang('CreateSite');
 
 $tpl = new Template($tool_name);
 
-if (api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) {
+if (
+    api_get_setting('allow_users_to_create_courses') == 'false' &&
+    !api_is_platform_admin()
+) {
     api_not_allowed(true);
 }
 
@@ -63,75 +69,148 @@ $form = new FormValidator('add_course');
 $form->addElement('header', $tool_name);
 
 // Title
-$form->addElement('text', 'title', array(get_lang('CourseName'), get_lang('Ex')), array('class' => 'span6', 'id' => 'title'));
+$form->addElement(
+    'text',
+    'title',
+    array(
+        get_lang('CourseName'),
+        get_lang('Ex')
+    ),
+    array(
+        'class' => 'span6',
+        'id' => 'title'
+    )
+);
 $form->applyFilter('title', 'html_filter');
 $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
 
 $form->addButtonAdvancedSettings('advanced_params');
-$form->addElement('html','<div id="advanced_params_options" style="display:none">');
+$form->addElement(
+    'html',
+    '<div id="advanced_params_options" style="display:none">'
+);
 
 // Category category.
-$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
+$url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
 
 $form->addElement(
     'select_ajax',
     'category_code',
     get_lang('CourseFaculty'),
     null,
-    array(
-        'url' => $url
-    )
+    array('url' => $url)
 );
 
 // Course code
-$form->addText('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE));
+$form->addText(
+    'wanted_code',
+    array(
+        get_lang('Code'),
+        get_lang('OnlyLettersAndNumbers')
+    ),
+    '',
+    array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE)
+);
 $form->applyFilter('wanted_code', 'html_filter');
-$form->addRule('wanted_code', get_lang('Max'), 'maxlength', CourseManager::MAX_COURSE_LENGTH_CODE);
+$form->addRule(
+    'wanted_code',
+    get_lang('Max'),
+    'maxlength',
+    CourseManager::MAX_COURSE_LENGTH_CODE
+);
 
 // The teacher
-$titular = & $form->addElement('hidden', 'tutor_name', ''); //array(get_lang('Professor'), null), null, array('size' => '60', 'disabled' => 'disabled'));
+//array(get_lang('Professor'), null), null, array('size' => '60', 'disabled' => 'disabled'));
+$titular = & $form->addElement('hidden', 'tutor_name', '');
 if ($course_validation_feature) {
 
     // Description of the requested course.
-    $form->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3'));
+    $form->addElement(
+        'textarea',
+        'description',
+        get_lang('Description'),
+        array('rows' => '3')
+    );
 
     // Objectives of the requested course.
-    $form->addElement('textarea', 'objetives', get_lang('Objectives'), array('rows' => '3'));
+    $form->addElement(
+        'textarea',
+        'objetives',
+        get_lang('Objectives'),
+        array('rows' => '3')
+    );
 
     // Target audience of the requested course.
-    $form->addElement('textarea', 'target_audience', get_lang('TargetAudience'), array('rows' => '3'));
+    $form->addElement(
+        'textarea',
+        'target_audience',
+        get_lang('TargetAudience'),
+        array('rows' => '3')
+    );
 }
 
 // Course language.
-$form->addElement('select_language', 'course_language', get_lang('Ln'), array(), array('style'=>'width:150px'));
+$form->addElement(
+    'select_language',
+    'course_language',
+    get_lang('Ln'),
+    array(),
+    array('style' => 'width:150px')
+);
 $form->applyFilter('select_language', 'html_filter');
 
 // Exemplary content checkbox.
-$form->addElement('checkbox', 'exemplary_content', null, get_lang('FillWithExemplaryContent'));
+$form->addElement(
+    'checkbox',
+    'exemplary_content',
+    null,
+    get_lang('FillWithExemplaryContent')
+);
 
 if ($course_validation_feature) {
 
-    // A special URL to terms and conditions that is set in the platform settings page.
-    $terms_and_conditions_url = trim(api_get_setting('course_validation_terms_and_conditions_url'));
+    // A special URL to terms and conditions that is set
+    // in the platform settings page.
+    $terms_and_conditions_url = trim(
+        api_get_setting('course_validation_terms_and_conditions_url')
+    );
 
-    // If the special setting is empty, then we may get the URL from Chamilo's module "Terms and conditions", if it is activated.
+    // If the special setting is empty,
+    // then we may get the URL from Chamilo's module "Terms and conditions",
+    // if it is activated.
     if (empty($terms_and_conditions_url)) {
         if (api_get_setting('allow_terms_conditions') == 'true') {
-            $terms_and_conditions_url = api_get_path(WEB_CODE_PATH).'auth/inscription.php?legal';
+            $terms_and_conditions_url = api_get_path(WEB_CODE_PATH);
+            $terms_and_conditions_url .= 'auth/inscription.php?legal';
         }
     }
 
     if (!empty($terms_and_conditions_url)) {
         // Terms and conditions to be accepted before sending a course request.
-        $form->addElement('checkbox', 'legal', null, get_lang('IAcceptTermsAndConditions'), 1);
-        $form->addRule('legal', get_lang('YouHaveToAcceptTermsAndConditions'), 'required');
+        $form->addElement(
+            'checkbox',
+            'legal',
+            null,
+            get_lang('IAcceptTermsAndConditions'),
+            1
+        );
+        $form->addRule(
+            'legal', get_lang('YouHaveToAcceptTermsAndConditions'),
+            'required'
+        );
         // Link to terms and conditions.
-        $link_terms_and_conditions = '<script>
-        function MM_openBrWindow(theURL,winName,features) { //v2.0
-            window.open(theURL,winName,features);
-        }
-        </script><a href="#" onclick="javascript: MM_openBrWindow(\''.$terms_and_conditions_url.'\',\'Conditions\',\'scrollbars=yes, width=800\')">';
-        $link_terms_and_conditions .= get_lang('ReadTermsAndConditions').'</a>';
+        $link_terms_and_conditions = '
+            <script>
+            function MM_openBrWindow(theURL, winName, features) { //v2.0
+                window.open(theURL,winName,features);
+            }
+            </script>
+        ';
+        $link_terms_and_conditions .= Display::url(
+            get_lang('ReadTermsAndConditions'),
+            '#',
+            ['onclick' => "javascript:MM_openBrWindow('$terms_and_conditions_url', 'Conditions', 'scrollbars=yes, width=800');"]
+        );
         $form->addElement('label', null, $link_terms_and_conditions);
     }
 }
@@ -139,7 +218,7 @@ if ($course_validation_feature) {
 $obj = new GradeModel();
 $obj->fill_grade_model_select_in_form($form);
 
-$form->addElement('html','</div>');
+$form->addElement('html', '</div>');
 
 // Submit button.
 $form->addButtonCreate($course_validation_feature ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'));
@@ -189,12 +268,12 @@ if ($form->validate()) {
         if (!$course_validation_feature) {
 
             $params = array();
-            $params['title']                = $title;
-            $params['exemplary_content']    = $exemplary_content;
-            $params['wanted_code']          = $wanted_code;
-            $params['course_category']        = $category_code;
-            $params['course_language']      = $course_language;
-            $params['gradebook_model_id']   = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
+            $params['title'] = $title;
+            $params['exemplary_content'] = $exemplary_content;
+            $params['wanted_code'] = $wanted_code;
+            $params['course_category'] = $category_code;
+            $params['course_language'] = $course_language;
+            $params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
 
             $course_info = CourseManager::create_course($params);
 
@@ -213,12 +292,18 @@ if ($form->validate()) {
                 $add_course_tpl = $tpl->get_template('create_course/add_course.tpl');
                 $message = $tpl->fetch($add_course_tpl);*/
 
-                $url = api_get_path(WEB_CODE_PATH).'course_info/start.php?cidReq='.$course_info['code'].'&first=1';
-                header('Location: '.$url);
+                $url = api_get_path(WEB_CODE_PATH);
+                $url .= 'course_info/start.php?cidReq=';
+                $url .= $course_info['code'];
+                $url .= '&first=1';
+                header('Location: ' . $url);
                 exit;
-
             } else {
-                $message = Display :: return_message(get_lang('CourseCreationFailed'), 'error', false);
+                $message = Display::return_message(
+                    get_lang('CourseCreationFailed'),
+                    'error',
+                    false
+                );
                 // Display the form.
                 $content = $form->returnForm();
             }
@@ -238,25 +323,43 @@ if ($form->validate()) {
 
             if ($request_id) {
                 $course_request_info = CourseRequestManager::get_course_request_info($request_id);
-                $message = (is_array($course_request_info) ? '<strong>'.$course_request_info['code'].'</strong> : ' : '').get_lang('CourseRequestCreated');
-                $message = Display :: return_message($message, 'confirmation', false);
-                $message .=  '<div style="float: left; margin:0px; padding: 0px;">' .
-                    '<a class="btn btn-default" href="'.api_get_path(WEB_PATH).'user_portal.php">'.get_lang('Enter').'</a>' .
-                    '</div>';
+                $message = (is_array($course_request_info) ? '<strong>' . $course_request_info['code'] . '</strong> : ' : '') . get_lang('CourseRequestCreated');
+                $message = Display::return_message(
+                    $message,
+                    'confirmation',
+                    false
+                );
+                $message .= Display::tag(
+                    'div',
+                    Display::url(
+                        get_lang('Enter'),
+                        api_get_path(WEB_PATH) . 'user_portal.php',
+                        ['class' => 'btn btn-default']
+                    ),
+                    ['style' => 'float: left; margin:0px; padding: 0px;']
+                );
             } else {
-                $message = Display :: return_message(get_lang('CourseRequestCreationFailed'), 'error', false);
+                $message = Display::return_message(
+                    get_lang('CourseRequestCreationFailed'),
+                    'error',
+                    false
+                );
                 // Display the form.
                 $content = $form->return_form();
             }
         }
     } else {
-        $message = Display :: return_message(get_lang('CourseCodeAlreadyExists'), 'error', false);
+        $message = Display::return_message(
+            get_lang('CourseCodeAlreadyExists'),
+            'error',
+            false
+        );
         // Display the form.
         $content = $form->return_form();
     }
 } else {
     if (!$course_validation_feature) {
-        $message = Display :: return_message(get_lang('Explanation'));
+        $message = Display::return_message(get_lang('Explanation'));
     }
     // Display the form.
     $content = $form->returnForm();