12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * This file contains additional dropbox functions. Initially there were some
- * functions in the init files also but I have moved them over
- * to one file -- Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya adding c_id support
- */
- use ChamiloSession as Session;
- $this_section = SECTION_COURSES;
- $htmlHeadXtra[] = '<script>
- function setFocus(){
- $("#category_title").focus();
- }
- $(document).ready(function () {
- setFocus();
- });
- </script>';
- /**
- * This function is a wrapper function for the multiple actions feature.
- * @return string|null If there is a problem, return a string message, otherwise nothing
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function handle_multiple_actions()
- {
- $_user = api_get_user_info();
- $is_courseAdmin = api_is_course_admin();
- $is_courseTutor = api_is_course_tutor();
- // STEP 1: are we performing the actions on the received or on the sent files?
- if ($_POST['action'] == 'delete_received' || $_POST['action'] == 'download_received') {
- $part = 'received';
- } elseif ($_POST['action'] == 'delete_sent' || $_POST['action'] == 'download_sent') {
- $part = 'sent';
- }
- // STEP 2: at least one file has to be selected. If not we return an error message
- $ids = isset($_GET['id']) ? $_GET['id'] : array();
- if (count($ids)>0) {
- $checked_file_ids = $_POST['id'];
- } else {
- foreach ($_POST as $key => $value) {
- if (strstr($value, $part.'_') AND $key != 'view_received_category' AND $key != 'view_sent_category') {
- $checked_files = true;
- $checked_file_ids[] = intval(substr($value, strrpos($value, '_')));
- }
- }
- }
- $checked_file_ids = $_POST['id'];
- if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
- return get_lang('CheckAtLeastOneFile');
- }
- // STEP 3A: deleting
- if ($_POST['action'] == 'delete_received' || $_POST['action'] == 'delete_sent') {
- $dropboxfile = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
- foreach ($checked_file_ids as $key => $value) {
- if ($_GET['view'] == 'received') {
- $dropboxfile->deleteReceivedWork($value);
- $message = get_lang('ReceivedFileDeleted');
- }
- if ($_GET['view'] == 'sent' OR empty($_GET['view'])) {
- $dropboxfile->deleteSentWork($value);
- $message = get_lang('SentFileDeleted');
- }
- }
- return $message;
- }
- // STEP 3B: giving comment
- if ($_POST['actions'] == 'comment') {
- // This has not been implemented.
- // The idea was that it would be possible to write the same feedback for the selected documents.
- }
- // STEP 3C: moving
- if (strstr($_POST['action'], 'move_')) {
- // check move_received_n or move_sent_n command
- if (strstr($_POST['action'], 'received')) {
- $part = 'received';
- $to_cat_id = str_replace('move_received_', '', $_POST['action']);
- } else {
- $part = 'sent';
- $to_cat_id = str_replace('move_sent_', '', $_POST['action']);
- }
- foreach ($checked_file_ids as $value) {
- store_move($value, $to_cat_id, $part);
- }
- return get_lang('FilesMoved');
- }
- // STEP 3D: downloading
- if ($_POST['action'] == 'download_sent' || $_POST['action'] == 'download_received') {
- zip_download($checked_file_ids);
- }
- }
- /**
- * Get conf settings
- * @return array
- */
- function getDropboxConf()
- {
- return Session::read('dropbox_conf');
- }
- /**
- * This function deletes a dropbox category
- *
- * @todo give the user the possibility what needs to be done with the files
- * in this category: move them to the root, download them as a zip, delete them
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function delete_category($action, $id, $user_id = null)
- {
- $course_id = api_get_course_int_id();
- $is_courseAdmin = api_is_course_admin();
- $is_courseTutor = api_is_course_tutor();
- $dropbox_cnf = getDropboxConf();
- if (empty($user_id)) {
- $user_id = api_get_user_id();
- }
- $cat = get_dropbox_category($id);
- if (count($cat)==0) {
- return false;
- }
- if ($cat['user_id'] != $user_id && !api_is_platform_admin($user_id)) {
- return false;
- }
- // an additional check that might not be necessary
- if ($action == 'deletereceivedcategory') {
- $sentreceived = 'received';
- $entries_table = $dropbox_cnf['tbl_post'];
- $id_field = 'file_id';
- $return_message = get_lang('ReceivedCatgoryDeleted');
- } elseif ($action == 'deletesentcategory') {
- $sentreceived = 'sent';
- $entries_table = $dropbox_cnf['tbl_file'];
- $id_field = 'id';
- $return_message = get_lang('SentCatgoryDeleted');
- } else {
- return get_lang('Error');
- }
- // step 1: delete the category
- $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']."
- WHERE c_id = $course_id AND cat_id='".intval($id)."' AND $sentreceived='1'";
- Database::query($sql);
- // step 2: delete all the documents in this category
- $sql = "SELECT * FROM ".$entries_table."
- WHERE c_id = $course_id AND cat_id='".intval($id)."'";
- $result = Database::query($sql);
- while($row = Database::fetch_array($result)) {
- $dropboxfile = new Dropbox_Person($user_id, $is_courseAdmin, $is_courseTutor);
- if ($action == 'deletereceivedcategory') {
- $dropboxfile->deleteReceivedWork($row[$id_field]);
- }
- if ($action == 'deletesentcategory') {
- $dropboxfile->deleteSentWork($row[$id_field]);
- }
- }
- return $return_message;
- }
- /**
- * Displays the form to move one individual file to a category
- *@ return html code of the form that appears in a message box.
- * @author Julio Montoya - function rewritten
- */
- function display_move_form($part, $id, $target = array(), $extra_params = array(), $viewReceivedCategory, $viewSentCategory, $view)
- {
- $form = new FormValidator(
- 'form1',
- 'post',
- api_get_self().'?view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&'.$extra_params
- );
- $form->addElement('header', get_lang('MoveFileTo'));
- $form->addElement('hidden', 'id', intval($id));
- $form->addElement('hidden', 'part', Security::remove_XSS($part));
- $options = array('0' => get_lang('Root'));
- foreach ($target as $category) {
- $options[$category['cat_id']] = $category['cat_name'];
- }
- $form->addElement('select', 'move_target', get_lang('MoveFileTo'), $options);
- $form->addElement('button', 'do_move', get_lang('MoveFile'));
- $form->display();
- }
- /**
- * This function moves a file to a different category
- *
- * @param $id the id of the file we are moving
- * @param $target the id of the folder we are moving to
- * @param string $part are we moving a received file or a sent file?
- *
- * @return string string
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function store_move($id, $target, $part)
- {
- $_user = api_get_user_info();
- $dropbox_cnf = getDropboxConf();
- $course_id = api_get_course_int_id();
- if ((isset($id) && $id != '') &&
- (isset($target) && $target != '') &&
- (isset($part) && $part != '')
- ) {
- if ($part == 'received') {
- $sql = "UPDATE ".$dropbox_cnf["tbl_post"]."
- SET cat_id = ".intval($target)."
- WHERE c_id = $course_id AND dest_user_id = ".intval($_user['user_id'])."
- AND file_id = ".intval($id)."";
- Database::query($sql);
- $return_message = get_lang('ReceivedFileMoved');
- }
- if ($part == 'sent') {
- $sql = "UPDATE ".$dropbox_cnf["tbl_file"]."
- SET cat_id = ".intval($target)."
- WHERE
- c_id = $course_id AND
- uploader_id = ".intval($_user['user_id'])." AND
- id = ".intval($id)."";
- Database::query($sql);
- $return_message = get_lang('SentFileMoved');
- }
- } else {
- $return_message = get_lang('NotMovedError');
- }
- return $return_message;
- }
- /**
- * This functions displays all teh possible actions that can be
- * performed on multiple files. This is the dropdown list that
- * appears below the sortable table of the sent / or received files.
- *
- * @return html value for the dropdown list
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function display_action_options($part, $categories, $current_category = 0)
- {
- echo '<select name="actions">';
- echo '<option value="download">'.get_lang('Download').'</option>';
- echo '<option value="delete">'.get_lang('Delete').'</option>';
- if (is_array($categories)) {
- echo '<optgroup label="'.get_lang('MoveTo').'">';
- if ($current_category != 0) {
- echo '<option value="move_0">'.get_lang('Root').'</a>';
- }
- foreach ($categories as $value) {
- if ($current_category != $value['cat_id']) {
- echo '<option value="move_'.$value['cat_id'].'">'.$value['cat_name'].'</option>';
- }
- }
- echo '</optgroup>';
- }
- echo '</select>';
- echo '<input type="submit" name="do_actions_'.Security::remove_XSS($part).'" value="'.get_lang('Ok').'" />';
- }
- /**
- * this function returns the html code that displays the checkboxes next to the files so that
- * multiple actions on one file are possible.
- *
- * @param $id the unique id of the file
- * @param $part are we dealing with a sent or with a received file?
- *
- * @return string code
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function display_file_checkbox($id, $part) {
- if (isset($_GET['selectall'])) {
- $checked = 'checked';
- }
- $return_value = '<input type="checkbox" name="'.Security::remove_XSS($part).'_'.Security::remove_XSS($id).'" value="'.Security::remove_XSS($id).'" '.$checked.' />';
- return $return_value;
- }
- /**
- * This function retrieves all dropbox categories and returns them as an array
- *
- * @param $filter default '', when we need only the categories of the sent or the received part.
- *
- * @return array
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function get_dropbox_categories($filter = '')
- {
- $course_id = api_get_course_int_id();
- $_user = api_get_user_info();
- $dropbox_cnf = getDropboxConf();
- $return_array = array();
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']."
- WHERE c_id = $course_id AND user_id='".$_user['user_id']."' $condition_session";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- if (($filter == 'sent' && $row['sent'] == 1) || ($filter == 'received' && $row['received'] == 1) || $filter == '') {
- $return_array[$row['cat_id']] = $row;
- }
- }
- return $return_array;
- }
- /**
- * Get a dropbox category details
- * @param int The category ID
- * @return array The details of this category
- */
- function get_dropbox_category($id)
- {
- $dropbox_cnf = getDropboxConf();
- $course_id = api_get_course_int_id();
- if (empty($id) or $id != intval($id)) { return array(); }
- $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']."
- WHERE c_id = $course_id AND cat_id='".$id."'";
- $res = Database::query($sql);
- if ($res === false) {
- return array();
- }
- $row = Database::fetch_assoc($res);
- return $row;
- }
- /**
- * This functions stores a new dropboxcategory
- *
- * @var it might not seem very elegant if you create a category in sent
- * and in received with the same name that you get two entries in the
- * dropbox_category table but it is the easiest solution. You get
- * cat_name | received | sent | user_id
- * test | 1 | 0 | 237
- * test | 0 | 1 | 237
- * more elegant would be
- * test | 1 | 1 | 237
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function store_addcategory()
- {
- $course_id = api_get_course_int_id();
- $_user = api_get_user_info();
- $dropbox_cnf = getDropboxConf();
- // check if the target is valid
- if ($_POST['target'] == 'sent') {
- $sent = 1;
- $received = 0;
- } elseif ($_POST['target'] == 'received') {
- $sent = 0;
- $received = 1;
- } else {
- return get_lang('Error');
- }
- // check if the category name is valid
- if ($_POST['category_name'] == '') {
- return array('type' => 'error', 'message' => get_lang('ErrorPleaseGiveCategoryName'));
- }
- if (!$_POST['edit_id']) {
- $session_id = api_get_session_id();
- // step 3a, we check if the category doesn't already exist
- $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']."
- WHERE
- c_id = $course_id AND
- user_id='".$_user['user_id']."' AND
- cat_name='".Database::escape_string($_POST['category_name'])."' AND
- received='".$received."' AND
- sent='$sent' AND
- session_id='$session_id'";
- $result = Database::query($sql);
- // step 3b, we add the category if it does not exist yet.
- if (Database::num_rows($result) == 0) {
- $params = [
- 'cat_id' => 0,
- 'c_id' => $course_id,
- 'cat_name' => $_POST['category_name'],
- 'received' => $received,
- 'sent' => $sent,
- 'user_id' => $_user['user_id'],
- 'session_id' => $session_id,
- ];
- $id = Database::insert($dropbox_cnf['tbl_category'], $params);
- if ($id) {
- $sql = "UPDATE ".$dropbox_cnf['tbl_category']." SET cat_id = iid WHERE iid = $id";
- Database::query($sql);
- }
- return array('type' => 'confirmation', 'message' => get_lang('CategoryStored'));
- } else {
- return array('type' => 'error', 'message' => get_lang('CategoryAlreadyExistsEditIt'));
- }
- } else {
- $params = [
- 'cat_name' => $_POST['category_name'],
- 'received' => $received,
- 'sent' => $sent
- ];
- Database::update(
- $dropbox_cnf['tbl_category'],
- $params,
- [
- 'c_id = ? AND user_id = ? AND cat_id = ?' => [
- $course_id,
- $_user['user_id'],
- $_POST['edit_id'],
- ],
- ]
- );
- return array('type' => 'confirmation', 'message' => get_lang('CategoryModified'));
- }
- }
- /**
- * This function displays the form to add a new category.
- *
- * @param $category_name this parameter is the name of the category (used when no section is selected)
- * @param $id this is the id of the category we are editing.
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- @author Julio Montoya UI changes
- *
- * @version march 2006
- */
- function display_addcategory_form($category_name = '', $id = '', $action)
- {
- $dropbox_cnf = getDropboxConf();
- $course_id = api_get_course_int_id();
- $title = get_lang('AddNewCategory');
- if (isset($id) && $id != '') {
- // retrieve the category we are editing
- $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']."
- WHERE c_id = $course_id AND cat_id = ".intval($id)."";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if (empty($category_name)) {
- // after an edit with an error we do not want to return to the
- // original name but the name we already modified.
- // (happens when createinrecievedfiles AND createinsentfiles are not checked)
- $category_name = $row['cat_name'];
- }
- if ($row['received'] == '1') {
- $target = 'received';
- }
- if ($row['sent'] == '1') {
- $target = 'sent';
- }
- $title = get_lang('EditCategory');
- }
- if ($action == 'addreceivedcategory') {
- $target = 'received';
- }
- if ($action == 'addsentcategory') {
- $target = 'sent';
- }
- if ($action == 'editcategory') {
- $text = get_lang('ModifyCategory');
- } elseif ($action == 'addreceivedcategory' || $action == 'addsentcategory') {
- $text = get_lang('CreateCategory');
- }
- $form = new FormValidator('add_new_category', 'post', api_get_self().'?view='.Security::remove_XSS($_GET['view']));
- $form->addElement('header', $title);
- if (isset($id) && $id != '') {
- $form->addElement('hidden', 'edit_id', intval($id));
- }
- $form->addElement('hidden', 'action', Security::remove_XSS($action));
- $form->addElement('hidden', 'target', Security::remove_XSS($target));
- $form->addElement('text', 'category_name', get_lang('CategoryName'));
- $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required');
- $form->addButtonSave($text, 'StoreCategory');
- $defaults = array();
- $defaults['category_name'] = $category_name;
- $form->setDefaults($defaults);
- $form->display();
- }
- /**
- * this function displays the form to upload a new item to the dropbox.
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view)
- {
- $course_info = api_get_course_info();
- $_user = api_get_user_info();
- $is_courseAdmin = api_is_course_admin();
- $is_courseTutor = api_is_course_tutor();
- $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
- $token = Security::get_token();
- $dropbox_person = new Dropbox_Person(
- api_get_user_id(),
- $is_courseAdmin,
- $is_courseTutor
- );
- $form = new FormValidator(
- 'sent_form',
- 'post',
- api_get_self().'?view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&'.api_get_cidreq(),
- null,
- array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);')
- );
- $form->addElement('header', get_lang('UploadNewFile'));
- $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize'));
- $form->addElement('hidden', 'dropbox_unid', $dropbox_unid);
- $form->addElement('hidden', 'sec_token', $token);
- $form->addElement('hidden', 'origin', $origin);
- $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);'));
- if (dropbox_cnf('allowOverwrite')) {
- $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite'));
- }
- // List of all users in this course and all virtual courses combined with it
- if (api_get_session_id()) {
- $complete_user_list_for_dropbox = array();
- if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
- $complete_user_list_for_dropbox = CourseManager:: get_user_list_from_course_code(
- $course_info['code'],
- api_get_session_id(),
- null,
- null,
- 0
- );
- }
- $complete_user_list2 = CourseManager::get_coach_list_from_course_code(
- $course_info['code'],
- api_get_session_id()
- );
- $generalCoachList = array();
- $courseCoachList = array();
- foreach ($complete_user_list2 as $coach) {
- if ($coach['type'] == 'general_coach') {
- $generalCoachList[] = $coach;
- } else {
- $courseCoachList[] = $coach;
- }
- }
- $hideCourseCoach = api_get_setting('dropbox_hide_course_coach');
- if ($hideCourseCoach == 'false') {
- $complete_user_list_for_dropbox = array_merge(
- $complete_user_list_for_dropbox,
- $courseCoachList
- );
- }
- $hideGeneralCoach = api_get_setting('dropbox_hide_general_coach');
- if ($hideGeneralCoach == 'false') {
- $complete_user_list_for_dropbox = array_merge(
- $complete_user_list_for_dropbox,
- $generalCoachList
- );
- }
- } else {
- if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
- $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code(
- $course_info['code'],
- api_get_session_id()
- );
- } else {
- $complete_user_list_for_dropbox = CourseManager::get_teacher_list_from_course_code(
- $course_info['code'],
- false
- );
- }
- }
- if (!empty($complete_user_list_for_dropbox)) {
- foreach ($complete_user_list_for_dropbox as $k => $e) {
- $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname']));
- }
- $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst');
- }
- /*
- Create the options inside the select box:
- List all selected users their user id as value and a name string as display
- */
- $current_user_id = '';
- $options = array();
- $userGroup = new UserGroup();
- foreach ($complete_user_list_for_dropbox as $current_user) {
- if (($dropbox_person -> isCourseTutor
- || $dropbox_person -> isCourseAdmin
- || dropbox_cnf('allowStudentToStudent')
- || $current_user['status'] != 5 // Always allow teachers.
- || $current_user['is_tutor'] == 1 // Always allow tutors.
- ) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself.
- if ($current_user['user_id'] == $current_user_id) {
- continue;
- }
- $userId = $current_user['user_id'];
- $userInfo = api_get_user_info($userId);
- if ($userInfo['status'] != INVITEE) {
- $groupNameListToString = '';
- if (!empty($groups)) {
- $groupNameList = array_column($groups, 'name');
- $groupNameListToString = ' - ['.implode(', ', $groupNameList).']';
- }
- $groups = $userGroup->getUserGroupListByUser($userId);
- $full_name = $userInfo['complete_name'].$groupNameListToString;
- $current_user_id = $current_user['user_id'];
- $options['user_' . $current_user_id] = $full_name;
- }
- }
- }
- /*
- * Show groups
- */
- if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin)
- && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')
- ) {
- $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId'));
- if (count($complete_group_list_for_dropbox) > 0) {
- foreach ($complete_group_list_for_dropbox as $current_group) {
- if ($current_group['number_of_members'] > 0) {
- $options['group_'.$current_group['id']] = 'G: '.$current_group['name'].' - '.$current_group['number_of_members'].' '.get_lang('Users');
- }
- }
- }
- }
- if (dropbox_cnf('allowJustUpload')) {
- $options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect');
- }
- $form->addSelect(
- 'recipients',
- get_lang('SendTo'),
- $options,
- array(
- 'multiple' => 'multiple',
- 'size' => '10'
- )
- );
- $form->addButtonUpload(get_lang('Upload'), 'submitWork');
- $headers = array(
- get_lang('Upload'),
- get_lang('Upload').' ('.get_lang('Simple').')',
- );
- $multipleForm = new FormValidator(
- 'sent_multiple',
- 'post',
- '#',
- null,
- array('enctype' => 'multipart/form-data', 'id' => 'fileupload')
- );
- $multipleForm->addSelect(
- 'recipients',
- get_lang('SendTo'),
- $options,
- array(
- 'multiple' => 'multiple',
- 'size' => '10',
- 'id' => 'recipient_form'
- )
- );
- $url = api_get_path(WEB_AJAX_PATH).'dropbox.ajax.php?'.api_get_cidreq().'&a=upload_file&id=';
- $multipleForm->addHtml('<div id="multiple_form" style="display:none">');
- $multipleForm->addMultipleUpload($url);
- $multipleForm->addHtml('</div>');
- echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs');
- }
- /**
- * returns username or false if user isn't registered anymore
- * @todo check if this function is still necessary. There might be a library function for this.
- */
- function getUserNameFromId($id)
- {
- $dropbox_cnf = getDropboxConf();
- $mailingId = $id - dropbox_cnf('mailingIdBase');
- if ($mailingId > 0) {
- return get_lang('MailingAsUsername', '') . $mailingId;
- }
- $id = intval($id);
- $sql = "SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ', lastname)" : "CONCAT(lastname,' ', firstname)")." AS name
- FROM " . $dropbox_cnf['tbl_user'] . "
- WHERE user_id='$id'";
- $result = Database::query($sql);
- $res = Database::fetch_array($result);
- if (!$res) {
- return false;
- }
- return stripslashes($res['name']);
- }
- /**
- * returns loginname or false if user isn't registered anymore
- * @todo check if this function is still necessary. There might be a library function for this.
- */
- function getLoginFromId($id)
- {
- $id = intval($id);
- $sql = "SELECT username
- FROM " . dropbox_cnf('tbl_user') . "
- WHERE user_id='$id'";
- $result = Database::query($sql);
- $res = Database::fetch_array($result);
- if (!$res) return false;
- return stripslashes($res['username']);
- }
- /**
- * @param string $user_id
- * @return boolean indicating if user with user_id=$user_id is a course member
- * @todo check if this function is still necessary. There might be a library function for this.
- */
- function isCourseMember($user_id)
- {
- $_course = api_get_course_info();
- $course_code = $_course['code'];
- $is_course_member = CourseManager::is_user_subscribed_in_course($user_id, $course_code, true);
- return $is_course_member;
- }
- /**
- * Checks if there are files in the dropbox_file table that aren't used anymore in dropbox_person table.
- * If there are, all entries concerning the file are deleted from the db + the file is deleted from the server
- */
- function removeUnusedFiles()
- {
- $course_id = api_get_course_int_id();
- // select all files that aren't referenced anymore
- $sql = "SELECT DISTINCT f.id, f.filename
- FROM " . dropbox_cnf('tbl_file') . " f
- LEFT JOIN " . dropbox_cnf('tbl_person') . " p
- ON (f.id = p.file_id)
- WHERE p.user_id IS NULL AND
- f.c_id = $course_id
- ";
- $result = Database::query($sql);
- while ($res = Database::fetch_array($result)) {
- //delete the selected files from the post and file tables
- $sql = "DELETE FROM " . dropbox_cnf('tbl_post') . "
- WHERE c_id = $course_id AND file_id = '" . $res['id'] . "'";
- Database::query($sql);
- $sql = "DELETE FROM " . dropbox_cnf('tbl_file') . "
- WHERE c_id = $course_id AND id ='" . $res['id'] . "'";
- Database::query($sql);
- //delete file from server
- @unlink( dropbox_cnf('sysPath') . '/' . $res['filename']);
- }
- }
- /**
- *
- * Mailing zip-file is posted to (dest_user_id = ) mailing pseudo_id
- * and is only visible to its uploader (user_id).
- *
- * Mailing content files have uploader_id == mailing pseudo_id, a normal recipient,
- * and are visible initially to recipient and pseudo_id.
- *
- * @author René Haentjens, Ghent University
- *
- * @todo check if this function is still necessary.
- */
- function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '')
- {
- $course_id = api_get_course_int_id();
- $dropbox_cnf = getDropboxConf();
- $mailingPseudoId = intval($mailingPseudoId);
- $sql = "SELECT f.uploader_id
- FROM " . $dropbox_cnf['tbl_file'] . " f
- LEFT JOIN " . $dropbox_cnf['tbl_post'] . " p
- ON (f.id = p.file_id AND f.c_id = $course_id AND p.c_id = $course_id)
- WHERE
- p.dest_user_id = '" . $mailingPseudoId . "' AND
- p.c_id = $course_id
- ";
- $result = Database::query($sql);
- if (!($res = Database::fetch_array($result)))
- die(get_lang('GeneralError').' (code 901)');
- if ($owner == 0) return $res['uploader_id'];
- if ($res['uploader_id'] == $owner) return true;
- die(get_lang('GeneralError').' (code '.$or_die.')');
- }
- /**
- * @author René Haentjens, Ghent University
- * @todo check if this function is still necessary.
- */
- function removeMoreIfMailing($file_id)
- {
- $course_id = api_get_course_int_id();
- $dropbox_cnf = getDropboxConf();
- // when deleting a mailing zip-file (posted to mailingPseudoId):
- // 1. the detail window is no longer reachable, so
- // for all content files, delete mailingPseudoId from person-table
- // 2. finding the owner (getUserOwningThisMailing) is no longer possible, so
- // for all content files, replace mailingPseudoId by owner as uploader
- $file_id = intval($file_id);
- $sql = "SELECT p.dest_user_id
- FROM " . $dropbox_cnf['tbl_post'] . " p
- WHERE c_id = $course_id AND p.file_id = '" . $file_id . "'";
- $result = Database::query($sql);
- if ($res = Database::fetch_array($result)) {
- $mailingPseudoId = $res['dest_user_id'];
- if ($mailingPseudoId > dropbox_cnf('mailingIdBase')) {
- $sql = "DELETE FROM " . dropbox_cnf('tbl_person') . "
- WHERE c_id = $course_id AND user_id='" . $mailingPseudoId . "'";
- Database::query($sql);
- $sql = "UPDATE " . dropbox_cnf('tbl_file') ."
- SET uploader_id='" . api_get_user_id() . "'
- WHERE c_id = $course_id AND uploader_id='" . $mailingPseudoId . "'";
- Database::query($sql);
- }
- }
- }
- /**
- * Function that finds a given config setting
- *
- * @author René Haentjens, Ghent University
- */
- function dropbox_cnf($variable)
- {
- $dropbox_cnf = getDropboxConf();
- return $dropbox_cnf[$variable];
- }
- /**
- * @param array $file
- *
- * @return array|null|string
- */
- function store_add_dropbox($file = [])
- {
- $_course = api_get_course_info();
- $_user = api_get_user_info();
- $dropbox_cnf = getDropboxConf();
- if (empty($file)) {
- $file = isset($_FILES['file']) ? $_FILES['file'] : null;
- }
- // Validating the form data
- // there are no recipients selected
- if (!isset($_POST['recipients']) || count($_POST['recipients']) <= 0) {
- return get_lang('YouMustSelectAtLeastOneDestinee');
- } else {
- // Check if all the recipients are valid
- $thisIsAMailing = false;
- $thisIsJustUpload = false;
- foreach ($_POST['recipients'] as $rec) {
- if ($rec == 'mailing') {
- $thisIsAMailing = true;
- } elseif ($rec == 'upload') {
- $thisIsJustUpload = true;
- } elseif (strpos($rec, 'user_') === 0 && !isCourseMember(substr($rec, strlen('user_')))) {
- Display::addFlash(Display::return_message(get_lang('InvalideUserDetected'), 'warning'));
- return false;
- } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) {
- Display::addFlash(Display::return_message(get_lang('InvalideGroupDetected'), 'warning'));
- return false;
- }
- }
- }
- // we are doing a mailing but an additional recipient is selected
- if ($thisIsAMailing && (count($_POST['recipients']) != 1)) {
- Display::addFlash(Display::return_message(get_lang('MailingSelectNoOther'), 'warning'));
- return false;
- }
- // we are doing a just upload but an additional recipient is selected.
- // note: why can't this be valid? It is like sending a document to
- // yourself AND to a different person (I do this quite often with my e-mails)
- if ($thisIsJustUpload && (count($_POST['recipients']) != 1)) {
- Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning'));
- return false;
- }
- if (empty($file['name'])) {
- Display::addFlash(Display::return_message(get_lang('NoFileSpecified'), 'warning'));
- return false;
- }
- // are we overwriting a previous file or sending a new one
- $dropbox_overwrite = false;
- if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) {
- $dropbox_overwrite = true;
- }
- // doing the upload
- $dropbox_filename = $file['name'];
- $dropbox_filesize = $file['size'];
- $dropbox_filetype = $file['type'];
- $dropbox_filetmpname = $file['tmp_name'];
- // check if the filesize does not exceed the allowed size.
- if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) {
- Display::addFlash(Display::return_message(get_lang('DropboxFileTooBig'), 'warning'));
- return false;
- }
- // check if the file is actually uploaded
- if (!is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg.
- Display::addFlash(Display::return_message(get_lang('TheFileIsNotUploaded'), 'warning'));
- return false;
- }
- $upload_ok = process_uploaded_file($file, true);
- if (!$upload_ok) {
- return null;
- }
- // Try to add an extension to the file if it hasn't got one
- $dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
- // Replace dangerous characters
- $dropbox_filename = api_replace_dangerous_char($dropbox_filename);
- // Transform any .php file in .phps fo security
- $dropbox_filename = php2phps($dropbox_filename);
- //filter extension
- if (!filter_extension($dropbox_filename)) {
- Display::addFlash(Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'warning'));
- return false;
- }
- // set title
- $dropbox_title = $dropbox_filename;
- // set author
- if (!isset($_POST['authors'])) {
- $_POST['authors'] = getUserNameFromId($_user['user_id']);
- }
- // note: I think we could better migrate everything from here on to
- // separate functions: store_new_dropbox, store_new_mailing, store_just_upload
- if ($dropbox_overwrite) {
- $dropbox_person = new Dropbox_Person(
- $_user['user_id'],
- api_is_course_admin(),
- api_is_course_tutor()
- );
- foreach ($dropbox_person->sentWork as $w) {
- if ($w->title == $dropbox_filename) {
- if (($w->recipients[0]['id'] > dropbox_cnf('mailingIdBase')) xor $thisIsAMailing) {
- Display::addFlash(Display::return_message(get_lang('MailingNonMailingError'), 'warning'));
- return false;
- }
- if (($w->recipients[0]['id'] == $_user['user_id']) xor $thisIsJustUpload) {
- Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning'));
- return false;
- }
- $dropbox_filename = $w->filename;
- $found = true; // note: do we still need this?
- break;
- }
- }
- } else { // rename file to login_filename_uniqueId format
- $dropbox_filename = getLoginFromId($_user['user_id']) . "_" . $dropbox_filename . "_".uniqid('');
- }
- // creating the array that contains all the users who will receive the file
- $new_work_recipients = array();
- foreach ($_POST['recipients'] as $rec) {
- if (strpos($rec, 'user_') === 0) {
- $new_work_recipients[] = substr($rec, strlen('user_'));
- } elseif (strpos($rec, 'group_') === 0) {
- $userList = GroupManager::get_subscribed_users(substr($rec, strlen('group_')));
- foreach ($userList as $usr) {
- if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
- $new_work_recipients[] = $usr['user_id'];
- }
- }
- }
- }
- @move_uploaded_file($dropbox_filetmpname, dropbox_cnf('sysPath') . '/' . $dropbox_filename);
- $b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox');
- if ($b_send_mail) {
- foreach ($new_work_recipients as $recipient_id) {
- $recipent_temp = api_get_user_info($recipient_id);
- $additionalParameters = array(
- 'smsType' => SmsPlugin::NEW_FILE_SHARED_COURSE_BY,
- 'userId' => $recipient_id,
- 'courseTitle' => $_course['title'],
- 'userUsername' => $recipent_temp['username']
- );
- api_mail_html(
- api_get_person_name(
- $recipent_temp['firstname'].' '.$recipent_temp['lastname'],
- null,
- PERSON_NAME_EMAIL_ADDRESS
- ),
- $recipent_temp['email'],
- get_lang('NewDropboxFileUploaded'),
- get_lang('NewDropboxFileUploadedContent').' <a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?' . api_get_cidreq() . '">'.get_lang('SeeFile').'</a>'.
- "\n\n".
- api_get_person_name(
- $_user['firstName'],
- $_user['lastName'],
- null,
- PERSON_NAME_EMAIL_ADDRESS
- )."\n". get_lang('Email') ." : ".$_user['mail'],
- api_get_person_name(
- $_user['firstName'],
- $_user['lastName'],
- null,
- PERSON_NAME_EMAIL_ADDRESS
- ),
- $_user['mail'],
- null,
- null,
- null,
- $additionalParameters
- );
- }
- }
- $result = new Dropbox_SentWork(
- $_user['user_id'],
- $dropbox_title,
- isset($_POST['description']) ? $_POST['description'] : '',
- strip_tags($_POST['authors']),
- $dropbox_filename,
- $dropbox_filesize,
- $new_work_recipients
- );
- Security::clear_token();
- Display::addFlash(Display::return_message(get_lang('FileUploadSucces')));
- return $result;
- }
- /**
- * Transforms the array containing all the feedback into something visually attractive.
- *
- * @param an array containing all the feedback about the given message.
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function feedback($array) {
- $output = null;
- foreach ($array as $value) {
- $output .= format_feedback($value);
- }
- $output .= feedback_form();
- return $output;
- }
- /**
- * This function returns the html code to display the feedback messages on a given dropbox file
- * @param $feedback_array an array that contains all the feedback messages about the given document.
- * @return string code
- * @todo add the form for adding new comment (if the other party has not deleted it yet).
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function format_feedback($feedback)
- {
- $userInfo = api_get_user_info($feedback['author_user_id']);
- $output = UserManager::getUserProfileLink($userInfo);
- $output .= ' '.api_convert_and_format_date($feedback['feedback_date'], DATE_TIME_FORMAT_LONG).'<br />';
- $output .= '<div style="padding-top:6px">'.nl2br($feedback['feedback']).'</div><hr size="1" noshade/><br />';
- 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 <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function feedback_form()
- {
- $return = get_lang('AddNewFeedback').'<br />';
- $number_users_who_see_file = check_if_file_exist($_GET['id']);
- if ($number_users_who_see_file) {
- $token = Security::get_token();
- $return .= '<textarea name="feedback" style="width: 80%; height: 80px;"></textarea>';
- $return .= '<input type="hidden" name="sec_token" value="'.$token.'"/>';
- $return .= '<br /><button type="submit" class="add" name="store_feedback" value="'.get_lang('Ok').'"
- onclick="javascript: document.form_dropbox.attributes.action.value = document.location;">'.get_lang('AddComment').'</button>';
- } else {
- $return .= get_lang('AllUsersHaveDeletedTheFileAndWillNotSeeFeedback');
- }
- return $return;
- }
- function user_can_download_file($id, $user_id)
- {
- $dropbox_cnf = getDropboxConf();
- $course_id = api_get_course_int_id();
- $id = intval($id);
- $user_id = intval($user_id);
- $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_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 ".$dropbox_cnf["tbl_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)
- {
- $dropbox_cnf = getDropboxConf();
- $id = intval($id);
- $course_id = api_get_course_int_id();
- $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_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 ".$dropbox_cnf["tbl_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 <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function store_feedback()
- {
- $dropbox_cnf = getDropboxConf();
- 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($dropbox_cnf['tbl_feedback'], $params);
- if ($id) {
- $sql = "UPDATE ".$dropbox_cnf['tbl_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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, Ghent University
- * @author Julio Montoya Addin c_id support
- * @version march 2006
- */
- function zip_download($fileList)
- {
- $_course = api_get_course_info();
- $dropbox_cnf = getDropboxConf();
- $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 ".$dropbox_cnf['tbl_file']." file
- INNER JOIN ".$dropbox_cnf['tbl_person']." person
- ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
- INNER JOIN ".$dropbox_cnf['tbl_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';
- DocumentManager::file_send_for_download($temp_zip_file, true, $name);
- @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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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 = '<!DOCTYPE html'."\n";
- $return .= "\t".'PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'."\n";
- $return .= "\t".'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
- $return .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.api_get_language_isocode().'" lang="'.api_get_language_isocode().'">'."\n";
- $return .= "<head>\n\t<title>".get_lang('OverviewOfFilesInThisZip')."</title>\n";
- $return .= "\t".'<meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />'."\n";
- $return .= "</head>\n\n";
- $return .= '<body dir="'.api_get_text_direction().'">'."\n\n";
- $return .= "<table border=\"1px\">\n";
- $counter = 0;
- foreach ($files as $value) {
- // Adding the header.
- if ($counter == 0) {
- $columns_array = array_keys($value);
- $return .= "\n<tr>";
- foreach ($columns_array as $columns_array_key => $columns_array_value) {
- if (!in_array($columns_array_value, $dont_show_columns)) {
- $return .= "\n\t<th>".$columns_array_value."</th>";
- }
- $column[] = $columns_array_value;
- }
- $return .= "\n</tr>\n";
- }
- $counter++;
- // Adding the content.
- $return .= "\n<tr>";
- foreach ($column as $column_key => $column_value) {
- if (!in_array($column_value,$dont_show_columns)) {
- $return .= "\n\t<td>";
- if (in_array($column_value, $make_link)) {
- $return .= '<a href="'.$value[$column_value].'">'.$value[$column_value].'</a>';
- } else {
- $return .= $value[$column_value];
- }
- $return .= "</td>";
- }
- }
- $return .= "\n</tr>\n";
- }
- $return .= "\n</table>\n\n</body>";
- $return .= "\n</html>";
- 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 <patrick.cool@UGent.be>, Ghent University
- * @version march 2006
- */
- function get_total_number_feedback($file_id = '')
- {
- $dropbox_cnf = getDropboxConf();
- $course_id = api_get_course_int_id();
- $sql = "SELECT COUNT(feedback_id) AS total, file_id
- FROM ".$dropbox_cnf['tbl_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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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'];
- }
|