From eec5e3c1b58513586258b1ea399e55bb8fe4ee4c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 3 Mar 2010 12:27:55 -0500 Subject: [PATCH] Fixing sql queries --- main/work/work.lib.php | 143 +++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/main/work/work.lib.php b/main/work/work.lib.php index edc8474377..573f08c4a6 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -348,14 +348,14 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou "WHERE url LIKE BINARY '$sub_course_dir%' " . "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query. $condition_session. - "ORDER BY sent_date DESC"; + " ORDER BY sent_date DESC"; $sql_get_publications_num = "SELECT count(*) " . "FROM ".$work_table." " . "WHERE url LIKE BINARY '$sub_course_dir%' " . "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query. $condition_session. - "ORDER BY id"; + " ORDER BY id"; } else { if (!empty($_SESSION['toolgroup'])) { @@ -372,10 +372,9 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou "WHERE url LIKE BINARY '$sub_course_dir%' " . "AND url NOT LIKE BINARY '$sub_course_dir%/%' " .$add_in_where_query. $condition_session. - "ORDER BY id"; + " ORDER BY id"; } - $sql_result = Database::query($sql_get_publications_list); $sql_result_num = Database::query($sql_get_publications_num); @@ -739,81 +738,83 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou $table_data[] = $row; } } - while( $work = Database::fetch_object($sql_result)) { - //Get the author ID for that document from the item_property table - $is_author = false; - $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND ref=".$work->id; - $author_qry = Database::query($author_sql); - $row2=Database::fetch_array($author_qry); - - - if(Database::num_rows($author_qry)==1) { - $is_author = true; - } - - //display info depending on the permissions - if( $work->accepted == '1' || $is_allowed_to_edit) { - $row = array(); - if($work->accepted == '0') - { - $class='class="invisible"'; - } else { - $class=''; + + if (Database::num_rows($sql_result) > 0 ) { + while( $work = Database::fetch_object($sql_result)) { + //Get the author ID for that document from the item_property table + $is_author = false; + $author_sql = "SELECT * FROM $iprop_table WHERE tool = 'work' AND ref=".$work->id; + $author_qry = Database::query($author_sql); + $row2=Database::fetch_array($author_qry); + + + if(Database::num_rows($author_qry)==1) { + $is_author = true; } - - $qualification_string = ''; - $add_string = ''; - if(defined('IS_ASSIGNMENT')): - if($work->qualification=='') { - $qualification_string = ' / '.get_lang('NotRevised').''; + + //display info depending on the permissions + if( $work->accepted == '1' || $is_allowed_to_edit) { + $row = array(); + if($work->accepted == '0') + { + $class='class="invisible"'; } else { - $qualification_string = ' / '.get_lang('Qualification').': '.$work->qualification.''; - } - if(defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))) { - $add_string = ' '.get_lang('Expired').''; + $class=''; } - endif; - - $url = implode("/", array_map("rawurlencode", explode("/", $work->url))); - - //$full_file_name = 'download.php?file='.$realname; - $row[]= build_document_icon_tag('file',$work->url); - $row[]= ''.get_lang('Save').''.$work->title.'
'.$work->description; - $row[]= display_user_link_work($row2['insert_user_id'],$work->author).$qualification_string;// $work->author; - $work_sent_date = api_get_local_time($work->sent_date, null, null, date_default_timezone_get()); - $sent_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($work_sent_date))).'    '; - $sent_date .= ucfirst(strftime($timeNoSecFormat,strtotime($work_sent_date))); - $row[]= date_to_str_ago($work->sent_date).$add_string.'
'.$sent_date.''.''; - - if( $is_allowed_to_edit) { - - $action = ''; - $action .= ''.get_lang('Modify').''; - $action .= ''.Display::return_icon('delete.gif',get_lang('WorkDelete')).''; - $action .= ''.get_lang('Move').''; - if($work->accepted == '1') { - $action .= ''.get_lang('Invisible').''; + + $qualification_string = ''; + $add_string = ''; + if(defined('IS_ASSIGNMENT')): + if($work->qualification=='') { + $qualification_string = ' / '.get_lang('NotRevised').''; + } else { + $qualification_string = ' / '.get_lang('Qualification').': '.$work->qualification.''; + } + if(defined('ASSIGNMENT_EXPIRES') && (ASSIGNMENT_EXPIRES < convert_date_to_number($work->sent_date))) { + $add_string = ' '.get_lang('Expired').''; + } + endif; + + $url = implode("/", array_map("rawurlencode", explode("/", $work->url))); + + //$full_file_name = 'download.php?file='.$realname; + $row[]= build_document_icon_tag('file',$work->url); + $row[]= ''.get_lang('Save').''.$work->title.'
'.$work->description; + $row[]= display_user_link_work($row2['insert_user_id'],$work->author).$qualification_string;// $work->author; + $work_sent_date = api_get_local_time($work->sent_date, null, null, date_default_timezone_get()); + $sent_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($work_sent_date))).'    '; + $sent_date .= ucfirst(strftime($timeNoSecFormat,strtotime($work_sent_date))); + $row[]= date_to_str_ago($work->sent_date).$add_string.'
'.$sent_date.''.''; + + if( $is_allowed_to_edit) { + + $action = ''; + $action .= ''.get_lang('Modify').''; + $action .= ''.Display::return_icon('delete.gif',get_lang('WorkDelete')).''; + $action .= ''.get_lang('Move').''; + if($work->accepted == '1') { + $action .= ''.get_lang('Invisible').''; + } else { + $action .= ''.get_lang('Visible').''; + } + + $row[] = $action; + // the user that is not course admin can only edit/delete own document + } elseif($row2['insert_user_id'] == $_user['user_id']) { + $action = ''; + $action .= ''.get_lang('Modify').''; + if (api_get_course_setting('student_delete_own_publication')==1) { + $action .= ''.Display::return_icon('delete.gif',get_lang('WorkDelete')).''; + } + + $row[] = $action; } else { - $action .= ''.get_lang('Visible').''; - } - - $row[] = $action; - // the user that is not course admin can only edit/delete own document - } elseif($row2['insert_user_id'] == $_user['user_id']) { - $action = ''; - $action .= ''.get_lang('Modify').''; - if (api_get_course_setting('student_delete_own_publication')==1) { - $action .= ''.Display::return_icon('delete.gif',get_lang('WorkDelete')).''; + $row[] = " "; } - - $row[] = $action; - } else { - $row[] = " "; + $table_data[] = $row; } - $table_data[] = $row; } } - $sorting_options=array(); $sorting_options['column']=1;