Эх сурвалжийг харах

Issue #306 - Training reporting: Enabling showing the access-chart and other minor corrections.

Ivan Tcholakov 15 жил өмнө
parent
commit
cfdcb5a60b

+ 7 - 1
archive/.htaccess

@@ -1,2 +1,8 @@
 order deny,allow
-deny from all
+deny from all
+
+# pChart generated files should be allowed
+<FilesMatch "^[0-9a-f]+$">
+	order allow,deny
+	allow from all
+</FilesMatch>

+ 16 - 15
main/mySpace/access_details.php

@@ -106,7 +106,7 @@ if (api_is_xml_http_request()) {
 		$DataSet->AddAllSeries();  
 		$DataSet->RemoveSerie('Date');  
 		$DataSet->SetAbsciseLabelSerie('Date');
-		$DataSet->SetYAxisName(get_lang('Minutes'));
+		$DataSet->SetYAxisName(get_lang('Minutes', ''));
 		$graph_id = api_get_user_id().'AccessDetails'.api_get_course_id();
 		$DataSet->AddAllSeries();
 
@@ -155,7 +155,7 @@ if (api_is_xml_http_request()) {
 			$Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
 
 			$Test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
-			$Test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);
+			$Test->drawTitle(60, 22, get_lang('AccessDetails', ''), 50, 50, 50, 585);
 
 			//------------------
 			//echo 'not in cache';
@@ -163,7 +163,7 @@ if (api_is_xml_http_request()) {
 			ob_start();
 			$Test->Stroke();
 			ob_end_clean();
-			$img_file = $Cache->GetHash($graph_id,$DataSet->GetData());
+			$img_file = $Cache->GetHash($graph_id, $DataSet->GetData());
 		}
 		echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
 	} else {
@@ -271,20 +271,21 @@ function get_connections_to_course($user_id, $course_code) {
     $rs = Database::query($sql, __FILE__, __LINE__);
     $connections = array();
 
-    while ($a_connections = Database::fetch_array($rs)) {
+    while ($row = Database::fetch_array($rs)) {
 
-        $s_login_date = $a_connections['login_course_date'];
-        $s_logout_date = $a_connections['logout_course_date'];
+        $login_date = $row['login_course_date'];
+        $logout_date = $row['logout_course_date'];
 
-        $i_timestamp_login_date = strtotime($s_login_date);
-        $i_timestamp_logout_date = strtotime($s_logout_date);
+        $timestamp_login_date = strtotime($login_date);
+        $timestamp_logout_date = strtotime($logout_date);
 
-        $connections[] = array('login' => $i_timestamp_login_date, 'logout' => $i_timestamp_logout_date);
+        $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
     }
     return $connections;
 }
 
 /**
+ * TODO: Not used, to b deleted?
  * Enter description here...
  *
  * @param unknown_type $user_id
@@ -311,12 +312,12 @@ function get_connections_to_course_by_time($user_id, $course_code, $year = '', $
 
     $rs = Database::query($sql, __FILE__, __LINE__);
     $connections = array();
-    while ($a_connections = Database::fetch_array($rs)) {
-        $s_login_date 				= $a_connections['login_course_date'];
-        $s_logout_date 				= $a_connections['logout_course_date'];
-        $i_timestamp_login_date 	= strtotime($s_login_date);
-        $i_timestamp_logout_date 	= strtotime($s_logout_date);
-        $connections[] = array('login' => $i_timestamp_login_date, 'logout' => $i_timestamp_logout_date);
+    while ($row = Database::fetch_array($rs)) {
+        $login_date 				= $row['login_course_date'];
+        $logout_date 				= $row['logout_course_date'];
+        $timestamp_login_date 	= strtotime($login_date);
+        $timestamp_logout_date 	= strtotime($logout_date);
+        $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
     }
     return $connections;
 }

+ 43 - 0
main/mySpace/myspace.lib.php

@@ -0,0 +1,43 @@
+<?php
+
+/* For licensing terms, see /dokeos_license.txt */
+
+/**
+ * This function serves exporting data in CSV format.
+ * @param array $header			The header labels.
+ * @param array $data			The data array.
+ * @param string $file_name		The name of the file which contains exported data.
+ * @return mixed				Returns a message (string) if an error occurred.
+ */
+function export_csv($header, $data, $file_name = 'export.csv') {
+
+	$archive_path = api_get_path(SYS_ARCHIVE_PATH);
+	$archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
+
+	if (!$open = fopen($archive_path.$file_name, 'w+')) {
+		$message = get_lang('noOpen');
+	} else {
+		$info = '';
+
+		foreach ($header as $value) {
+			$info .= $value.';';
+		}
+		$info .= "\r\n";
+
+		foreach ($data as $row) {
+			foreach ($row as $value) {
+				$info .= $value.';';
+			}
+			$info .= "\r\n";
+		}
+
+		fwrite($open, $info);
+		fclose($open);
+		$perm = api_get_setting('permissions_for_new_files');
+		$perm = octdec(!empty($perm) ? $perm : '0660');
+		@chmod($file_name, $perm);
+
+		header("Location:".$archive_url.$file_name);
+	}
+	return $message;
+}