Browse Source

Format code

Julio Montoya 10 years ago
parent
commit
9f516e9dc4

+ 30 - 32
main/gradebook/lib/fe/catform.class.php

@@ -12,12 +12,10 @@ require_once dirname(__FILE__).'/../be.inc.php';
  */
 class CatForm extends FormValidator
 {
-
-    const TYPE_ADD              = 1;
-    const TYPE_EDIT             = 2;
-    const TYPE_MOVE             = 3;
-    const TYPE_SELECT_COURSE    = 4;
-
+    const TYPE_ADD = 1;
+    const TYPE_EDIT = 2;
+    const TYPE_MOVE = 3;
+    const TYPE_SELECT_COURSE = 4;
     private $category_object;
 
     /**
@@ -132,16 +130,16 @@ class CatForm extends FormValidator
         $this->build_basic_form();
     }
 
-	/**
-	 * Builds an form to edit a category
-	 */
+    /**
+     * Builds an form to edit a category
+     */
     protected function build_editing_form()
     {
         $skills = $this->category_object->get_skills_for_select();
 
         $course_code = api_get_course_id();
         $session_id = api_get_session_id();
-         //Freeze or not
+        //Freeze or not
         $test_cats = Category::load(
             null,
             null,
@@ -388,37 +386,37 @@ class CatForm extends FormValidator
             $visibility_default = 0;
         }
         $this->setDefaults(array('visible' => $visibility_default));
-   	}
+    }
 
     /**
-	 * This function builds an 'select course' form in the add category process,
-	 * if parent id is 0, it will only show courses
-	 */
+     * This function builds an 'select course' form in the add category process,
+     * if parent id is 0, it will only show courses
+     */
     protected function build_select_course_form()
     {
-		$select = $this->addElement('select','select_course',array(get_lang('PickACourse'),'test'), null);
-		$coursecat = Category :: get_all_courses(api_get_user_id());
-		//only return courses that are not yet created by the teacher
-
-		foreach($coursecat as $row) {
-			$select->addoption($row[1],$row[0]);
-		}
-		$this->setDefaults(array(
-		   'hid_user_id' => $this->category_object->get_user_id(),
-		   'hid_parent_id' => $this->category_object->get_parent_id()
-		));
-   		$this->addElement('hidden','hid_user_id');
-   		$this->addElement('hidden','hid_parent_id');
-		$this->addElement('submit', null, get_lang('Ok'));
-   	}
+        $select = $this->addElement('select','select_course',array(get_lang('PickACourse'),'test'), null);
+        $coursecat = Category :: get_all_courses(api_get_user_id());
+        //only return courses that are not yet created by the teacher
+
+        foreach($coursecat as $row) {
+            $select->addoption($row[1],$row[0]);
+        }
+        $this->setDefaults(array(
+            'hid_user_id' => $this->category_object->get_user_id(),
+            'hid_parent_id' => $this->category_object->get_parent_id()
+        ));
+        $this->addElement('hidden','hid_user_id');
+        $this->addElement('hidden','hid_parent_id');
+        $this->addElement('submit', null, get_lang('Ok'));
+    }
 
     function display()
     {
-   		parent :: display();
-   	}
+        parent :: display();
+    }
 
     function setDefaults($defaults = array(), $filter = null)
     {
         parent::setDefaults($defaults, $filter);
-   	}
+    }
 }

+ 12 - 20
main/gradebook/lib/fe/dataform.class.php

@@ -1,24 +1,18 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
 
 /**
- * Extends formvalidator with import and export forms
+ * Extends FormValidator with import and export forms
  * @author Stijn Konings
  * @package chamilo.gradebook
  */
