';
return $output;
}
/**
* this function returns the code for the form for adding a new feedback message to a dropbox file.
* @return string code
*
* @author Patrick Cool , Ghent University
* @version march 2006
*/
function feedback_form()
{
$return = get_lang('AddNewFeedback').' ';
$number_users_who_see_file = check_if_file_exist($_GET['id']);
if ($number_users_who_see_file) {
$token = Security::get_token();
$return .= '';
$return .= '';
$return .= ' ';
} else {
$return .= get_lang('AllUsersHaveDeletedTheFileAndWillNotSeeFeedback');
}
return $return;
}
function user_can_download_file($id, $user_id)
{
$course_id = api_get_course_int_id();
$id = intval($id);
$user_id = intval($user_id);
$sql = "SELECT file_id FROM ".Database::get_course_table(TABLE_DROPBOX_PERSON)."
WHERE c_id = $course_id AND user_id = $user_id AND file_id = ".$id;
$result = Database::query($sql);
$number_users_who_see_file = Database::num_rows($result);
$sql = "SELECT file_id FROM ".Database::get_course_table(TABLE_DROPBOX_POST)."
WHERE c_id = $course_id AND dest_user_id = $user_id AND file_id = ".$id;
$result = Database::query($sql);
$count = Database::num_rows($result);
return $number_users_who_see_file > 0 || $count > 0;
}
// we now check if the other users have not delete this document yet.
// If this is the case then it is useless to see the
// add feedback since the other users will never get to see the feedback.
function check_if_file_exist($id)
{
$id = intval($id);
$course_id = api_get_course_int_id();
$sql = "SELECT file_id FROM ".Database::get_course_table(TABLE_DROPBOX_PERSON)."
WHERE c_id = $course_id AND file_id = ".$id;
$result = Database::query($sql);
$number_users_who_see_file = Database::num_rows($result);
$sql = "SELECT file_id FROM ".Database::get_course_table(TABLE_DROPBOX_POST)."
WHERE c_id = $course_id AND file_id = ".$id;
$result = Database::query($sql);
$count = Database::num_rows($result);
return $number_users_who_see_file > 0 || $count > 0;
}
/**
* @return string language string (depending on the success or failure.
*
* @author Patrick Cool , Ghent University
* @version march 2006
*/
function store_feedback()
{
if (!is_numeric($_GET['id'])) {
return get_lang('FeedbackError');
}
$course_id = api_get_course_int_id();
if (empty($_POST['feedback'])) {
return get_lang('PleaseTypeText');
} else {
$params = [
'c_id' => $course_id,
'file_id' => $_GET['id'],
'author_user_id' => api_get_user_id(),
'feedback' => $_POST['feedback'],
'feedback_date' => api_get_utc_datetime(),
];
$id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FEEDBACK), $params);
if ($id) {
$sql = "UPDATE ".Database::get_course_table(TABLE_DROPBOX_FEEDBACK)." SET feedback_id = iid WHERE iid = $id";
Database::query($sql);
}
return get_lang('DropboxFeedbackStored');
}
}
/**
* This function downloads all the files of the input array into one zip
* @param array $fileList containing all the ids of the files that have to be downloaded.
* @author Patrick Cool , Ghent University
* @todo consider removing the check if the user has received or sent this file (zip download of a folder already sufficiently checks for this).
* @todo integrate some cleanup function that removes zip files that are older than 2 days
*
* @author Patrick Cool , Ghent University
* @author Julio Montoya Addin c_id support
* @version march 2006
*/
function zip_download($fileList)
{
$_course = api_get_course_info();
$course_id = api_get_course_int_id();
$fileList = array_map('intval', $fileList);
// note: we also have to add the check if the user has received or sent this file.
$sql = "SELECT DISTINCT file.filename, file.title, file.author, file.description
FROM ". Database::get_course_table(TABLE_DROPBOX_FILE)." file
INNER JOIN ". Database::get_course_table(TABLE_DROPBOX_PERSON)." person
ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
INNER JOIN ".Database::get_course_table(TABLE_DROPBOX_POST)." post
ON (post.file_id = file.id AND post.c_id = $course_id AND file.c_id = $course_id)
WHERE
file.id IN (".implode(', ', $fileList).") AND
file.id = person.file_id AND
(
person.user_id = '".api_get_user_id()."' OR
post.dest_user_id = '".api_get_user_id()."'
) ";
$result = Database::query($sql);
$files = array();
while ($row = Database::fetch_array($result)) {
$files[$row['filename']] = array(
'filename' => $row['filename'],
'title' => $row['title'],
'author' => $row['author'],
'description' => $row['description']
);
}
// Step 3: create the zip file and add all the files to it
$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip";
Session::write('dropbox_files_to_download', $files);
$zip = new PclZip($temp_zip_file);
foreach ($files as $value) {
$zip->add(
api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'],
PCLZIP_OPT_REMOVE_ALL_PATH,
PCLZIP_CB_PRE_ADD,
'my_pre_add_callback'
);
}
Session::erase('dropbox_files_to_download');
$name = 'dropbox-'.api_get_utc_datetime().'.zip';
$result = DocumentManager::file_send_for_download($temp_zip_file, true, $name);
if ($result === false) {
api_not_allowed(true);
}
@unlink($temp_zip_file);
exit;
}
/**
* This is a callback function to decrypt the files in the zip file to their normal filename (as stored in the database)
* @param array $p_event a variable of PCLZip
* @param array $p_header a variable of PCLZip
*
* @author Patrick Cool , Ghent University
* @version march 2006
*/
function my_pre_add_callback($p_event, &$p_header)
{
$files = Session::read('dropbox_files_to_download');
$p_header['stored_filename'] = $files[$p_header['stored_filename']]['title'];
return 1;
}
/**
* @desc Generates the contents of a html file that gives an overview of all the files in the zip file.
* This is to know the information of the files that are inside the zip file (who send it, the comment, ...)
* @author Patrick Cool , Ghent University, March 2006
* @author Ivan Tcholakov, 2010, code for html metadata has been added.
*/
function generate_html_overview($files, $dont_show_columns = array(), $make_link = array())
{
$return = ''."\n";
$return .= ''."\n";
$return .= "\n\t".get_lang('OverviewOfFilesInThisZip')."\n";
$return .= "\t".''."\n";
$return .= "\n\n";
$return .= ''."\n\n";
$return .= "
\n";
$counter = 0;
foreach ($files as $value) {
// Adding the header.
if ($counter == 0) {
$columns_array = array_keys($value);
$return .= "\n
";
foreach ($columns_array as $columns_array_key => $columns_array_value) {
if (!in_array($columns_array_value, $dont_show_columns)) {
$return .= "\n\t
\n\n";
$return .= "\n";
return $return;
}
/**
* @desc This function retrieves the number of feedback messages on every document. This function might become obsolete when
* the feedback becomes user individual.
* @author Patrick Cool , Ghent University
* @version march 2006
*/
function get_total_number_feedback($file_id = '')
{
$course_id = api_get_course_int_id();
$sql = "SELECT COUNT(feedback_id) AS total, file_id
FROM ". Database::get_course_table(TABLE_DROPBOX_FEEDBACK)."
WHERE c_id = $course_id GROUP BY file_id";
$result = Database::query($sql);
$return = array();
while ($row = Database::fetch_array($result)) {
$return[$row['file_id']] = $row['total'];
}
return $return;
}
/**
* @desc this function checks if the key exists. If this is the case it returns the value, if not it returns 0
* @author Patrick Cool , Ghent University
* @version march 2006
*/
function check_number_feedback($key, $array)
{
if (is_array($array)) {
if (array_key_exists($key, $array)) {
return $array[$key];
} else {
return 0;
}
} else {
return 0;
}
}
/**
* Get the last access to a given tool of a given user
* @param $tool string the tool constant
* @param $courseId the course_id
* @param $user_id the id of the user
* @return string last tool access date
*
* @author Patrick Cool , Ghent University
* @version march 2006
*
* @todo consider moving this function to a more appropriate place.
*/
function get_last_tool_access($tool, $courseId = null, $user_id = null)
{
// The default values of the parameters
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
if (empty($user_id)) {
$user_id = api_get_user_id();
}
// the table where the last tool access is stored (=track_e_lastaccess)
$table_last_access = Database::get_main_table('track_e_lastaccess');
$sql = "SELECT access_date FROM $table_last_access
WHERE
access_user_id = ".intval($user_id)." AND
c_id='".intval($courseId)."' AND
access_tool='".Database::escape_string($tool)."'
ORDER BY access_date DESC
LIMIT 1";
$result = Database::query($sql);
$row = Database::fetch_array($result);
return $row['access_date'];
}
/**
* Previously $dropbox_cnf['mailingIdBase'], returns a mailing ID to generate a mail ID
* @return int
*/
function get_mail_id_base()
{
// false = no mailing functionality
//$dropbox_cnf['mailingIdBase'] = 10000000; // bigger than any user_id,
// allowing enough space for pseudo_ids as uploader_id, dest_user_id, user_id:
// mailing pseudo_id = dropbox_cnf('mailingIdBase') + mailing id
return 10000000;
}