Browse Source

first working reports - need code cleaning

Arnaud Ligot 14 years ago
parent
commit
60d713f18e
2 changed files with 103 additions and 5 deletions
  1. 21 5
      main/reports/index.php
  2. 82 0
      main/reports/reports.php

+ 21 - 5
main/reports/index.php

@@ -28,7 +28,7 @@ $this_section = SECTION_REPORTS;
 $tool_name=get_lang('Reports');
 
 // Displaying the header
-foreach (array('jquery-1.4.2.min.js','jquery-ui-1.8.5.custom.min.js', 'jquery.ba-bbq.min.js', 'jquery.validate.js', 'jquery.form.js', 'jquery.form.wizard.js') as $js)
+foreach (array('jquery.js','jquery-ui-1.8.5.custom.min.js', 'jquery.ba-bbq.min.js', 'jquery.validate.js', 'jquery.form.js', 'jquery.form.wizard.js') as $js)
 	$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/'.$js.'" type="text/javascript" language="javascript"></script>'."\n";
 
 
@@ -107,6 +107,7 @@ Display::display_header($tool_name);
 ?>
 		<div id="reportsBuilderWizard">
 			<h3>Reports Builder</h3>
+			<div id='wizardContent'>
 			<p>Please fill the following from to build your report.
 			<hr />
 			<h5 id="status"></h5>
@@ -155,6 +156,7 @@ Display::display_header($tool_name);
 					<select name="format" id="format">
 						<option value="html">html</option>
 						<option value="csv">csv</option>
+						<option value="sql">sql</option>
 					</select><br />
 				</span>
 				</div>
@@ -164,22 +166,36 @@ Display::display_header($tool_name);
 				</div>
 			</form>
 			<hr />
-			
+			</div>
+			<div id="wizardShowButton">
+				Show Wizard
+			</div>		
 			<p id="data"></p>
 
 		</div>
 
+
+		<div id="result">
+		</div>
     <script type="text/javascript">
 			$(function(){
+				$("#wizardShowButton").hide();
+				$("#wizardShowButton").click(function() {
+					$("#wizardContent").show();
+					$("#wizardShowButton").hide();
+				});
 				$("#reportsBuilderWizardForm").formwizard({ 
 				 	formPluginEnabled: true,
 				 	validationEnabled: true,
 				 	focusFirstInput : true,
 				 	formOptions :{
-						success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })},
+						success: function(data){
+		                                        $("#wizardContent").hide();
+                		                        $("#wizardShowButton").show();
+							$("#result").html(data); 
+						},
 						beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
-						dataType: 'json',
-						resetForm: true
+						resetForm: false
 				 	}	
 				 }
 				);

+ 82 - 0
main/reports/reports.php

@@ -0,0 +1,82 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+* Reports
+* @author Arnaud Ligot <arnaud@cblue.be>
+* @copyrights CBLUE SPRL 2011
+* @package chamilo.reports
+*/
+
+// name of the language file that needs to be included
+$language_file = array ('index', 'tracking', 'userInfo', 'admin', 'gradebook'); // FIXME
+$cidReset = true;
+
+// including files 
+require_once '../inc/global.inc.php';
+require_once 'reports.lib.php';
+
+// protect script
+api_block_anonymous_users();
+
+// defining constants
+
+// current section
+$this_section = SECTION_REPORTS;
+
+// setting the name of the tool
+$tool_name=get_lang('Reports');
+
+if ($_REQUEST['format'] == 'csv')  {
+	// converting post vars to get uri
+	$params = '';
+	$kv = array();
+	foreach ($_POST as $key => $value)
+		if ($key != 'format')
+			$kv[] = $key.'='.urlencode($value);
+	$query_string = join("&", $kv);
+	echo '<a href="reports.php?format=downloadcsv&'.$query_string.'">download file</a>';
+} else if ($_REQUEST['format'] == 'downloadcsv') {
+	header('content-type: application/csv'); // fixme
+	$_REQUEST['format'] = 'csv';
+}
+
+if ($_REQUEST['type'] == "exercicesMultiCourses") {
+	// foreach quiz
+	$result = array();
+	// fixme database name
+	$columns = Database::query('select r.id as kid, c.title as course, r.child_name as test from reports_keys r, course c where r.course_id=c.id order by r.course_id, r.child_name');
+	if (Database::num_rows($columns) == 0)
+		die('<b>'.get_lang('no data found').'</b>');
+	$query = 'select u.user_id, u.lastname, u.firstname ';
+	$columns = Database::store_result($columns);
+	foreach ($columns as $key => $column)
+		$query .= ', avg(k'.$key.'.score) as `'.$column['course'].'-'.$column['test'].'` '; // FIXME function
+	$query .= ' from user u ';
+	foreach ($columns as $key => $column) // fixme sessions
+		$query .= 'left outer join reports_values k'.$key.' on k'.$key.'.key_id = '.$column['kid'].' and k'.$key.'.uid = u.user_id ';
+	if ($_REQUEST['format'] == 'sql')
+		die($query);
+	$result = Database::query($query);
+} else {
+	die('<b>'.get_lang('error while building your report').'</b>');
+}
+
+if ($_REQUEST['format'] == 'html') {
+	echo '<table border="1">'; // FIXME style
+	while ($row = Database::fetch_row($result)) {
+		echo '<tr>';
+		foreach ($row as $col)
+			echo '<td>'.$col.'</td>'; 
+		echo '</tr>';
+	}
+	echo '</table>';
+} else if ($_REQUEST['format'] == 'csv') {
+	while ($row = Database::fetch_row($result)) {
+		foreach ($row as $col)
+			echo $col.',';  // fixme
+		echo "\n";
+	}
+} else die('format unknown');
+
+?>