-class DataForm extends FormValidator {
-
+class DataForm extends FormValidator
+{
 	const TYPE_IMPORT = 1;
 	const TYPE_EXPORT = 2;
 	const TYPE_EXPORT_PDF = 3;
@@ -32,20 +26,19 @@ class DataForm extends FormValidator {
 	 * @param method
 	 * @param action
 	 */
-	function DataForm($form_type, $form_name, $method = 'post', $action = null, $target='', $locked_status) {
+	public function DataForm($form_type, $form_name, $method = 'post', $action = null, $target='', $locked_status)
+	{
 		parent :: __construct($form_name, $method, $action,$target);
 		$this->form_type = $form_type;
 		if ($this->form_type == self :: TYPE_IMPORT) {
 			$this->build_import_form();
-		}
-		elseif ($this->form_type == self :: TYPE_EXPORT) {
+		} elseif ($this->form_type == self :: TYPE_EXPORT) {
 			if ($locked_status == 0) {
 				$this->build_export_form_option(false);
 			} else {
 				$this->build_export_form();
-			}			
-		}
-		elseif ($this->form_type == self :: TYPE_EXPORT_PDF) {
+			}
+		} elseif ($this->form_type == self :: TYPE_EXPORT_PDF) {
 			$this->build_pdf_export_form();
 		}
 		$this->setDefaults();
@@ -64,7 +57,6 @@ class DataForm extends FormValidator {
 		));
 	}
 
-
 	protected function build_export_form() {
 		$this->addElement('header', get_lang('ChooseFormat'));
 		$this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
@@ -80,7 +72,7 @@ class DataForm extends FormValidator {
 		$this->addElement('header', get_lang('ChooseFormat'));
 		$this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
 		$this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
-		$this->addElement('radio', 'file_type', Display::return_icon('info3.gif',get_lang('ToExportMustLockEvaluation')), 'PDF (Portable Document Format)', 'pdf', array('disabled'));			
+		$this->addElement('radio', 'file_type', Display::return_icon('info3.gif',get_lang('ToExportMustLockEvaluation')), 'PDF (Portable Document Format)', 'pdf', array('disabled'));
 		$this->addElement('style_submit_button', 'submit', get_lang('Export'), 'class="upload"');
 		$this->setDefaults(array (
 			'file_type' => 'csv'
@@ -102,8 +94,8 @@ class DataForm extends FormValidator {
 		$this->addElement('checkbox','ignoreerrors',null,get_lang('IgnoreErrors'));
 		$this->addElement('style_submit_button', 'submit', get_lang('Ok'));
 		$this->setDefaults(array(
-		'formSent' => '1',
-		'file_type' => 'csv'
+			'formSent' => '1',
+			'file_type' => 'csv'
 		));
 	}
 

+ 2 - 5
main/gradebook/lib/fe/displaygradebook.php

@@ -1,11 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Class
+ * Class DisplayGradebook
  * @package chamilo.gradebook
  */
 class DisplayGradebook

+ 8 - 14
main/gradebook/lib/fe/evalform.class.php

@@ -1,23 +1,11 @@
 <?php
-
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__) . '/../../../inc/global.inc.php';
 require_once dirname(__FILE__) . '/../be.inc.php';
 require_once dirname(__FILE__) . '/../gradebook_functions.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
 
-/**
- * Extends formvalidator with add&edit forms for evaluations
- * @author Stijn Konings
- * @package chamilo.gradebook
- */
 $htmlHeadXtra[] = '<script type="text/javascript">
 function setFocus(){
     $("#evaluation_title").focus();
@@ -27,9 +15,15 @@ $(document).ready(function () {
 });
 </script>';
 
+/**
+ * Class EvalForm
+ *
+ * Extends FormValidator with add&edit forms for evaluations
+ * @author Stijn Konings
+ * @package chamilo.gradebook
+ */
 class EvalForm extends FormValidator
 {
-
     const TYPE_ADD = 1;
     const TYPE_EDIT = 2;
     const TYPE_MOVE = 3;

+ 117 - 117
main/gradebook/lib/fe/exportgradebook.php

@@ -94,15 +94,15 @@ a:active {text-decoration: none; font-weight : bold;  color : black;}
  * @return void
  */
 function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf) {
-    require_once api_get_path(LIBRARY_PATH).'mpdf/mpdf.php';
+	require_once api_get_path(LIBRARY_PATH).'mpdf/mpdf.php';
 
-    $mpdf = new mPDF('UTF-8', 'A4-L', '', '', 15, 10, 35, 20, 4, 2, 'L');
-    $mpdf->useOnlyCoreFonts = true;
-    $mpdf->mirrorMargins = 0;      // Use different Odd/Even headers and footers and mirror margins
+	$mpdf = new mPDF('UTF-8', 'A4-L', '', '', 15, 10, 35, 20, 4, 2, 'L');
+	$mpdf->useOnlyCoreFonts = true;
+	$mpdf->mirrorMargins = 0;      // Use different Odd/Even headers and footers and mirror margins
 
-    if (is_array($headers_pdf)) {
-        // preparing headers pdf
-        $header = '<table width="100%"  cellspacing="1" cellpadding="1" border="0" class="strong">
+	if (is_array($headers_pdf)) {
+		// preparing headers pdf
+		$header = '<table width="100%"  cellspacing="1" cellpadding="1" border="0" class="strong">
                                 <tr>
                                    <td ROWSPAN="3" style="text-align: left;" class="title"><img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png"></td><td  colspan="3"><h1>'.$title_pdf.'</h1></td>
                                 <tr>
@@ -122,92 +122,92 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
                                     <td><strong>'.$headers_pdf[5][0].'</strong> </td><td> <strong>'.$headers_pdf[5][1].'</strong></td>
                                 </tr>
                             </table>';
-    }
+	}
 
-    // preparing footer pdf
-    $footer = '<table width="100%" cellspacing="2" cellpadding="10" border="0">';
-    if (is_array($footers_pdf)) {
-        $footer .= '<tr>';
-        foreach ($footers_pdf as $foot_pdf) {
-            $footer .= '<td width="33%" style="text-align: center;">'.$foot_pdf.'</td>';
-        }
-        $footer .= '</tr>';
-    }
-    $footer .= '</table>';
+	// preparing footer pdf
+	$footer = '<table width="100%" cellspacing="2" cellpadding="10" border="0">';
+	if (is_array($footers_pdf)) {
+		$footer .= '<tr>';
+		foreach ($footers_pdf as $foot_pdf) {
+			$footer .= '<td width="33%" style="text-align: center;">'.$foot_pdf.'</td>';
+		}
+		$footer .= '</tr>';
+	}
+	$footer .= '</table>';
 
-    $footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
+	$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
 
-    // preparing content pdf
-    $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
-    if (file_exists($css_file)) {
-        $css = @file_get_contents($css_file);
-    } else {
-        $css = '';
-    }
+	// preparing content pdf
+	$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
+	if (file_exists($css_file)) {
+		$css = @file_get_contents($css_file);
+	} else {
+		$css = '';
+	}
 
-    if(count($data_table) > 30)
-            $items_per_page = (count($data_table)/2);
-        else
-            $items_per_page = count($data_table);
+	if(count($data_table) > 30)
+		$items_per_page = (count($data_table)/2);
+	else
+		$items_per_page = count($data_table);
 
-    $count_pages = ceil(count($data_table) / $items_per_page);
-    for ($x = 0; $x<$count_pages; $x++) {
-        $content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
-        // header table
-        $content_table .= '<tr>';
-        $i = 0;
-        if (is_array($headers_table)) {
+	$count_pages = ceil(count($data_table) / $items_per_page);
+	for ($x = 0; $x<$count_pages; $x++) {
+		$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
+		// header table
+		$content_table .= '<tr>';
+		$i = 0;
+		if (is_array($headers_table)) {
 
-            foreach ($headers_table as $head_table) {
-                if (!empty($head_table[0])) {
-                    $width = (!empty($head_table[1])?$head_table[1].'%':'');
-                    $content_table .= '<th width="'.$width.'">'.$head_table[0].'</th>';
-                    $i++;
-                }
-            }
-        }
-        $content_table .= '</tr>';
-        // body table
-        if (is_array($data_table) && count($data_table) > 0) {
-            $offset = $x*$items_per_page;
-            $data_table = array_slice ($data_table, $offset, count($data_table));
-            $i = 1;
-            $item = $offset+1;
-            foreach ($data_table as $data) {
-                $content_table .= '<tr>';
-                $content_table .= '<td>'.($item<10?'0'.$item:$item).'</td>';
-                foreach ($data as  $key => $content) {
-                    if (isset($content)) {
-                        $key == 1 ? $align='align="left"':$align='align="center"';
-                        $content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
-                    }
-                }
-                $content_table .= '</tr>';
-                $i++;
-                $item++;
-                if ($i > $items_per_page) { break; }
-            }
-        } else {
-            $content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
-        }
-        $content_table .= '</table>';
-        if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
-    }
+			foreach ($headers_table as $head_table) {
+				if (!empty($head_table[0])) {
+					$width = (!empty($head_table[1])?$head_table[1].'%':'');
+					$content_table .= '<th width="'.$width.'">'.$head_table[0].'</th>';
+					$i++;
+				}
+			}
+		}
+		$content_table .= '</tr>';
+		// body table
+		if (is_array($data_table) && count($data_table) > 0) {
+			$offset = $x*$items_per_page;
+			$data_table = array_slice ($data_table, $offset, count($data_table));
+			$i = 1;
+			$item = $offset+1;
+			foreach ($data_table as $data) {
+				$content_table .= '<tr>';
+				$content_table .= '<td>'.($item<10?'0'.$item:$item).'</td>';
+				foreach ($data as  $key => $content) {
+					if (isset($content)) {
+						$key == 1 ? $align='align="left"':$align='align="center"';
+						$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
+					}
+				}
+				$content_table .= '</tr>';
+				$i++;
+				$item++;
+				if ($i > $items_per_page) { break; }
+			}
+		} else {
+			$content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
+		}
+		$content_table .= '</table>';
+		if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
+	}
 
-    $html = $content_table;
+	$html = $content_table;
 
 
-    // set attributes for pdf
-    $mpdf->SetHTMLHeader($header);
-    $mpdf->SetHTMLFooter($footer);
-    if (!empty($css)) {
-        $mpdf->WriteHTML($css, 1);
-        $mpdf->WriteHTML($html, 2);
-    } else {
-        $mpdf->WriteHTML($html);
-    }
-    $mpdf->Output(replace_dangerous_char($title_pdf.'.pdf'), 'D');
-    exit;
+	// set attributes for pdf
+	$mpdf->SetHTMLHeader($header);
+	$mpdf->SetHTMLFooter($footer);
+	if (!empty($css)) {
+		$mpdf->WriteHTML($css, 1);
+		$mpdf->WriteHTML($html, 2);
+	} else {
+		$mpdf->WriteHTML($html);
+	}
+	$mpdf->Output(replace_dangerous_char($title_pdf.'.pdf'), 'D');
+	exit;
 }
 
 
@@ -220,45 +220,45 @@ function export_pdf_attendance($headers_table, $data_table, $headers_pdf, $foote
  * @return void
  */
 function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf) {
-	
+
 	require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
 	$headers_in_pdf = '<img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png">';
-    
+
 	if (is_array($headers_pdf)) {
 		// preparing headers pdf
-		$header = '<br/><br/><table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">							
-					        <tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr>';		
-		foreach($headers_pdf as $header_pdf) {			
+		$header = '<br/><br/><table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">
+					        <tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr>';
+		foreach($headers_pdf as $header_pdf) {
 			if (!empty($header_pdf[0]) && !empty($header_pdf[1])) {
 				$header.= '<tr><td><strong>'.$header_pdf[0].'</strong> </td><td>'.$header_pdf[1].'</td></tr>';
 			}
-		}		
+		}
 		$header.='</table><br />';
 	}
-		
+
 	// preparing footer pdf
 	$footer = '<table width="100%" cellspacing="2" cellpadding="10" border="0">';
 	if (is_array($footers_pdf)) {
-		$footer .= '<tr>';	
+		$footer .= '<tr>';
 		foreach ($footers_pdf as $foot_pdf) {
 			$footer .= '<td width="33%" style="text-align: center;">'.$foot_pdf.'</td>';
 		}
-		$footer .= '</tr>';	
+		$footer .= '</tr>';
 	}
-	$footer .= '</table>';	
+	$footer .= '</table>';
 	$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
-	
-	// preparing content pdf		
+
+	// preparing content pdf
 	$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
 	if (file_exists($css_file)) {
 		$css = @file_get_contents($css_file);
 	} else {
 		$css = '';
-	}	
+	}
 	$items_per_page = 30;
-	$count_pages = ceil(count($data_table) / $items_per_page);  
+	$count_pages = ceil(count($data_table) / $items_per_page);
 	for ($x = 0; $x<$count_pages; $x++) {
-		$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';	
+		$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
 		// header table
 		$content_table .= '<tr>';
 		$i = 0;
@@ -267,41 +267,41 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
 				if (!empty($head_table[0])) {
 					$width = (!empty($head_table[1])?$head_table[1].'%':'');
 					$content_table .= '<th width="'.$width.'">'.$head_table[0].'</th>';
-					$i++;	
-				}			
-			}		
-		}	
-		$content_table .= '</tr>';			
+					$i++;
+				}
+			}
+		}
+		$content_table .= '</tr>';
 		// body table
-		
+
 		if (is_array($data_table) && count($data_table) > 0) {
-			$offset = $x*$items_per_page;				
+			$offset = $x*$items_per_page;
 			$data_table = array_slice ($data_table, $offset, count($data_table));
 			$i = 1;
 			$item = $offset+1;
-			foreach ($data_table as $data) {			
+			foreach ($data_table as $data) {
 				$content_table .= '<tr>';
 				$content_table .= '<td>'.($item<10?'0'.$item:$item).'</td>';
-				foreach ($data as  $key => $content) {							
+				foreach ($data as  $key => $content) {
 					if (isset($content)) {
 						$key == 1 ? $align='align="left"':$align='align="center"';
-						$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';	
-					}					
+						$content_table .= '<td '.$align.' style="padding:4px;" >'.$content.'</td>';
+					}
 				}
 				$content_table .= '</tr>';
 				$i++;
 				$item++;
 				if ($i > $items_per_page) { break; }
-			}			
+			}
 		} else {
 			$content_table .= '<tr colspan="'.$i.'"><td>'.get_lang('Empty').'</td></tr>';
-		}	
-		$content_table .= '</table>';				
-		if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }		
-	}	
+		}
+		$content_table .= '</table>';
+		if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
+	}
 	$pdf = new PDF();
