From 97540137c5719f3a10f31943e2c406cb9559f5f3 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 17 Mar 2008 23:44:52 +0100 Subject: [PATCH] =?UTF-8?q?[svn=20r14637]=20Use=20=E2=80=9CToday=E2=80=9D,?= =?UTF-8?q?=20=E2=80=9CYesterday=E2=80=9D=20and=20=E2=80=9CTwo=20days=20ag?= =?UTF-8?q?o=E2=80=9D=20to=20specify=20the=20date=20for=20recent=20files.?= =?UTF-8?q?=20(See=20FS#2349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/css/academica/default.css | 7 ++ main/css/baby/default.css | 7 ++ main/css/corporativa/default.css | 7 ++ main/css/default/default.css | 6 +- main/css/default_with_tabs/default.css | 6 +- main/css/dokeosgrey/default.css | 7 +- main/dropbox/dropbox_functions.inc.php | 9 +- main/dropbox/index.php | 145 +++++++++++++++++-------- main/inc/lib/display.lib.php | 62 ++++++++++- main/inc/lib/sortabletable.class.php | 69 +++++++++++- main/inc/lib/tablesort.lib.php | 126 ++++++++++++++++++--- main/inc/lib/text.lib.php | 134 ++++++++++++++++++++++- 12 files changed, 508 insertions(+), 77 deletions(-) diff --git a/main/css/academica/default.css b/main/css/academica/default.css index cc9ef8ec1f..7050b1597f 100644 --- a/main/css/academica/default.css +++ b/main/css/academica/default.css @@ -1366,6 +1366,13 @@ a.specialLink:hover,a.specialLink:focus { margin: 0 .8em; } +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; +} + + /* ============================================================================== SYSTEM ANNOUNCEMENTS diff --git a/main/css/baby/default.css b/main/css/baby/default.css index 7f4c7d3bda..4fbef38553 100644 --- a/main/css/baby/default.css +++ b/main/css/baby/default.css @@ -1306,6 +1306,13 @@ th span { margin: 0 .8em; } +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; +} + + /* ============================================================================== SYSTEM ANNOUNCEMENTS diff --git a/main/css/corporativa/default.css b/main/css/corporativa/default.css index 69f5c14c74..127c6e3530 100644 --- a/main/css/corporativa/default.css +++ b/main/css/corporativa/default.css @@ -1269,6 +1269,13 @@ a.specialLink:hover,a.specialLink:focus { margin: 0 .8em; } +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; +} + + /* ============================================================================== SYSTEM ANNOUNCEMENTS diff --git a/main/css/default/default.css b/main/css/default/default.css index 2776c6d976..76223e230c 100644 --- a/main/css/default/default.css +++ b/main/css/default/default.css @@ -1045,8 +1045,10 @@ dl.upload_option { font-style: italic } -.dropbox_person { - font-weight: bold +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; } .dropbox_listTitle { diff --git a/main/css/default_with_tabs/default.css b/main/css/default_with_tabs/default.css index 87f348035f..6d1d54b942 100644 --- a/main/css/default_with_tabs/default.css +++ b/main/css/default_with_tabs/default.css @@ -746,7 +746,11 @@ dl.upload_option {margin: 1em 0; padding: 0;} **********************************************/ /* styles from dropbox.php file */ .dropbox_detail {font-size: small} -.dropbox_date {font-style: italic} +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; +} .dropbox_person {font-weight: bold} .dropbox_listTitle { color: #000000;} .dropbox_feedback {font-size: x-small; height: 50px; width: 200px; overflow: auto} diff --git a/main/css/dokeosgrey/default.css b/main/css/dokeosgrey/default.css index 88052f067f..2393ff19d7 100644 --- a/main/css/dokeosgrey/default.css +++ b/main/css/dokeosgrey/default.css @@ -721,7 +721,12 @@ dl.upload_option {margin: 1em 0; padding: 0;} **********************************************/ /* styles from dropbox.php file */ .dropbox_detail {font-size: small} -.dropbox_date {font-style: italic} +.dropbox_date { + color: #737780; + font-style: italic ; + font-weight: normal; +} + .dropbox_person {font-weight: bold} .dropbox_listTitle { color: #000000;} .dropbox_feedback {font-size: x-small; height: 50px; width: 200px; overflow: auto} diff --git a/main/dropbox/dropbox_functions.inc.php b/main/dropbox/dropbox_functions.inc.php index 2e594f14a2..7ec58503f4 100644 --- a/main/dropbox/dropbox_functions.inc.php +++ b/main/dropbox/dropbox_functions.inc.php @@ -3,7 +3,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2006 Dokeos S.A. + Copyright (c) 2006-2008 Dokeos S.A. Copyright (c) 2006 Ghent University (UGent) Copyright (c) various contributors @@ -1047,10 +1047,9 @@ function feedback($array) */ function format_feedback($feedback) { - - $output.=''.get_lang('Date').': '.$feedback['feedback_date'].'
'; - $output.=''.get_lang('Author').': '.display_user_link($feedback['author_user_id']).'
'; - $output.=''.get_lang('Text').': '.nl2br($feedback['feedback']).'
'; + $output.=display_user_link($feedback['author_user_id']); + $output.='  ['.$feedback['feedback_date'].']
'; + $output.='
'.nl2br($feedback['feedback']).'


'; return $output; } diff --git a/main/dropbox/index.php b/main/dropbox/index.php index 8b98178e94..73421c4adb 100644 --- a/main/dropbox/index.php +++ b/main/dropbox/index.php @@ -3,7 +3,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2006 Dokeos S.A. + Copyright (c) 2006-2008 Dokeos S.A. Copyright (c) 2006 Ghent University (UGent) Copyright (c) various contributors @@ -160,6 +160,7 @@ if ($_GET['action']=="add") { display_add_form(); } + if ($_POST['submitWork']) { $check = Security::check_token(); @@ -251,7 +252,8 @@ if (isset($_GET['error']) AND !empty($_GET['error'])) - +if ($_GET['action']!="add") +{ // getting all the categories in the dropbox for the given user $dropbox_categories=get_dropbox_categories(); // creating the arrays with the categories for the received files and for the sent files @@ -290,7 +292,6 @@ if ($dropbox_cnf['sent_received_tabs']) RECEIVED FILES ----------------------------------------------------------- */ - if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_tabs']==false) { //echo '

'.get_lang('ReceivedFiles').'

'; @@ -305,13 +306,14 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t $view_dropbox_category_received=0; } + /* *** Menu Received *** */ if ($view_dropbox_category_received<>0) { echo get_lang('CurrentlySeeing').': '.$dropbox_categories[$view_dropbox_category_received]['cat_name'].'
'; echo ''.get_lang('up').''.get_lang('Root')."\n"; } - echo "\"".get_lang('NewFolder')."\" ".get_lang('AddNewCategory')."\n"; + echo ' '.get_lang('AddNewCategory').''; // object initialisation @@ -329,12 +331,38 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t $column_header[] = array('',false,''); $column_header[] = array(get_lang('Type'),true,'style="width:40px"'); $column_header[] = array(get_lang('ReceivedTitle'), TRUE, ''); - $column_header[] = array(get_lang('Authors'), TRUE, ''); - $column_header[] = array(get_lang('Description'), TRUE, ''); $column_header[] = array(get_lang('Size'), TRUE, ''); - $column_header[] = array(get_lang('LastResent'), TRUE, ''); + $column_header[] = array(get_lang('Authors'), TRUE, ''); + $column_header[] = array(get_lang('LastResent'), true); $column_header[] = array(get_lang('Modify'), FALSE, '', 'nowrap style="text-align: right"'); - + $column_header[] = array('RealDate', true); + + + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=0; + + // Here we change the way how the colums are going to be sort + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" + + $column_order[]=1; + $column_order[]=2; + $column_order[]=3; + $column_order[]=4; + $column_order[]=7; + $column_order[]=6; + $column_order[]=7; + $column_order[]=8; + + + // the content of the sortable table = the received files foreach ( $dropbox_person -> receivedWork as $dropbox_file) { @@ -342,6 +370,7 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t if ($view_dropbox_category_received==$dropbox_file->category) // we only display the files that are in the category that we are in. { $dropbox_file_data[]=$dropbox_file->id; + // new icon if ($dropbox_file->last_upload_date > $last_access AND !in_array($dropbox_file->id,$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) { @@ -352,11 +381,13 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t $new_icon=''; } $dropbox_file_data[]=build_document_icon_tag('file',$dropbox_file->title); - $dropbox_file_data[]=''.get_lang('Save').''.$dropbox_file->title.''.$new_icon; - $dropbox_file_data[]=$dropbox_file->author; - $dropbox_file_data[]=$dropbox_file->description; + $dropbox_file_data[]=''.get_lang('Save').''.$dropbox_file->title.''.$new_icon.'
'.$dropbox_file->description; $dropbox_file_data[]=ceil(($dropbox_file->filesize)/1024).' '.get_lang('kB'); - $dropbox_file_data[]=$dropbox_file->last_upload_date; + $dropbox_file_data[]=$dropbox_file->author; + //$dropbox_file_data[]=$dropbox_file->description; + + $dropbox_file_data[]=date_to_str_ago($dropbox_file->last_upload_date).'
'.$dropbox_file->last_upload_date.''; + $action_icons=check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' '.get_lang('Comment').' '.get_lang('Move').' @@ -364,18 +395,22 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t //$action_icons=' '.get_lang('Move').' // '.get_lang('Delete').''; // this is a hack to have an additional row in a sortable table + if($_GET['action']=='viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id==$_GET['id']) { $action_icons.="\n"; // ending the normal row of the sortable table - $action_icons.="\n\t".get_lang('CloseFeedback')."".feedback($dropbox_file->feedback2)."\n\n"; - + $action_icons.='".get_lang('CloseFeedback')."".feedback($dropbox_file->feedback2)."\n\n"; } $dropbox_file_data[]=$action_icons; $action_icons=''; - - $dropbox_data_recieved[]=$dropbox_file_data; + + $dropbox_file_data[]=$dropbox_file->last_upload_date;//date + + $dropbox_data_recieved[]=$dropbox_file_data; } } + + // the content of the sortable table = the categories (if we are not in the root) if ($view_dropbox_category_received==0) @@ -392,7 +427,6 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t $dropbox_category_data[]=''; $dropbox_category_data[]=''; $dropbox_category_data[]=''; - $dropbox_category_data[]=''; $dropbox_category_data[]=''.get_lang('Edit').' '.get_lang('Delete').''; } @@ -401,19 +435,14 @@ if (!$_GET['view'] OR $_GET['view']=='received' OR $dropbox_cnf['sent_received_t $dropbox_data_recieved[]=$dropbox_category_data; } } - } - + // Displaying the table - $additional_get_parameters=array('view'=>$_GET['view'], 'view_received_category'=>$_GET['view_received_category'],'view_sent_category'=>$_GET['view_sent_category']); - Display::display_sortable_table($column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters, array ('delete_received' => get_lang('Delete'),'download_received'=>get_lang('Download'))); - + $additional_get_parameters=array('view'=>$_GET['view'], 'view_received_category'=>$_GET['view_received_category'],'view_sent_category'=>$_GET['view_sent_category']); + Display::display_sortable_config_table($column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters,$column_show,$column_order, array ('delete_received' => get_lang('Delete'),'download_received'=>get_lang('Download'))); } - - - /* ----------------------------------------------------------- SENT FILES @@ -439,8 +468,8 @@ if ($_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs']==false) echo get_lang('CurrentlySeeing').': '.$dropbox_categories[$view_dropbox_category_sent]['cat_name'].'
'; echo ''.get_lang('Up').''.get_lang('Root')."\n"; } - echo "\"".get_lang('Upload')."\" ".get_lang('UploadNewFile')." \n"; - echo "\"".get_lang('NewFolder')."\" ".get_lang('AddNewCategory')."\n"; + echo " ".get_lang('UploadNewFile')." \n"; + echo " ".get_lang('AddNewCategory')."\n"; //echo '
'; @@ -454,39 +483,63 @@ if ($_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs']==false) $sorting_options = array(); $paging_options = array(); - // the headers of the sortable tables $column_header=array(); + $column_header[] = array('',false,''); $column_header[] = array(get_lang('Type'),true,'style="width:40px"','style="text-align:center"'); $column_header[] = array(get_lang('SentTitle'), TRUE, ''); - $column_header[] = array(get_lang('Authors'), TRUE, ''); - $column_header[] = array(get_lang('Description'), TRUE, ''); $column_header[] = array(get_lang('Size'), TRUE, ''); + $column_header[] = array(get_lang('SentTo'), TRUE, ''); $column_header[] = array(get_lang('LastResent'), TRUE, ''); - $column_header[] = array(get_lang('SentTo'), TRUE, ''); $column_header[] = array(get_lang('Modify'), FALSE, '', 'nowrap style="text-align: right"'); - + $column_header[] = array('RealDate', FALSE); + + $column_show=array(); + $column_order=array(); + + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=1; + $column_show[]=0; + + // Here we change the way how the colums are going to be sort + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" + + $column_order[]=1; + $column_order[]=2; + $column_order[]=3; + $column_order[]=4; + $column_order[]=7; + $column_order[]=6; + $column_order[]=7; + $column_order[]=8; + // the content of the sortable table = the received files foreach ( $dropbox_person -> sentWork as $dropbox_file) { - $dropbox_file_data=array(); if ($view_dropbox_category_sent==$dropbox_file->category) { $dropbox_file_data[]=$dropbox_file->id; $dropbox_file_data[]=build_document_icon_tag('file',$dropbox_file->title); - $dropbox_file_data[]=''.get_lang('Save').''.$dropbox_file->title.''; - $dropbox_file_data[]=$dropbox_file->author; - $dropbox_file_data[]=$dropbox_file->description; + $dropbox_file_data[]=''.get_lang('Save').''.$dropbox_file->title.'
'.$dropbox_file->description; $dropbox_file_data[]=ceil(($dropbox_file->filesize)/1024).' '.get_lang('kB'); - $dropbox_file_data[]=$dropbox_file->last_upload_date; foreach ($dropbox_file->recipients as $recipient) { $receivers_celldata=display_user_link($recipient['user_id'], $recipient['name']).', '.$receivers_celldata; } - $dropbox_file_data[]=$receivers_celldata; + $dropbox_file_data[]=$receivers_celldata; + $dropbox_file_data[]=date_to_str_ago($dropbox_file->last_upload_date).'
'.$dropbox_file->last_upload_date.''; + + //$dropbox_file_data[]=$dropbox_file->author; $receivers_celldata=''; $action_icons=check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' '.get_lang('Comment').' @@ -499,7 +552,8 @@ if ($_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs']==false) $action_icons.="\n\t".get_lang('CloseFeedback')."".feedback($dropbox_file->feedback2)."\n\n"; } - $dropbox_file_data[]=$action_icons; + $dropbox_file_data[]=$action_icons; + $dropbox_file_data[]=$dropbox_file->last_upload_date; $action_icons=''; $dropbox_data_sent[]=$dropbox_file_data; @@ -517,9 +571,9 @@ if ($_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs']==false) $dropbox_category_data[]=''; // this is where the checkbox icon for the files appear $dropbox_category_data[]=build_document_icon_tag('folder',$category['cat_name']); $dropbox_category_data[]=''.get_lang('Save').''.$category['cat_name'].''; + //$dropbox_category_data[]=''; $dropbox_category_data[]=''; - $dropbox_category_data[]=''; - $dropbox_category_data[]=''; + //$dropbox_category_data[]=''; $dropbox_category_data[]=''; $dropbox_category_data[]=''; $dropbox_category_data[]=''.get_lang('Edit').' @@ -530,16 +584,11 @@ if ($_GET['view']=='sent' OR $dropbox_cnf['sent_received_tabs']==false) $dropbox_data_sent[]=$dropbox_category_data; } } - } - // Displaying the table $additional_get_parameters=array('view'=>$_GET['view'], 'view_received_category'=>$_GET['view_received_category'],'view_sent_category'=>$_GET['view_sent_category']); - Display::display_sortable_table($column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, array ('delete_received' => get_lang('Delete'),'download_received'=>get_lang('Download'))); - + Display::display_sortable_config_table($column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters,$column_show,$column_order, array ('delete_received' => get_lang('Delete'),'download_received'=>get_lang('Download'))); +} } - - Display::display_footer(); - ?> \ No newline at end of file diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 948d86a765..490d48149e 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -4,7 +4,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2004-2005 Dokeos S.A. + Copyright (c) 2004-2008 Dokeos S.A. Copyright (c) Roan Embrechts, Vrije Universiteit Brussel Copyright (c) Wolfgang Schneider Copyright (c) Bert Vanderkimpen, Ghent University @@ -281,17 +281,75 @@ class Display { global $origin; $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0; $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20; + $table = new SortableTableFromArray($content, $column, $default_items_per_page); + if (is_array($query_vars)) { $table->set_additional_parameters($query_vars); } foreach ($header as $index => $header_item) - { + { $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]); } $table->set_form_actions($form_actions); $table->display(); } + + + /** + * Display a table with a special configuration + * @param array $header Titles for the table header + * each item in this array can contain 3 values + * - 1st element: the column title + * - 2nd element: true or false (column sortable?) + * - 3th element: additional attributes for + * th-tag (eg for column-width) + * - 4the element: additional attributes for the td-tags + * @param array $content 2D-array with the tables content + * @param array $sorting_options Keys are: + * 'column' = The column to use as sort-key + * 'direction' = SORT_ASC or SORT_DESC + * @param array $paging_options Keys are: + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * @param array $query_vars Additional variables to add in the query-string + * @param array $column_show Array of binaries 1= show columns 0. hide a column + * @param array $column_order An array of integers that let us decide how the columns are going to be sort. + * i.e: $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column + * @param array $form_actions Set optional forms actions + * + * @author Julio Montoya + */ + + function display_sortable_config_table($header, $content, $sorting_options = array (), $paging_options = array (), $query_vars = null, $column_show=array(),$column_order=array(),$form_actions=array()) + { + global $origin; + $column = isset ($sorting_options['column']) ? $sorting_options['column'] : 0; + $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20; + + $table = new SortableTableFromArrayConfig($content, $column, $default_items_per_page,'tablename',$column_show,$column_order); + + if (is_array($query_vars)) { + $table->set_additional_parameters($query_vars); + } + // show or hide the columns header + if (is_array($column_show) ) + { + for ($i=0;$iset_header($i, $header[$i][0], $header[$i][1], $header[$i][2], $header[$i][3]); + } + } + } + $table->set_form_actions($form_actions); + $table->display(); + } + + /** * Displays a normal message. It is recommended to use this function * to display any normal information messages. diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index c679b37333..d2589efc49 100644 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -4,7 +4,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2005 Dokeos S.A. + Copyright (c) 2005-2008 Dokeos S.A. Copyright (c) Bart Mollet (bart.mollet@hogent.be) For a full list of contributors, see "credits.txt". @@ -107,6 +107,8 @@ class SortableTable extends HTML_Table * table */ var $other_tables; + + /** * Create a new SortableTable * @param string $table_name A name for the table (default = 'table') @@ -612,4 +614,69 @@ class SortableTableFromArray extends SortableTable return count($this->table_data); } } + + +/** + * Sortable table which can be used for data available in an array + * + * Is a variation of SortableTableFromArray because we add 2 new arrays $column_show and $column_order + * $column_show is an array that lets us decide which are going to be the columns to show + * $column_order is an array that lets us decide the ordering of the columns + * i.e: $column_header=array('a','b','c','d','e'); $column_order=array(1,2,5,4,5); + * These means that the 3th column (letter "c") will be sort like the order we use in the 5th column + */ + +class SortableTableFromArrayConfig extends SortableTable +{ + /** + * The array containing the columns that will be show i.e $column_show=array('1','0','0'); we will show only the 1st column + */ + private $column_show; + + /** + *The array containing the real sort column $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column + */ + private $column_order; + /** + * The array containing all data for this table + */ + private $table_data; + + /** + * Constructor + * @param array $table_data All the information of the table + * @param int $default_column Default column that will be use in the sorts functions + * @param int $default_items_per_page quantity of pages that we are going to see + * @param int $tablename Name of the table + * @param array $column_show An array with binary values 1: we show the column 2: we don't show it + * @param array $column_order An array of integers that let us decide how the columns are going to be sort. + */ + public function SortableTableFromArrayConfig($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename',$column_show=null,$column_order=null) + { + $this->column_show=$column_show; + $this->column_order=$column_order; + + parent :: SortableTable($tablename, null, null, $default_column, $default_items_per_page,'ASC'); + + $this->table_data = $table_data; + } + /** + * Get table data to show on current page + * @see SortableTable#get_table_data + */ + public function get_table_data($from = 1) + { + $content = TableSort :: sort_table_config($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC ,$this->column_show, $this->column_order); + return array_slice($content, $from, $this->per_page); + } + + /** + * Get total number of items + * @see SortableTable#get_total_number_of_items + */ + public function get_total_number_of_items() + { + return count($this->table_data); + } +} ?> \ No newline at end of file diff --git a/main/inc/lib/tablesort.lib.php b/main/inc/lib/tablesort.lib.php index 836c0837ce..75c095b344 100644 --- a/main/inc/lib/tablesort.lib.php +++ b/main/inc/lib/tablesort.lib.php @@ -3,7 +3,7 @@ ============================================================================== Dokeos - elearning and course management software - Copyright (c) 2004 Dokeos S.A. + Copyright (c) 2004-2008 Dokeos S.A. Copyright (c) 2003 Ghent University (UGent) Copyright (c) 2001 Universite catholique de Louvain (UCL) Copyright (c) Bart Mollet (bart.mollet@hogent.be) @@ -36,31 +36,31 @@ class TableSort /** * String to lowercase (keep accents). * @param string $txt The string to convert - * @author René Haentjens + * @author Ren� Haentjens * This function is 8859-1 specific and should be adapted when Dokeos is * used with other charsets. */ function strtolower_keepaccents($txt) { - return strtolower(strtr($txt, "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ", "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ")); + return strtolower(strtr($txt, "������������������������������", "������������������������������")); } /** * String to lowercase. * @param string $txt The string to convert - * @author René Haentjens + * @author Ren� Haentjens * This function is 8859-1 specific and should be adapted when Dokeos is * used with other charsets. */ function strtolower_eorlatin($txt) { - return str_replace(array ("æ", "ß"), array ("ae", "ss"), strtr(TableSort::strtolower_keepaccents($txt), "àáâãäåçèéêëìíîïðñòóôõöøùúûüýÿ", "aaaaaaceeeeiiiidnoooooouuuuyy")); - // do not replace "þ" by "th", leave it at the end of the alphabet... - // do not replace any of "$&¢£¥©ª®µº", though they resemble letters... + return str_replace(array ("�", "�"), array ("ae", "ss"), strtr(TableSort::strtolower_keepaccents($txt), "�����������������������������", "aaaaaaceeeeiiiidnoooooouuuuyy")); + // do not replace "�" by "th", leave it at the end of the alphabet... + // do not replace any of "$&��������", though they resemble letters... } /** * Create a string to use in sorting. * @param string $txt The string to convert - * @author René Haentjens + * @author Ren� Haentjens * This function is 8859-1 specific and should be adapted when Dokeos is * used with other charsets. * See http://anubis.dkuug.dk/CEN/TC304/EOR/eorhome.html @@ -69,7 +69,7 @@ class TableSort */ function orderingstring($txt) { - return ereg_replace("[^0-9a-zþ]", "", TableSort::strtolower_eorlatin($txt)); + return ereg_replace("[^0-9a-z�]", "", TableSort::strtolower_eorlatin($txt)); } /** * Sort 2-dimensional table. @@ -101,7 +101,6 @@ class TableSort { return TableSort::sort_table($data, $column, $direction, SORT_NUMERIC); } - return TableSort::sort_table($data, $column, $direction, SORT_STRING); break; case SORT_NUMERIC : @@ -130,13 +129,13 @@ class TableSort * @author bart.mollet@hogent.be */ function is_numeric_column($data, $column) - { + { $is_numeric = true; + foreach ($data as $index => $row) { $is_numeric &= is_numeric(strip_tags($row[$column])); - } - return $is_numeric; + } } /** * Checks if a column of a 2D-array contains only dates (GNU date syntax) @@ -146,7 +145,7 @@ class TableSort * @author bart.mollet@hogent.be */ function is_date_column($data, $column) - { + { $is_date = true; foreach ($data as $index => $row) { @@ -182,5 +181,104 @@ class TableSort } return $is_image; } + + + /** + * Sort 2-dimensional table. It is possile of change the columns that will be show and the way that the columns are sorted. + * @param array $data The data to be sorted. + * @param int $column The column on which the data should be sorted (default = 0) + * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC) + * @param array $column_show The columns that we will show in the table i.e: $column_show=array('1','0','1') we will show the 1st and the 3th column. + * @param array $column_order Changes how the columns will be sorted ie. $column_order=array('1','4','3','4') The 2nd column will be sorted like the 4 column + * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC,SORT_STRING,SORT_DATE,SORT_IMAGE) * + * @return array The sorted dataset + * @author bart.mollet@hogent.be + */ + + function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show=null, $column_order=null,$type = SORT_REGULAR) + { + if(!is_array($data) || count($data)==0) + { + return array(); + } + + // Change columns sort + // Here we say that the real way of how the columns are going to be order is manage by the $column_order array + if(is_array($column_order)) + { + for($i=0;$i \ No newline at end of file diff --git a/main/inc/lib/text.lib.php b/main/inc/lib/text.lib.php index a80920fa31..d5886b3316 100644 --- a/main/inc/lib/text.lib.php +++ b/main/inc/lib/text.lib.php @@ -1,9 +1,9 @@ -, Ghent University - * @author Christophe Gesché + * @author Christophe Gesch� * originally inspired from from PhpMyAdmin * @param string $formatOfDate date pattern * @param integer $timestamp, default is NOW. @@ -278,4 +278,132 @@ function latex_gif_renderer($latex_code) $return .= ''.$latex_code.''; return $return; } + + +/** + * This function returns the difference between the current date (date(now)) with the parameter $date in a string format like "2 days, 1 hour" + * Example: $date="2008-03-07 15:44:08"; + * date_to_str($date) it will return 3 days, 20 hours + * + * @param string This string has to be the result of a date function in this format -> date("Y-m-d H:i:s",time()); + * @return string The difference between the current date and the parameter in a literal way "3 days, 2 hour" * + * @author Julio Montoya + */ + +function date_to_str_ago($date) +{ + $dst_date=strtotime($date); + //for not call date several times + $date_array=date("s/i/G/j/n/Y",$dst_date); + $date_split=explode("/",$date_array); + + $dst_s=$date_split[0]; + $dst_m=$date_split[1]; + $dst_h=$date_split[2]; + $dst_day=$date_split[3]; + $dst_mth=$date_split[4]; + $dst_yr=$date_split[5]; + + $dst_date = mktime($dst_h,$dst_m,$dst_s,$dst_mth,$dst_day,$dst_yr); + $time=$offset = time()-$dst_date; //seconds between current days and today + + //------------ Here start the functions sec_to_str + $act_day=date('d'); + $act_mth=date('n'); + $act_yr = date('Y'); + + if ($dst_day==$act_day && $dst_mth==$act_mth && $dst_yr == $act_yr ) + { + return ucfirst(get_lang('Today')); + } + + if ($dst_day==$act_day-1 && $dst_mth==$act_mth && $dst_yr == $act_yr ) + { + return ucfirst(get_lang('Yesterday')); + } + + // original 1 + //$sec_time=array("century"=>3.1556926*pow(10,9),"decade"=>315569260,"year"=>31556926,"month"=>2629743.83,"week"=>604800,"day"=>86400,"hour"=>3600,"minute"=>60,"second"=>1); + //$sec_time=array(get_lang('MinDecade')=>315569260,get_lang('MinYear')=>31556926,get_lang('MinMonth')=>2629743.83,get_lang('MinWeek')=>604800,get_lang('MinDay')=>86400,get_lang('MinHour')=>3600,get_lang('MinMinute')=>60); + + $MinDecade=get_lang('MinDecade'); + $MinYear=get_lang('MinYear'); + $MinMonth=get_lang('MinMonth'); + $MinWeek=get_lang('MinWeek'); + $MinDay=get_lang('MinDay'); + $MinHour=get_lang('MinHour'); + $MinMinute=get_lang('MinMinute'); + + $MinDecades=get_lang('MinDecades'); + $MinYears=get_lang('MinYears'); + $MinMonths=get_lang('MinMonths'); + $MinWeeks=get_lang('MinWeeks'); + $MinDays=get_lang('MinDays'); + $MinHours=get_lang('MinHours'); + $MinMinutes=get_lang('MinMinutes'); + + $sec_time_time=array(315569260,31556926,2629743.83,604800,86400,3600,60); + $sec_time_sing=array($MinDecade,$MinYear,$MinMonth,$MinWeek,$MinDay,$MinHour,$MinMinute); + $sec_time_plu =array($MinDecades,$MinYears,$MinMonths,$MinWeeks,$MinDays,$MinHours,$MinMinutes); + + + $str_result=array(); + $time_result=array(); + $key_result=array(); + + $str=''; + $i=0; + for ($i=0;$i $time) { + continue; + } + + $current_value=intval($time/$seconds); + + if ($current_value!='1') + { + $date_str= $sec_time_plu[$i]; + } + else + { + $date_str= $sec_time_sing[$i]; + + } + $key_result[]=$sec_time_sing[$i]; + + $str_result[]=$current_value.' '.$date_str; + $time_result[]= $current_value; + $str.=$current_value.$date_str; + $time%=$seconds; + } + + + if ($key_result[0]== $MinDay && $key_result[1]== $MinMinute) + { + $key_result[1]=' 0 '.$MinHours; + $str_result[0]=$time_result[0].' '.$key_result[0]; + $str_result[1]=$key_result[1]; + } + + if ($key_result[0]== $MinYear && ($key_result[1]== $MinDay || $key_result[1]== $MinWeek)) + { + $key_result[1]=' 0 '.$MinMonths; + $str_result[0]=$time_result[0].' '.$key_result[0]; + $str_result[1]=$key_result[1]; + } + + if (!empty($str_result[1])) + { + $str=$str_result[0].', '.$str_result[1]; + } + else + { + $str=$str_result[0]; + } + + return $str; +} ?> \ No newline at end of file