Adding graph for document quota see #4483

skala
Julio Montoya 12 years ago
parent 72af54a796
commit f7297dcfca
  1. 209
      main/document/document.php
  2. 77
      main/document/document_quota.php
  3. 2
      main/document/upload.php
  4. 47
      main/inc/lib/document.lib.php
  5. 4
      main/inc/lib/sessionmanager.lib.php

@ -73,6 +73,7 @@ $course_dir = $course_info['path'] . '/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path . $course_dir;
$http_www = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document';
$dbl_click_id = 0; // Used for avoiding double-click
$selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
@ -96,9 +97,7 @@ if (api_get_session_id() != 0) {
//Setting group variables
if (api_get_group_id()) {
// Needed for group related stuff
require_once $lib_path . 'groupmanager.lib.php';
if (api_get_group_id()) {
// Get group info
$group_properties = GroupManager::get_group_properties(api_get_group_id());
$noPHP_SELF = true;
@ -143,7 +142,6 @@ if (api_get_group_id()) {
//Actions
$document_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$message = '';
@ -355,8 +353,7 @@ if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $
api_not_allowed(true);
}
$htmlHeadXtra[] =
"<script type=\"text/javascript\">
$htmlHeadXtra[] ="<script type=\"text/javascript\">
function confirmation (name) {
if (confirm(\" " . get_lang("AreYouSureToDelete") . " \"+ name + \" ?\"))
{return true;}
@ -908,6 +905,101 @@ if ($is_certificate_mode && $curdirpath != '/certificates') {
<?php Display::display_icon('folder_up.png', get_lang('Up'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
$column_show = array();
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
// TODO:check enable more options for shared folders
/* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
// Create new document
if (!$is_certificate_mode) {
?>
<a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
// Create new draw
if (api_get_setting('enabled_support_svg') == 'true') {
if (api_browser_support('svg')) {
?>
<a href="create_draw.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM); ?></a>&nbsp;
<?php
} else {
Display::display_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
}
}
// Create new paint
if (api_get_setting('enabled_support_pixlr') == 'true') {
?>
<a href="create_paint.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record an image clip from my webcam
if (api_get_setting('enable_webcam_clip') == 'true') {
?>
<a href="webcam_clip.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
<?php Display::display_icon('webcam.png', get_lang('WebCamClip'),'',ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record audio (nanogong)
if (api_get_setting('enable_nanogong') == 'true') {
?>
<a href="record_audio.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record audio (wami record)
if (api_get_setting('enable_wami_record') == 'true') {
?>
<a href="record_audio_wami.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Create new audio from text
if (api_get_setting('enabled_text2audio') == 'true') {
$dt2a = 'google';
$req_dt2a = '&amp;dt2a=' . $dt2a;
?>
<a href="create_audio.php?<?php echo api_get_cidreq(); ?>&amp;id=<?php echo $document_id . $req_gid . $req_dt2a; ?>">
<?php Display::display_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
}
// Create new certificate
if ($is_certificate_mode) {
?>
<a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>&certificate=true&selectcat=<?php echo $selectcat; ?>">
<?php Display::display_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// File upload link
if ($is_certificate_mode) {
echo '<a href="upload.php?' . api_get_cidreq() . '&id=' . $current_folder_id . $req_gid . '">';
echo Display::display_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM) . '</a>';
} else {
echo '<a href="upload.php?' . api_get_cidreq() . '&id=' . $current_folder_id . $req_gid . '">';
echo Display::display_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM) . '</a>';
}
// Create directory
if (!$is_certificate_mode) {
?>
<a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>&createdir=1">
<?php Display::display_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
}
$table_footer = '';
$total_size = 0;
@ -1025,99 +1117,6 @@ if (isset($docs_and_folders) && is_array($docs_and_folders)) {
$table_footer = get_lang('NoDocsInFolder');
}
$column_show = array();
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
// TODO:check enable more options for shared folders
/* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
// Create new document
if (!$is_certificate_mode) {
?>
<a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_document.png', get_lang('CreateDoc'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
// Create new draw
if (api_get_setting('enabled_support_svg') == 'true') {
if (api_browser_support('svg')) {
?>
<a href="create_draw.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_draw.png', get_lang('Draw'), '', ICON_SIZE_MEDIUM); ?></a>&nbsp;
<?php
} else {
Display::display_icon('new_draw_na.png', get_lang('BrowserDontSupportsSVG'), '', ICON_SIZE_MEDIUM);
}
}
// Create new paint
if (api_get_setting('enabled_support_pixlr') == 'true') {
?>
<a href="create_paint.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_paint.png', get_lang('PhotoRetouching'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record an image clip from my webcam
if (api_get_setting('enable_webcam_clip') == 'true') {
?>
<a href="webcam_clip.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id.$req_gid; ?>">
<?php Display::display_icon('webcam.png', get_lang('WebCamClip'),'',ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record audio (nanogong)
if (api_get_setting('enable_nanogong') == 'true') {
?>
<a href="record_audio.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Record audio (wami record)
if (api_get_setting('enable_wami_record') == 'true') {
?>
<a href="record_audio_wami.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>">
<?php Display::display_icon('new_recording.png', get_lang('RecordMyVoice'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// Create new audio from text
if (api_get_setting('enabled_text2audio') == 'true') {
$dt2a = 'google';
$req_dt2a = '&amp;dt2a=' . $dt2a;
?>
<a href="create_audio.php?<?php echo api_get_cidreq(); ?>&amp;id=<?php echo $document_id . $req_gid . $req_dt2a; ?>">
<?php Display::display_icon('new_sound.png', get_lang('CreateAudio'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
}
// Create new certificate
if ($is_certificate_mode) {
?>
<a href="create_document.php?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>&certificate=true&selectcat=<?php echo $selectcat; ?>">
<?php Display::display_icon('new_certificate.png', get_lang('CreateCertificate'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
// File upload link
if ($is_certificate_mode) {
echo '<a href="upload.php?' . api_get_cidreq() . '&id=' . $current_folder_id . $req_gid . '">';
echo Display::display_icon('upload_certificate.png', get_lang('UploadCertificate'), '', ICON_SIZE_MEDIUM) . '</a>';
} else {
echo '<a href="upload.php?' . api_get_cidreq() . '&id=' . $current_folder_id . $req_gid . '">';
echo Display::display_icon('upload_file.png', get_lang('UplUploadDocument'), '', ICON_SIZE_MEDIUM) . '</a>';
}
// Create directory
if (!$is_certificate_mode) {
?>
<a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&id=<?php echo $document_id . $req_gid; ?>&createdir=1">
<?php Display::display_icon('new_folder.png', get_lang('CreateDir'), '', ICON_SIZE_MEDIUM); ?></a>
<?php
}
}
if (!is_null($docs_and_folders)) {
// Show download zipped folder icon
@ -1136,6 +1135,9 @@ require 'document_slideshow.inc.php';
if ($image_present && !isset($_GET['keyword'])) {
echo '<a href="slideshow.php?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpathurl . '">' . Display::return_icon('slideshow.png', get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM) . '</a>';
}
echo '<a href="document_quota.php?' . api_get_cidreq() . '">' . Display::return_icon('percentage.png', get_lang('DocumentQuota'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '</div>'; //end actions
@ -1230,16 +1232,15 @@ if (count($docs_and_folders) > 1) {
$course_quota = DocumentManager::get_course_quota();
// Calculating the total space
$already_consumed_space = DocumentManager::documents_total_space($_course);
$already_consumed_space_course = DocumentManager::documents_total_space(api_get_course_int_id());
// Displaying the quota
DocumentManager::display_simple_quota($course_quota, $already_consumed_space);
DocumentManager::display_simple_quota($course_quota, $already_consumed_space_course);
}
}
if (!empty($table_footer)) {
Display::display_warning_message($table_footer);
}
// Footer
Display::display_footer();
Display::display_footer();

@ -0,0 +1,77 @@
<?php
$language_file = array('document');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_DOCUMENT;
$this_section = SECTION_COURSES;
$tool_name = get_lang('DocumentQuota');
$interbreadcrumb[] = array('url' => 'document.php', 'name' => get_lang('Documents'));
$htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.min.js');
$htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.pieRenderer.min.js');
$htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.min.js');
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.min.css');
$course_id = api_get_course_id();
$session_id = api_get_session_id();
$session = array();
$session_list = SessionManager::get_session_by_course($course_id);
$total_quota = DocumentManager::get_course_quota();
$only_base_quota = DocumentManager::documents_total_space(api_get_course_int_id(), 0, 0);
$course_quota = round($only_base_quota/$total_quota, 2)*100;
$session[] = array(get_lang('Course'), $course_quota);
$used_quota = $course_quota;
if (!empty($session_list)) {
foreach ($session_list as $session_data) {
$quota = intval(DocumentManager::documents_total_space(api_get_course_int_id(), null, $session_data['id']));
if (!empty($quota)) {
$quota = round($quota/$total_quota, 2)*100;
}
if ($session_id == $session_data['id']) {
$session_data['name'] = $session_data['name'] . ' * ';
}
$used_quota += $quota;
$session[] = array(addslashes($session_data['name']), $quota);
}
}
$session[] = array(addslashes(get_lang('ShowCourseQuotaUse')), 100 - $used_quota);
$quota_data = json_encode($session);
$htmlHeadXtra[] = "
<script>
$(document).ready(function(){
var data = ".$quota_data.";
var plot1 = jQuery.jqplot ('chart1', [data], {
seriesDefaults: {
// Make this a pie chart
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
}
);
});
</script>";
$tpl = new Template($tool_name);
$content = Display::page_subheader(get_lang('ShowCourseQuotaUse')).'<div id="chart1"></div>';
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -227,7 +227,7 @@ $action = Uri::here($params, false);
$form = new FormValidator('upload', 'POST', $action, '', 'enctype="multipart/form-data"');
$form->addElement('hidden', 'id', $document_id);
$form->addElement('hidden', 'curdirpath', $path);
$label = get_lang('MaxFileSize').': '.ini_get('upload_max_filesize').'<br/>'.get_lang('DocumentQuota').': '.(round(DocumentManager::get_course_quota()/1000000)-round(DocumentManager::documents_total_space($_course)/1000000)).'M';
$label = get_lang('MaxFileSize').': '.ini_get('upload_max_filesize').'<br/>'.get_lang('DocumentQuota').': '.(round(DocumentManager::get_course_quota()/1000000)-round(DocumentManager::documents_total_space()/1000000)).'M';
$form->addElement('file', 'file', array(get_lang('File'), $label), 'id="user_upload" size="45"');

@ -2331,19 +2331,42 @@ class DocumentManager {
* @param int $to_group_id (to calculate group document space)
* @return int total size
*/
static function documents_total_space($to_group_id = '0') {
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
static function documents_total_space($course_id = null, $group_id = null, $session_id = null) {
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
if (isset($course_id)) {
$course_id = intval($course_id);
} else {
$course_id = api_get_course_int_id();
}
$group_condition = null;
if (isset($group_id)) {
if (!empty($group_id)) {
$group_id = intval($group_id);
$group_condition = " AND props.to_group_id='".$group_id."' ";
}
}
$session_condition = null;
if (isset($session_id)) {
$session_id = intval($session_id);
$session_condition = " AND props.id_session='".$session_id."' ";
}
$sql = "SELECT SUM(size) FROM ".$TABLE_ITEMPROPERTY." AS props, ".$TABLE_DOCUMENT." AS docs
WHERE props.c_id = $course_id AND
docs.c_id = $course_id AND
docs.id = props.ref AND
props.tool = '".TOOL_DOCUMENT."' AND
props.to_group_id='".$to_group_id."' AND
props.visibility <> 2";
props.visibility <> 2
$group_condition
$session_condition
";
$result = Database::query($sql);
if ($result && Database::num_rows($result) != 0) {
@ -2365,9 +2388,7 @@ class DocumentManager {
$message = get_lang('MaximumAllowedQuota') . ' <strong>'.$course_quota_m.' megabyte</strong>.<br />';
$message .= get_lang('CourseCurrentlyUses') . ' <strong>' . $already_consumed_space_m . ' megabyte</strong>.<br />';
$percentage = $already_consumed_space / $course_quota * 100;
$percentage = round($percentage, 1);
$percentage = round( ($already_consumed_space / $course_quota * 100), 1);
$other_percentage = $percentage < 100 ? 100 - $percentage : 0;
@ -2450,7 +2471,7 @@ class DocumentManager {
*/
static function generate_jplayer_jquery($params = array()) {
$js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$js_path = api_get_path(WEB_LIBRARY_PATH).'javascript/';
$jplayer_definition = ' $("#jquery_jplayer_' . $params['count'] . '").jPlayer({
ready: function() {
@ -2875,7 +2896,7 @@ class DocumentManager {
return $return;
}
public function check_visibility_tree($doc_id, $course_code, $session_id, $user_id) {
public static function check_visibility_tree($doc_id, $course_code, $session_id, $user_id) {
$document_data = self::get_document_data_by_id($doc_id, $course_code);
if (!empty($document_data)) {

@ -1785,8 +1785,8 @@ class SessionManager {
}
}
}
function get_session_by_course($course_code) {
static function get_session_by_course($course_code) {
$table_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$table_session = Database::get_main_table(TABLE_MAIN_SESSION);
$course_code = Database::escape_string($course_code);

Loading…
Cancel
Save