-    $pdf->set_custom_footer($footer);
-    $pdf->set_custom_header($headers_in_pdf);
+	$pdf->set_custom_footer($footer);
+	$pdf->set_custom_header($headers_in_pdf);
 	$pdf->content_to_pdf($header.$content_table, $css, $title_pdf );
 	exit;
 

+ 1 - 1
main/gradebook/lib/fe/gradebooktable.class.php

@@ -530,7 +530,7 @@ class GradebookTable extends SortableTable
 	 * @param unknown_type $item
 	 * @return string
 	 */
-	private function build_name_link ($item)
+	private function build_name_link($item)
     {
         $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
 		switch ($item->get_item_type()) {

+ 74 - 80
main/gradebook/lib/fe/linkaddeditform.class.php

@@ -1,12 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
@@ -28,14 +22,14 @@ class LinkAddEditForm extends FormValidator
 	 * To add link, define category_object and link_type
 	 * To edit link, define link_object
 	 */
-    public function LinkAddEditForm(
-        $form_type,
-        $category_object,
-        $link_type,
-        $link_object,
-        $form_name,
-        $action = null
-    ) {
+	public function LinkAddEditForm(
+		$form_type,
+		$category_object,
+		$link_type,
+		$link_object,
+		$form_name,
+		$action = null
+	) {
 		parent :: __construct($form_name, 'post', $action);
 
 		// set or create link object
@@ -70,53 +64,53 @@ class LinkAddEditForm extends FormValidator
 			$this->addElement('hidden','name_link',$link->get_name(),array('id'=>'name_link'));
 		}
 
-        if (count($category_object) == 1) {
-            $this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
-        } else {
-            $select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
-            $this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero');
-
-            $default_weight = 0;
-            if (!empty($category_object)) {
-                foreach ($category_object as $my_cat) {
-
-                    if ($my_cat->get_course_code() == api_get_course_id()) {
-                        $grade_model_id = $my_cat->get_grade_model_id();
-                        if (empty($grade_model_id)) {
-
-                            if ($my_cat->get_parent_id() == 0 ) {
-                                $default_weight = $my_cat->get_weight();
-                                $select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
-                            } else {
-                                $select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
-                            }
-                        } else {
-                            $select_gradebook->addoption(get_lang('Select'), 0);
-                        }
-                        if ($link->get_category_id() == $my_cat->get_id()) {
-                            $default_weight = $my_cat->get_weight();
-                        }
-                    }
-                }
-            }
-        }
+		if (count($category_object) == 1) {
+			$this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
+		} else {
+			$select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
+			$this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero');
+
+			$default_weight = 0;
+			if (!empty($category_object)) {
+				foreach ($category_object as $my_cat) {
+
+					if ($my_cat->get_course_code() == api_get_course_id()) {
+						$grade_model_id = $my_cat->get_grade_model_id();
+						if (empty($grade_model_id)) {
+
+							if ($my_cat->get_parent_id() == 0 ) {
+								$default_weight = $my_cat->get_weight();
+								$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
+							} else {
+								$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
+							}
+						} else {
+							$select_gradebook->addoption(get_lang('Select'), 0);
+						}
+						if ($link->get_category_id() == $my_cat->get_id()) {
+							$default_weight = $my_cat->get_weight();
+						}
+					}
+				}
+			}
+		}
 
 		$this->add_textfield(
-            'weight_mask',
-            array(get_lang('Weight'), null, ' [0 .. <span id="max_weight">'.$category_object[0]->get_weight().'</span>] '),
-            true,
-            array(
-			    'size' => '4',
-			    'maxlength' => '5',
-                'class' => 'span1'
-		    )
-        );
+			'weight_mask',
+			array(get_lang('Weight'), null, ' [0 .. <span id="max_weight">'.$category_object[0]->get_weight().'</span>] '),
+			true,
+			array(
+				'size' => '4',
+				'maxlength' => '5',
+				'class' => 'span1'
+			)
+		);
 
-        $this->addElement('hidden', 'weight');
+		$this->addElement('hidden', 'weight');
 
-        /*
+		/*
 
-		// ELEMENT: weight
+        // ELEMENT: weight
         $this->add_textfield('weight', array(get_lang('Weight'), null, '/ <span id="max_weight">'.$default_weight.'</span>'), true, array (
             'size' => '4',
             'maxlength' => '5',
@@ -126,21 +120,21 @@ class LinkAddEditForm extends FormValidator
 		$this->addRule('weight_mask',get_lang('OnlyNumbers'),'numeric');
 		$this->addRule(array ('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
 		if ($form_type == self :: TYPE_EDIT) {
-            $parent_cat = Category :: load($link->get_category_id());
-
-            if ($parent_cat[0]->get_parent_id() == 0) {
-                $values['weight'] = $link->get_weight();
-            } else {
-                $cat = Category :: load($parent_cat[0]->get_parent_id());
-                //$global_weight = $cat[0]->get_weight();
-                //$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
-                //var_dump($global_weight, $link->get_weight(), $parent_cat[0]->get_weight());
-                //$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight;
-                //$values['weight'] = $weight;
-                $values['weight'] = $link->get_weight() ;
-            }
-            $defaults['weight_mask'] = $values['weight'] ;
-            $defaults['select_gradebook'] = $link->get_category_id();
+			$parent_cat = Category :: load($link->get_category_id());
+
+			if ($parent_cat[0]->get_parent_id() == 0) {
+				$values['weight'] = $link->get_weight();
+			} else {
+				$cat = Category :: load($parent_cat[0]->get_parent_id());
+				//$global_weight = $cat[0]->get_weight();
+				//$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
+				//var_dump($global_weight, $link->get_weight(), $parent_cat[0]->get_weight());
+				//$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight;
+				//$values['weight'] = $weight;
+				$values['weight'] = $link->get_weight() ;
+			}
+			$defaults['weight_mask'] = $values['weight'] ;
+			$defaults['select_gradebook'] = $link->get_category_id();
 
 		}
 		// ELEMENT: max
@@ -187,14 +181,14 @@ class LinkAddEditForm extends FormValidator
 			$this->addElement('style_submit_button', 'submit', get_lang('LinkMod'),'class="save"');
 		}
 
-        if ($form_type == self :: TYPE_ADD) {
-            $setting = api_get_setting('tool_visible_by_default_at_creation');
-            $visibility_default = 1;
-            if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
-                $visibility_default = 0;
-            }
-            $defaults['visible']  = $visibility_default;
-        }
+		if ($form_type == self :: TYPE_ADD) {
+			$setting = api_get_setting('tool_visible_by_default_at_creation');
+			$visibility_default = 1;
+			if (isset($setting['gradebook']) && $setting['gradebook'] == 'false') {
+				$visibility_default = 0;
+			}
+			$defaults['visible']  = $visibility_default;
+		}
 
 		// set default values
 		$this->setDefaults($defaults);

+ 40 - 43
main/gradebook/lib/fe/linkform.class.php

@@ -1,18 +1,13 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
 
 /**
+ * Class LinkForm
  * Forms related to links
  * @author Stijn Konings
  * @author Bert Steppé (made more generic)
@@ -35,7 +30,8 @@ class LinkForm extends FormValidator
 	 * @param method
 	 * @param action
 	 */
-	function LinkForm($form_type, $category_object,$link_object, $form_name, $method = 'post', $action = null, $extra = null) {
+	function LinkForm($form_type, $category_object,$link_object, $form_name, $method = 'post', $action = null, $extra = null)
+	{
 		parent :: __construct($form_name, $method, $action);
 
 		if (isset ($category_object)) {
@@ -54,7 +50,8 @@ class LinkForm extends FormValidator
 		//$this->setDefaults();
 	}
 
-	protected function build_move() {
+	protected function build_move()
+	{
 		$renderer =& $this->defaultRenderer();
 		$renderer->setElementTemplate('<span>{element}</span> ');
 		$this->addElement('static',null,null,'"'.$this->link_object->get_name().'" ');
@@ -67,11 +64,11 @@ class LinkForm extends FormValidator
 			$select->addoption($line.' '.$cat[1],$cat[0]);
 			$line = '';
 		}
-   		$this->addElement('submit', null, get_lang('Ok'));
+		$this->addElement('submit', null, get_lang('Ok'));
 	}
 
 	protected function build_create()
-    {
+	{
 		$this->addElement('header', get_lang('MakeLink'));
 		$select = $this->addElement('select', 'select_link', get_lang('ChooseLink'), null, array('onchange' => 'document.create_link.submit()'));
 
@@ -82,28 +79,28 @@ class LinkForm extends FormValidator
 		$courseCode = $this->category_object->get_course_code();
 
 		foreach ($linkTypes as $linkType) {
-            // The hot potatoe link will be added "inside" the exercise option.
-            if ($linkType == LINK_HOTPOTATOES) {
-                continue;
-            }
-            $link = $this->createLink($linkType, $courseCode);
+			// The hot potatoe link will be added "inside" the exercise option.
+			if ($linkType == LINK_HOTPOTATOES) {
+				continue;
+			}
+			$link = $this->createLink($linkType, $courseCode);
 			// disable this element if the link works with a dropdownlist
 			// and if there are no links left
 			if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') {
 				$select->addoption($link->get_type_name(), $linkType, 'disabled');
 			} else {
-                if ($link->get_type() == LINK_EXERCISE) {
-                    // Adding exercise
-				    $select->addoption($link->get_type_name(), $linkType);
-                    // Adding hot potatoes
-                    $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
-                    $select->addoption(
-                        '&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
-                        LINK_HOTPOTATOES
-                    );
-                } else {
-                    $select->addoption($link->get_type_name(), $linkType);
-                }
+				if ($link->get_type() == LINK_EXERCISE) {
+					// Adding exercise
+					$select->addoption($link->get_type_name(), $linkType);
+					// Adding hot potatoes
+					$linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode);
+					$select->addoption(
+						'&nbsp;&nbsp;&nbsp;'.$linkHot->get_type_name(),
+						LINK_HOTPOTATOES
+					);
+				} else {
+					$select->addoption($link->get_type_name(), $linkType);
+				}
 			}
 		}
 
@@ -112,20 +109,20 @@ class LinkForm extends FormValidator
 		}
 	}
 
-    /**
-     * @param $link
-     * @param $courseCode
-     * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink
-     */
-    private function createLink($link, $courseCode)
-    {
-        $link = LinkFactory::create($link);
-        if (!empty($courseCode)) {
-            $link->set_course_code($courseCode);
-        } elseif(!empty($_GET['course_code'])) {
-            $link->set_course_code(Database::escape_string($_GET['course_code']));
-        }
+	/**
+	 * @param $link
+	 * @param $courseCode
+	 * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink
+	 */
+	private function createLink($link, $courseCode)
+	{
+		$link = LinkFactory::create($link);
+		if (!empty($courseCode)) {
+			$link->set_course_code($courseCode);
+		} elseif(!empty($_GET['course_code'])) {
+			$link->set_course_code(Database::escape_string($_GET['course_code']));
+		}
 
-        return $link;
-    }
+		return $link;
+	}
 }

+ 16 - 21
main/gradebook/lib/fe/resulttable.class.php

@@ -1,16 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 
 /**
+ * Class ResultTable
  * Table to display results for an evaluation
  * @author Stijn Konings
  * @author Bert Steppé
@@ -18,7 +13,6 @@ require_once dirname(__FILE__).'/../be.inc.php';
  */
 class ResultTable extends SortableTable
 {
-
 	private $datagen;
 	private $evaluation;
 	private $allresults;
@@ -27,7 +21,8 @@ class ResultTable extends SortableTable
 	/**
 	 * Constructor
 	 */
-    function ResultTable ($evaluation, $results = array(), $iscourse, $addparams = null,$forprint = false) {
+    public function ResultTable ($evaluation, $results = array(), $iscourse, $addparams = null,$forprint = false)
+	{
     	parent :: __construct ('resultlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1);
 
 		$this->datagen = new ResultsDataGenerator($evaluation, $results, true);
@@ -81,7 +76,7 @@ class ResultTable extends SortableTable
 
 		// determine sorting type
 		$col_adjust = $this->iscourse == '1' ? 1 : 0;
-        
+
 		switch ($this->column) {
 			// first name or last name
 			case (0 + $col_adjust):
@@ -101,23 +96,23 @@ class ResultTable extends SortableTable
 				break;
             //Score
 			case (2 + $col_adjust):
-				$sorting = ResultsDataGenerator :: RDG_SORT_SCORE;                
+				$sorting = ResultsDataGenerator :: RDG_SORT_SCORE;
 				break;
 			case (3 + $col_adjust):
 				$sorting = ResultsDataGenerator :: RDG_SORT_MASK;
 				break;
 		}
-        
+
 		if ($this->direction == 'DESC') {
 			$sorting |= ResultsDataGenerator :: RDG_SORT_DESC;
 		} else {
 			$sorting |= ResultsDataGenerator :: RDG_SORT_ASC;
 		}
-        
+
 		$data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
-        
+
 		// generate the data to display
-		$sortable_data = array();		
+		$sortable_data = array();
 		foreach ($data_array as $item) {
 			$row = array ();
 			if ($this->iscourse == '1') {
@@ -130,9 +125,9 @@ class ResultTable extends SortableTable
 				$row[] = $item['lastname'];
 				$row[] = $item['firstname'];
 			}
-            
+
 			$row[] =  Display::bar_progress($item['percentage_score'], false, $item['score']);
-            //$row[] =  Display::bar_progress($item['percentage_score'], true);                        
+            //$row[] =  Display::bar_progress($item['percentage_score'], true);
 			if ($scoredisplay->is_custom()) {
 				$row[] = $item['display'];
 			}
@@ -144,8 +139,8 @@ class ResultTable extends SortableTable
 
 		return $sortable_data;
 	}
-    
-	private function build_edit_column ($item) { 
+
+	private function build_edit_column ($item) {
 		$status=CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
 		$locked_status = $this->evaluation->get_locked();
 		if (api_is_allowed_to_edit(null, true) && $locked_status == 0) {//api_is_course_admin()
@@ -156,12 +151,12 @@ class ResultTable extends SortableTable
 			$edit_column.= '&nbsp;<a href="' . api_get_self() . '?resultdelete=' . $item['result_id'] . '&selecteval=' . $this->evaluation->get_id() . '" onclick="return confirmationuser();"><img src="../img/delete.gif" border="0" title="' . get_lang('Delete') . '" alt="" /></a>';
 		    $edit_column.= '&nbsp;<a href="user_stats.php?userid=' . $item['id'] . '&selecteval=' . $this->evaluation->get_id() . '"><img src="../img/statistics.gif" width="17px" border="0" title="' . get_lang('Statistics') . '" alt="" /></a>';
 		}
-		// Evaluation's origin is a link        
+		// Evaluation's origin is a link
 		if ($this->evaluation->get_category_id() < 0) {
 			$link = LinkFactory :: get_evaluation_link ($this->evaluation->get_id());
 
 			$doc_url = $link->get_view_url($item['id']);
-            
+
 			if ($doc_url != null) {
 				$edit_column .= '&nbsp;<a href="'. $doc_url . '" target="_blank">'
 								.'<img src="'. api_get_path(WEB_CODE_PATH) . 'img/link.gif" border="0" title="' . get_lang('OpenDocument') . '" alt="" />'

+ 19 - 24
main/gradebook/lib/fe/scoredisplayform.class.php

@@ -1,16 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
 
 /**
+ * Class ScoreDisplayForm
  * Form for the score display dialog
  * @author Stijn Konings
  * @author Bert Steppé
@@ -22,12 +17,12 @@ class ScoreDisplayForm extends FormValidator
 		parent :: __construct($form_name, 'post', $action);
 		$displayscore = ScoreDisplay :: instance();
 		$customdisplays = $displayscore->get_custom_score_display_settings();
-        
+
 		$nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1';
-		$this->setDefaults(array (            
-            'scorecolpercent' => $displayscore->get_color_split_value()                
+		$this->setDefaults(array (
+            'scorecolpercent' => $displayscore->get_color_split_value()
 		));
-                
+
 		$this->addElement('hidden', 'maxvalue', '100');
 		$this->addElement('hidden', 'minvalue', '0');
 		$counter= 1;
@@ -46,20 +41,20 @@ class ScoreDisplayForm extends FormValidator
 		$scorecol = array();
 
 		//settings for the colored score
-		$this->addElement('header', get_lang('ScoreEdit'));		
-        
-        if ($displayscore->is_coloring_enabled()) {            
-            $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');            
+		$this->addElement('header', get_lang('ScoreEdit'));
+
+        if ($displayscore->is_coloring_enabled()) {
+            $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');
             $this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array (
                 'size' => 5,
                 'maxlength' => 5,
                 'class'=>'span1',
             ));
-            
-            if (api_get_setting('teachers_can_change_score_settings') != 'true') {            
+
+            if (api_get_setting('teachers_can_change_score_settings') != 'true') {
                 $this->freeze('scorecolpercent');
             }
-            
+
             $this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric');
             $this->addRule(array('scorecolpercent','maxvalue'), get_lang('Over100'), 'compare', '<=');
             $this->addRule(array('scorecolpercent','minvalue'), get_lang('UnderMin'), 'compare', '>');
@@ -67,8 +62,8 @@ class ScoreDisplayForm extends FormValidator
 
 		//Settings for the scoring system
 
-		if ($displayscore->is_custom()) {            
-            $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>');            
+		if ($displayscore->is_custom()) {
+            $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>');
 			$this->addElement('static', null, null, get_lang('ScoreInfo'));
 			$scorenull[]= & $this->CreateElement('static', null, null, get_lang('Between'));
 			$this->setDefaults(array (
@@ -86,14 +81,14 @@ class ScoreDisplayForm extends FormValidator
 				$elementTemplateTwoLabel =
 				'<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';" class="control-group">
 				<p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
-                
+
                 <label class="control-label">{label}</label>
 				<div class="controls"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->	<br/>&nbsp<b>'.get_lang('And').'</b>&nbsp&nbsp&nbsp&nbsp&nbsp{element}&nbsp%&nbsp&nbsp=';
 
 				$elementTemplateTwoLabel2 =
 				'<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}
                     <a href="javascript:plusItem(' . ($counter+1) . ')"><img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="plus-' . ($counter+1) . '" src="../img/icons/22/add.png" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></img></a>
-        			<a href="javascript:minItem(' . ($counter) . ')"><img style="display: '.(($counter>=$nr_items && $counter!=1)?'inline':'none').';" id="min-' . $counter . '" src="../img/delete.png" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></img></a>				
+        			<a href="javascript:minItem(' . ($counter) . ')"><img style="display: '.(($counter>=$nr_items && $counter!=1)?'inline':'none').';" id="min-' . $counter . '" src="../img/delete.png" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></img></a>
 				</div></p></div>';
 
 				$scorebetw= array ();
@@ -116,11 +111,11 @@ class ScoreDisplayForm extends FormValidator
 				$this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
 			}
 		}
-        
+
         if ($displayscore->is_custom())
             $this->addElement('style_submit_button', 'submit', get_lang('Ok'),'class="save"');
 	}
-    
+
 	function validate() {
 		return parent :: validate();
 	}

+ 18 - 15
main/gradebook/lib/fe/userform.class.php

@@ -1,18 +1,14 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
 require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
 require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
+
 /**
+ * Class UserForm
  * Extends formvalidator with import and export forms
  * @author Stijn Konings
  * @package chamilo.gradebook
@@ -29,7 +25,8 @@ class UserForm extends FormValidator
 	 * @param method
 	 * @param action
 	 */
-	function UserForm($form_type, $user, $form_name, $method= 'post', $action= null) {
+	public function UserForm($form_type, $user, $form_name, $method= 'post', $action= null)
+	{
 		parent :: __construct($form_name, $method, $action);
 		$this->form_type= $form_type;
 		if (isset ($user)) {
@@ -47,11 +44,12 @@ class UserForm extends FormValidator
 		$this->setDefaults();
 	}
 
-	protected function build_simple_search() {
+	protected function build_simple_search()
+	{
 		if (isset($_GET['search']) && (!empty($_GET['search']))) {
-		   	$this->setDefaults(array(
-   		    'keyword' => Security::remove_XSS($_GET['search'])
-   		    ));
+			$this->setDefaults(array(
+				'keyword' => Security::remove_XSS($_GET['search'])
+			));
 		}
 		$renderer =& $this->defaultRenderer();
 		$renderer->setElementTemplate('<span>{element}</span> ');
@@ -59,7 +57,8 @@ class UserForm extends FormValidator
 		$this->addElement('style_submit_button','submit',get_lang('Search'),'class="search"');
 	}
 
-	protected function build_user_info_form() {
+	protected function build_user_info_form()
+	{
 		if (api_is_western_name_order()) {
 			$this->addElement('static', 'fname', get_lang('FirstName'), $this->user_info['firstname']);
 			$this->addElement('static', 'lname', get_lang('LastName'), $this->user_info['lastname']);
@@ -73,10 +72,14 @@ class UserForm extends FormValidator
 		$this->addElement('static', 'phone', get_lang('Phone'), $this->user_info['phone']);
 		$this->addElement('style_submit_button', 'submit', get_lang('Back'),'class="save"');
 	}
-	function display() {
+
+	function display()
+	{
 		parent :: display();
 	}
-	function setDefaults($defaults= array(), $filter = null) {
+
+	function setDefaults($defaults= array(), $filter = null)
+	{
 		parent :: setDefaults($defaults, $filter);
 	}
 }

+ 21 - 31
main/gradebook/lib/fe/usertable.class.php

@@ -1,16 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
+
 require_once dirname(__FILE__).'/../../../inc/global.inc.php';
 require_once dirname(__FILE__).'/../be.inc.php';
 
 /**
+ * Class UserTable
  * Table to display flat view of a student's evaluations and links
  * @author Stijn Konings
  * @author Bert Steppé (refactored, optimised, use of caching, datagenerator class)
@@ -18,21 +13,17 @@ require_once dirname(__FILE__).'/../be.inc.php';
  */
 class UserTable extends SortableTable
 {
-
 	private $userid;
 	private $datagen;
 
-
 	/**
 	 * Constructor
 	 */
-    function UserTable ($userid, $evals = array(), $links = array(), $addparams = null) {
-    	parent :: __construct ('userlist', null, null, 0);
-
+	public function UserTable ($userid, $evals = array(), $links = array(), $addparams = null)
+	{
+		parent :: __construct ('userlist', null, null, 0);
 		$this->userid = $userid;
-
 		$this->datagen = new UserDataGenerator($userid, $evals, $links);
-
 		if (isset($addparams)) {
 			$this->set_additional_parameters($addparams);
 		}
@@ -48,22 +39,22 @@ class UserTable extends SortableTable
 		if ($scoredisplay->is_custom()) {
 			$this->set_header($column++, get_lang('Display'));
 		}
-    }
+	}
 
 
 	/**
 	 * Function used by SortableTable to get total number of items in the table
 	 */
-	function get_total_number_of_items () {
+	function get_total_number_of_items ()
+	{
 		return $this->datagen->get_total_items_count();
 	}
 
-
 	/**
 	 * Function used by SortableTable to generate the data to display
 	 */
-	function get_table_data ($from = 1) {
-
+	function get_table_data ($from = 1)
+	{
 		$scoredisplay = ScoreDisplay :: instance();
 
 		// determine sorting type
@@ -116,27 +107,26 @@ class UserTable extends SortableTable
 		return $sortable_data;
 	}
 
-
-// Other functions
-
-	private function build_type_column ($item) {
+	private function build_type_column($item)
+	{
 		return build_type_icon_tag($item->get_icon_name());
 	}
 
-	private function build_name_link ($item) {
+	private function build_name_link($item)
+	{
 		switch ($item->get_item_type()) {
 			// evaluation
 			case 'E' :
 				return '&nbsp;'
-					. '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">'
-					. $item->get_name()
-					. '</a>';
+				. '<a href="gradebook_view_result.php?selecteval=' . $item->get_id() . '">'
+				. $item->get_name()
+				. '</a>';
 			// link
 			case 'L' :
 				return '&nbsp;<a href="' . $item->get_link() . '">'
-						. $item->get_name()
-						. '</a>'
-						. '&nbsp;[' . $item->get_type_name() . ']';
+				. $item->get_name()
+				. '</a>'
+				. '&nbsp;[' . $item->get_type_name() . ']';
 		}
 	}
-}
+}

+ 1 - 1
main/gradebook/lib/gradebook_data_generator.class.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
- * GradebookDataGenerator Class
+ * Class GradebookDataGenerator
  * Class to select, sort and transform object data into array data,
  * used for the general gradebook view
  * @author Bert Steppé

+ 16 - 17
main/gradebook/lib/gradebook_functions_users.inc.php

@@ -12,10 +12,9 @@
  */
 function get_users_in_course($course_id)
 {
-	$tbl_course_user 			= Database :: get_main_table(TABLE_MAIN_COURSE_USER);
-	$tbl_session_course_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-	$tbl_user 					= Database :: get_main_table(TABLE_MAIN_USER);
-
+	$tbl_course_user = Database:: get_main_table(TABLE_MAIN_COURSE_USER);
+	$tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+	$tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
 	$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname ASC' : ' ORDER BY lastname, firstname ASC';
 
 	$current_session = api_get_session_id();
@@ -41,18 +40,18 @@ function get_users_in_course($course_id)
 
 function get_user_array_from_sql_result($result)
 {
-    $a_students = array();
-    while ($user = Database::fetch_array($result)) {
-        if (!array_key_exists($user['user_id'], $a_students)) {
-            $a_current_student = array ();
-            $a_current_student[] = $user['user_id'];
-            $a_current_student[] = $user['username'];
-            $a_current_student[] = $user['lastname'];
-            $a_current_student[] = $user['firstname'];
-            $a_current_student[] = $user['official_code'];
-            $a_students['STUD'.$user['user_id']] = $a_current_student;
-        }
-    }
+	$a_students = array();
+	while ($user = Database::fetch_array($result)) {
+		if (!array_key_exists($user['user_id'], $a_students)) {
+			$a_current_student = array ();
+			$a_current_student[] = $user['user_id'];
+			$a_current_student[] = $user['username'];
+			$a_current_student[] = $user['lastname'];
+			$a_current_student[] = $user['firstname'];
+			$a_current_student[] = $user['official_code'];
+			$a_students['STUD'.$user['user_id']] = $a_current_student;
+		}
+	}
 	return $a_students;
 }
 
@@ -76,7 +75,7 @@ function get_all_users ($evals = array(), $links = array())
 			$sql = 'SELECT user.user_id,lastname, firstname, user.official_code
                     FROM '.$tbl_res.' as res, '.$tbl_user.' as user
                     WHERE res.evaluation_id = '.intval($eval->get_id())
-					.' AND res.user_id = user.user_id';
+				.' AND res.user_id = user.user_id';
 			$result = Database::query($sql);
 			$users = array_merge($users, get_user_array_from_sql_result($result));
 		}

+ 5 - 5
main/gradebook/lib/results_data_generator.class.php

@@ -82,11 +82,11 @@ 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
-                )
+                array($result->get_score(), $this->evaluation->get_max()),
+                SCORE_PERCENT,
+                SCORE_BOTH,
+                true
+            )
             );
             if ($pdf && $number_decimals == null){
                 $user['scoreletter'] = $result->get_score();

+ 22 - 30
main/gradebook/lib/scoredisplay.class.php

@@ -1,37 +1,31 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Script
- * @package chamilo.gradebook
- */
-/**
- * Init
- */
 
 // Score display types constants
-define('SCORE_DIV',                      1);    // X / Y
-define('SCORE_PERCENT',                  2);    // XX %
-define('SCORE_DIV_PERCENT',              3);    // X / Y (XX %)
-define('SCORE_AVERAGE',                  4);    // XX %
-define('SCORE_DECIMAL',                  5);    // 0.50  (X/Y)
-define('SCORE_BAR',                      6);    // Uses the Display::bar_progress function
-define('SCORE_SIMPLE',                   7);    // X
+define('SCORE_DIV', 1);    // X / Y
+define('SCORE_PERCENT', 2);    // XX %
+define('SCORE_DIV_PERCENT', 3);    // X / Y (XX %)
+define('SCORE_AVERAGE', 4);    // XX %
+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);    //  ??
+define('SCORE_IGNORE_SPLIT', 8);    //  ??
 
-define('SCORE_DIV_PERCENT_WITH_CUSTOM',  9);    // X / Y (XX %) - Good!
-define('SCORE_CUSTOM',                  10);    // Good!
-define('SCORE_DIV_SIMPLE_WITH_CUSTOM',  11);    // X - Good!
+define('SCORE_DIV_PERCENT_WITH_CUSTOM', 9);    // X / Y (XX %) - Good!
+define('SCORE_CUSTOM', 10);    // Good!
+define('SCORE_DIV_SIMPLE_WITH_CUSTOM', 11);    // X - Good!
 
-define('SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS',  12);    // X - Good!
+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_BOTH', 1);
+define('SCORE_ONLY_DEFAULT', 2);
+define('SCORE_ONLY_CUSTOM', 3);
 
 /**
+ * Class ScoreDisplay
  * Class to display scores according to the settings made by the platform admin.
  * This class works as a singleton: call instance() to retrieve an object.
  * @author Bert Steppé
@@ -39,7 +33,12 @@ define('SCORE_ONLY_CUSTOM',3);
  */
 class ScoreDisplay
 {
-    // Singleton stuff
+    private $coloring_enabled;
+    private $color_split_value;
+    private $custom_enabled;
+    private $upperlimit_included;
+    private $custom_display;
+    private $custom_display_conv;
 
     /**
      * Get the instance of this class
@@ -76,13 +75,6 @@ class ScoreDisplay
         }
     }
 
-    private $coloring_enabled;
-    private $color_split_value;
-    private $custom_enabled;
-    private $upperlimit_included;
-    private $custom_display;
-    private $custom_display_conv;
-
     /**
      * Protected constructor - call instance() to instantiate
      */

+ 62 - 54
main/gradebook/lib/user_data_generator.class.php

@@ -1,10 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
- * Script
- * @package chamilo.gradebook
- */
-/**
+ * Class UserDataGenerator
  * Class to select, sort and transform object data into array data,
  * used for a student's general view
  * @author Bert Steppé
@@ -12,7 +10,6 @@
  */
 class UserDataGenerator
 {
-
 	// Sorting types constants
 	const UDG_SORT_TYPE = 1;
 	const UDG_SORT_NAME = 2;
@@ -33,7 +30,8 @@ class UserDataGenerator
 	private $scorecache;
 	private $avgcache;
 
-    function UserDataGenerator($userid, $evals = array(), $links = array()) {
+	public function UserDataGenerator($userid, $evals = array(), $links = array())
+	{
 		$this->userid = $userid;
 		$evals_filtered = array();
 		foreach ($evals as $eval) {
@@ -61,12 +59,13 @@ class UserDataGenerator
 		$this->categorycache = array();
 		$this->scorecache = null;
 		$this->avgcache = null;
-    }
+	}
 
 	/**
 	 * Get total number of items (rows)
 	 */
-	public function get_total_items_count() {
+	public function get_total_items_count()
+	{
 		return count($this->items);
 	}
 
@@ -81,7 +80,8 @@ class UserDataGenerator
 	 * 5: student's score
 	 * 6: student's score as custom display (only if custom scoring enabled)
 	 */
-	public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) {
+	public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false)
+	{
 		// do some checks on count, redefine if invalid value
 		if (!isset($count)) {
 			$count = count ($this->items) - $start;
@@ -102,22 +102,22 @@ class UserDataGenerator
 			usort($allitems, array('UserDataGenerator', 'sort_by_category'));
 		} elseif ($sorting & self :: UDG_SORT_AVERAGE) {
 			// if user sorts on average scores, first calculate them and cache them
-			foreach ($allitems as $item) {                
-				$this->avgcache[$item->get_item_type() . $item->get_id()]= $item->calc_score();                
+			foreach ($allitems as $item) {
+				$this->avgcache[$item->get_item_type() . $item->get_id()]= $item->calc_score();
 			}
 			usort($allitems, array('UserDataGenerator', 'sort_by_average'));
 		} elseif ($sorting & self :: UDG_SORT_SCORE) {
 			// if user sorts on student's scores, first calculate them and cache them
 			foreach ($allitems as $item) {
 				$this->scorecache[$item->get_item_type() . $item->get_id()]
-								= $item->calc_score($this->userid);
+					= $item->calc_score($this->userid);
 			}
 			usort($allitems, array('UserDataGenerator', 'sort_by_score'));
 		} elseif ($sorting & self :: UDG_SORT_MASK) {
 			// if user sorts on student's masks, first calculate scores and cache them
 			foreach ($allitems as $item) {
 				$this->scorecache[$item->get_item_type() . $item->get_id()]
-								= $item->calc_score($this->userid);
+					= $item->calc_score($this->userid);
 			}
 			usort($allitems, array('UserDataGenerator', 'sort_by_mask'));
 		}
@@ -132,7 +132,7 @@ class UserDataGenerator
 		if (!isset ($this->scorecache)) {
 			foreach ($visibleitems as $item) {
 				$this->scorecache[$item->get_item_type() . $item->get_id()]
-								= $item->calc_score($this->userid);
+					= $item->calc_score($this->userid);
 			}
 
 		}
@@ -154,10 +154,11 @@ class UserDataGenerator
 		return $data;
 	}
 
-    // Sort functions
-    // Make sure to only use functions as defined in the GradebookItem interface !
+	// Sort functions
+	// Make sure to only use functions as defined in the GradebookItem interface !
 
-	function sort_by_type($item1, $item2) {
+	function sort_by_type($item1, $item2)
+	{
 		if ($item1->get_item_type() == $item2->get_item_type()) {
 			return $this->sort_by_name($item1,$item2);
 		} else {
@@ -165,13 +166,15 @@ class UserDataGenerator
 		}
 	}
 
-	function sort_by_course($item1, $item2) {
+	function sort_by_course($item1, $item2)
+	{
 		$name1 = api_strtolower($this->get_course_name_from_code_cached($item1->get_course_code()));
 		$name2 = api_strtolower($this->get_course_name_from_code_cached($item2->get_course_code()));
 		return api_strnatcmp($name1, $name2);
 	}
 
-	function sort_by_category($item1, $item2) {
+	function sort_by_category($item1, $item2)
+	{
 		$cat1 = $this->get_category_cached($item1->get_category_id());
 		$cat2 = $this->get_category_cached($item2->get_category_id());
 		$name1 = api_strtolower($this->get_category_name_to_display($cat1));
@@ -179,31 +182,34 @@ class UserDataGenerator
 		return api_strnatcmp($name1, $name2);
 	}
 
-
-	function sort_by_name($item1, $item2) {
+	function sort_by_name($item1, $item2)
+	{
 		return api_strnatcmp($item1->get_name(),$item2->get_name());
 	}
 
-
-	function sort_by_average($item1, $item2) {
+	function sort_by_average($item1, $item2)
+	{
 		$score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()];
 		$score2 = $this->avgcache[$item2->get_item_type() . $item2->get_id()];
 		return $this->compare_scores($score1, $score2);
 	}
 
-	function sort_by_score($item1, $item2) {
+	function sort_by_score($item1, $item2)
+	{
 		$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()];
 		$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()];
 		return $this->compare_scores($score1, $score2);
 	}
 
-	function sort_by_mask($item1, $item2) {
+	function sort_by_mask($item1, $item2)
+	{
 		$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()];
 		$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()];
 		return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2);
 	}
 
-	function compare_scores ($score1, $score2) {
+	function compare_scores ($score1, $score2)
+	{
 		if (!isset($score1)) {
 			return (isset($score2) ? 1 : 0);
 		} elseif (!isset($score2)) {
@@ -213,28 +219,28 @@ class UserDataGenerator
 		} else {
 			return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1);
 		}
-
 	}
 
-// Other functions
-	private function build_course_name ($item) {
+	private function build_course_name ($item)
+	{
 		return $this->get_course_name_from_code_cached($item->get_course_code());
 	}
 
-	private function build_category_name ($item) {
+	private function build_category_name ($item)
+	{
 		$cat = $this->get_category_cached($item->get_category_id());
-       
+
 		return $this->get_category_name_to_display($cat);
 	}
 
-
-	private function build_average_column ($item, $ignore_score_color) {		
+	private function build_average_column ($item, $ignore_score_color)
+	{
 		if (isset($this->avgcache)) {
-			$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()];            
+			$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()];
 		} else {
 			$avgscore = $item->calc_score();
-		}		
-        
+		}
+
 		$scoredisplay = ScoreDisplay :: instance();
 		$displaytype = SCORE_AVERAGE;
 		/*if ($ignore_score_color)
@@ -243,8 +249,9 @@ class UserDataGenerator
 		return $scoredisplay->display_score($avgscore, $displaytype);
 	}
 
-	private function build_result_column ($item, $ignore_score_color) {
-		$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()];		
+	private function build_result_column ($item, $ignore_score_color)
+	{
+		$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()];
 		$scoredisplay = ScoreDisplay :: instance();
 		$displaytype = SCORE_DIV_PERCENT;
 		if ($ignore_score_color) {
@@ -253,7 +260,8 @@ class UserDataGenerator
 		return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT);
 	}
 
-	private function build_mask_column ($item, $ignore_score_color) {
+	private function build_mask_column($item, $ignore_score_color)
+	{
 		$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()];
 		$scoredisplay = ScoreDisplay :: instance();
 		$displaytype = SCORE_DIV_PERCENT;
@@ -266,9 +274,9 @@ class UserDataGenerator
 
 	private function get_course_name_from_code_cached ($coursecode) {
 		if (isset ($this->coursecodecache)
-		 && isset ($this->coursecodecache[$coursecode])) {
-		 	return $this->coursecodecache[$coursecode];
-		 } else {
+			&& isset ($this->coursecodecache[$coursecode])) {
+			return $this->coursecodecache[$coursecode];
+		} else {
 			$name = get_course_name_from_code($coursecode);
 			$this->coursecodecache[$coursecode] = $name;
 			return $name;
@@ -277,9 +285,9 @@ class UserDataGenerator
 
 	private function get_category_cached ($category_id) {
 		if (isset ($this->categorycache)
-		 && isset ($this->categorycache[$category_id])) {
-		 	return $this->categorycache[$category_id];
-		 }else {
+			&& isset ($this->categorycache[$category_id])) {
+			return $this->categorycache[$category_id];
+		}else {
 			$cat = Category::load($category_id);
 			if (isset($cat)){
 				$this->categorycache[$category_id] = $cat[0];
@@ -290,14 +298,14 @@ class UserDataGenerator
 	}
 
 	private function get_category_name_to_display ($cat) {
-		if (isset($cat)) {            
-            if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){
-                return '';
-            } else {
-                return $cat->get_name();
-            }
-        } else {
-            return '';
-        }
+		if (isset($cat)) {
+			if ($cat->get_parent_id() == '0' || $cat->get_parent_id() == null){
+				return '';
+			} else {
+				return $cat->get_name();
+			}
+		} else {
+			return '';
+		}
 	}
 }