diff --git a/main/auth/inscription.php b/main/auth/inscription.php index 68f6fb707b..520a85e61d 100755 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -2,8 +2,8 @@ /* For licensing terms, see /license.txt */ /** - * This script displays a form for registering new users. - * @package chamilo.auth + * This script displays a form for registering new users. + * @package chamilo.auth */ use \ChamiloSession as Session; @@ -51,11 +51,11 @@ if (!empty($course_code_redirect)) { if ($user_already_registered_show_terms == false) { if (api_is_western_name_order()) { - // FIRST NAME and LAST NAME + // FIRST NAME and LAST NAME $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40)); $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40)); } else { - // LAST NAME and FIRST NAME + // LAST NAME and FIRST NAME $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40)); $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40)); } @@ -63,7 +63,7 @@ if ($user_already_registered_show_terms == false) { $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); - // EMAIL + // EMAIL $form->addElement('text', 'email', get_lang('Email'), array('size' => 40)); if (api_get_setting('registration', 'email') == 'true') { $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required'); @@ -83,14 +83,14 @@ if ($user_already_registered_show_terms == false) { $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40)); } // Enabled by Ivan Tcholakov, 06-APR-2009. CONFVAL_ASK_FOR_OFFICIAL_CODE = false by default. - // OFFICIAL CODE + // OFFICIAL CODE if (CONFVAL_ASK_FOR_OFFICIAL_CODE) { $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40)); if (api_get_setting('registration', 'officialcode') == 'true') $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required'); } - // USERNAME + // USERNAME if (api_get_setting('login_is_email') != 'true') { $form->addElement('text', 'username', get_lang('UserName'), array('id' => 'username', 'size' => USERNAME_MAX_LENGTH)); $form->applyFilter('username','trim'); @@ -100,7 +100,7 @@ if ($user_already_registered_show_terms == false) { $form->addRule('username', get_lang('UserTaken'), 'username_available'); } - // PASSWORD + // PASSWORD $form->addElement('password', 'pass1', get_lang('Pass'), array('id' => 'pass1', 'size' => 20, 'autocomplete' => 'off')); if (isset($_configuration['allow_strength_pass_checker']) && $_configuration['allow_strength_pass_checker']) { @@ -115,7 +115,7 @@ if ($user_already_registered_show_terms == false) { if (CHECK_PASS_EASY_TO_FIND) $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password'); - // PHONE + // PHONE $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20)); if (api_get_setting('registration', 'phone') == 'true') $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required'); @@ -127,11 +127,11 @@ if ($user_already_registered_show_terms == false) { $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); }*/ - // LANGUAGE + // LANGUAGE if (api_get_setting('registration', 'language') == 'true') { $form->addElement('select_language', 'language', get_lang('Language')); } - // STUDENT/TEACHER + // STUDENT/TEACHER if (api_get_setting('allow_registration_as_teacher') != 'false') { $form->addElement('radio', 'status', get_lang('Profile'), get_lang('RegStudent'), STUDENT); $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER); @@ -165,7 +165,7 @@ if ($user_already_registered_show_terms == false) { $form->addRule('captcha', get_lang('TheTextYouEnteredDoesNotMatchThePicture'), 'CAPTCHA', $captcha_question); } - // EXTENDED FIELDS + // EXTENDED FIELDS if (api_get_setting('extended_profile') == 'true' && api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true') { $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130')); } @@ -485,26 +485,26 @@ if ($form->validate()) { Database::query($sql); // 2. Send mail to all platform admin - $emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username']; - $emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n"; - $emailbody .= get_lang('UserName',null,$values['language']).': '.$values['username']."\n"; + $emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username']; + $emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n"; + $emailbody .= get_lang('UserName',null,$values['language']).': '.$values['username']."\n"; if (api_is_western_name_order()) { - $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; - $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; + $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; + $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; } else { - $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; - $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; + $emailbody .= get_lang('LastName',null,$values['language']).': '.$values['lastname']."\n"; + $emailbody .= get_lang('FirstName',null,$values['language']).': '.$values['firstname']."\n"; } - $emailbody .= get_lang('Email',null,$values['language']).': '.$values['email']."\n"; - $emailbody .= get_lang('Status',null,$values['language']).': '.$values['status']."\n\n"; + $emailbody .= get_lang('Email',null,$values['language']).': '.$values['email']."\n"; + $emailbody .= get_lang('Status',null,$values['language']).': '.$values['status']."\n\n"; $url_edit = Display::url( api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id, api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user_id ); - $emailbody .= get_lang('ManageUser',null,$values['language']).": $url_edit"; + $emailbody .= get_lang('ManageUser',null,$values['language']).": $url_edit"; $admins = UserManager::get_all_administrators(); foreach ($admins as $admin_info) { @@ -551,10 +551,10 @@ if ($form->validate()) { /* SESSION REGISTERING */ /* @todo move this in a function */ $_user['firstName'] = stripslashes($values['firstname']); - $_user['lastName'] = stripslashes($values['lastname']); - $_user['mail'] = $values['email']; - $_user['language'] = $values['language']; - $_user['user_id'] = $user_id; + $_user['lastName'] = stripslashes($values['lastname']); + $_user['mail'] = $values['email']; + $_user['language'] = $values['language']; + $_user['user_id'] = $user_id; $is_allowedCreateCourse = $values['status'] == 1; $usersCanCreateCourse = (api_get_setting('allow_users_to_create_courses') == 'true'); diff --git a/main/dropbox/dropbox_functions.inc.php b/main/dropbox/dropbox_functions.inc.php index 3625b0cc22..84d9f93efe 100755 --- a/main/dropbox/dropbox_functions.inc.php +++ b/main/dropbox/dropbox_functions.inc.php @@ -4,7 +4,7 @@ /** * 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 , Ghent University +* to one file -- Patrick Cool , Ghent University * @author Julio Montoya adding c_id support */ use \ChamiloSession as Session; @@ -22,9 +22,9 @@ $(document).ready(function () { /** * This function is a wrapper function for the multiple actions feature. -* @return Mixed If there is a problem, return a string message, otherwise nothing -* @author Patrick Cool , Ghent University -* @version march 2006 +* @return Mixed If there is a problem, return a string message, otherwise nothing +* @author Patrick Cool , Ghent University +* @version march 2006 */ function handle_multiple_actions() { @@ -140,39 +140,39 @@ function delete_category($action, $id, $user_id = null) 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; + // 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; } /** @@ -187,14 +187,14 @@ function display_move_form($part, $id, $target = array(), $extra_params = array( 'post', api_get_self().'?view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&'.$extra_params ); - $form->addElement('header', get_lang('MoveFileTo')); + $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) { + 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(); @@ -218,26 +218,26 @@ function store_move($id, $target, $part) $dropbox_cnf = getDropboxConf(); $course_id = api_get_course_int_id(); - if ((isset($id) AND $id != '') AND (isset($target) AND $target != '') AND (isset($part) AND $part != '')) { - - if ($part == 'received') { - $sql = "UPDATE ".$dropbox_cnf["tbl_post"]." SET cat_id='".Database::escape_string($target)."' - WHERE c_id = $course_id AND dest_user_id='".Database::escape_string($_user['user_id'])."' - AND file_id='".Database::escape_string($id)."'"; - Database::query($sql); - $return_message = get_lang('ReceivedFileMoved'); - } - if ($part == 'sent') { - $sql = "UPDATE ".$dropbox_cnf["tbl_file"]." SET cat_id='".Database::escape_string($target)."' - WHERE c_id = $course_id AND uploader_id='".Database::escape_string($_user['user_id'])."' - AND id='".Database::escape_string($id)."'"; - Database::query($sql); - $return_message = get_lang('SentFileMoved'); - } - } else { - $return_message = get_lang('NotMovedError'); - } - return $return_message; + if ((isset($id) AND $id != '') AND (isset($target) AND $target != '') AND (isset($part) AND $part != '')) { + + if ($part == 'received') { + $sql = "UPDATE ".$dropbox_cnf["tbl_post"]." SET cat_id='".Database::escape_string($target)."' + WHERE c_id = $course_id AND dest_user_id='".Database::escape_string($_user['user_id'])."' + AND file_id='".Database::escape_string($id)."'"; + Database::query($sql); + $return_message = get_lang('ReceivedFileMoved'); + } + if ($part == 'sent') { + $sql = "UPDATE ".$dropbox_cnf["tbl_file"]." SET cat_id='".Database::escape_string($target)."' + WHERE c_id = $course_id AND uploader_id='".Database::escape_string($_user['user_id'])."' + AND id='".Database::escape_string($id)."'"; + Database::query($sql); + $return_message = get_lang('SentFileMoved'); + } + } else { + $return_message = get_lang('NotMovedError'); + } + return $return_message; } /** @@ -251,23 +251,23 @@ function store_move($id, $target, $part) */ function display_action_options($part, $categories, $current_category = 0) { - echo ''; - echo ''; + echo ''; + echo ''; } /** @@ -283,11 +283,11 @@ function display_action_options($part, $categories, $current_category = 0) * @version march 2006 */ function display_file_checkbox($id, $part) { - if (isset($_GET['selectall'])) { - $checked = 'checked'; - } - $return_value = ''; - return $return_value; + if (isset($_GET['selectall'])) { + $checked = 'checked'; + } + $return_value = ''; + return $return_value; } /** @@ -305,21 +305,21 @@ function get_dropbox_categories($filter = '') $course_id = api_get_course_int_id(); $_user = api_get_user_info(); $dropbox_cnf = getDropboxConf(); - $return_array = array(); + $return_array = array(); - $session_id = api_get_session_id(); - $condition_session = api_get_session_condition($session_id); + $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"; + $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' AND $row['sent'] == 1) OR ($filter == 'received' AND $row['received'] == 1) OR $filter == '') { - $return_array[$row['cat_id']] = $row; - } - } + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + if (($filter == 'sent' AND $row['sent'] == 1) OR ($filter == 'received' AND $row['received'] == 1) OR $filter == '') { + $return_array[$row['cat_id']] = $row; + } + } - return $return_array; + return $return_array; } /** @@ -344,13 +344,13 @@ function get_dropbox_category($id) /** * 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 +* @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 , Ghent University * @version march 2006 @@ -361,44 +361,44 @@ function store_addcategory() $_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) { - $sql = "INSERT INTO ".$dropbox_cnf['tbl_category']." (c_id, cat_name, received, sent, user_id, session_id) - VALUES ($course_id, '".Database::escape_string($_POST['category_name'])."', '".Database::escape_string($received)."', '".Database::escape_string($sent)."', '".Database::escape_string($_user['user_id'])."',$session_id)"; - Database::query($sql); - return array('type' => 'confirmation', 'message' => get_lang('CategoryStored')); - } else { - return array('type' => 'error', 'message' => get_lang('CategoryAlreadyExistsEditIt')); - } - } else { - $sql = "UPDATE ".$dropbox_cnf['tbl_category']." SET cat_name='".Database::escape_string($_POST['category_name'])."', received='".Database::escape_string($received)."' , sent='".Database::escape_string($sent)."' - WHERE c_id = $course_id AND user_id='".Database::escape_string($_user['user_id'])."' - AND cat_id='".Database::escape_string($_POST['edit_id'])."'"; - Database::query($sql); - return array('type' => 'confirmation', 'message' => get_lang('CategoryModified')); - } + // 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) { + $sql = "INSERT INTO ".$dropbox_cnf['tbl_category']." (c_id, cat_name, received, sent, user_id, session_id) + VALUES ($course_id, '".Database::escape_string($_POST['category_name'])."', '".Database::escape_string($received)."', '".Database::escape_string($sent)."', '".Database::escape_string($_user['user_id'])."',$session_id)"; + Database::query($sql); + return array('type' => 'confirmation', 'message' => get_lang('CategoryStored')); + } else { + return array('type' => 'error', 'message' => get_lang('CategoryAlreadyExistsEditIt')); + } + } else { + $sql = "UPDATE ".$dropbox_cnf['tbl_category']." SET cat_name='".Database::escape_string($_POST['category_name'])."', received='".Database::escape_string($received)."' , sent='".Database::escape_string($sent)."' + WHERE c_id = $course_id AND user_id='".Database::escape_string($_user['user_id'])."' + AND cat_id='".Database::escape_string($_POST['edit_id'])."'"; + Database::query($sql); + return array('type' => 'confirmation', 'message' => get_lang('CategoryModified')); + } } /** @@ -416,47 +416,47 @@ 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) AND $id != '') { - // retrieve the category we are editing - $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND cat_id='".Database::escape_string($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'); - $class = 'save'; - } elseif ($action == 'addreceivedcategory' or $action == 'addsentcategory') { - $text = get_lang('CreateCategory'); - $class = 'add'; - } + $title = get_lang('AddNewCategory'); + + if (isset($id) AND $id != '') { + // retrieve the category we are editing + $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND cat_id='".Database::escape_string($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'); + $class = 'save'; + } elseif ($action == 'addreceivedcategory' or $action == 'addsentcategory') { + $text = get_lang('CreateCategory'); + $class = 'add'; + } $form = new FormValidator('add_new_category', 'post', api_get_self().'?view='.Security::remove_XSS($_GET['view'])); $form->addElement('header', $title); - if (isset($id) AND $id != '') { + if (isset($id) AND $id != '') { $form->addElement('hidden', 'edit_id', intval($id)); - } + } $form->addElement('hidden', 'action', Security::remove_XSS($action)); $form->addElement('hidden', 'target', Security::remove_XSS($target)); @@ -485,7 +485,7 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor $origin = isset($_GET['origin']) ? $_GET['origin'] : null; $token = Security::get_token(); - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); + $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); $form = new FormValidator( 'sent_form', @@ -502,78 +502,78 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor $form->addElement('hidden', 'origin', $origin); $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);')); - if (dropbox_cnf('allowOverwrite')) { + 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()); - } - $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id()); - $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $complete_user_list2); - } 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); - } - } + } + + // 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()); + } + $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id()); + $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $complete_user_list2); + } 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'); + 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 - */ + /* + 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 = ''; + $current_user_id = ''; $options = array(); - 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['tutor_id'] == 1 // Always allow tutors. - ) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself. - if ($current_user['user_id'] == $current_user_id) { - continue; - } - $full_name = $current_user['lastcommafirst']; - $current_user_id = $current_user['user_id']; + 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['tutor_id'] == 1 // Always allow tutors. + ) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself. + if ($current_user['user_id'] == $current_user_id) { + continue; + } + $full_name = $current_user['lastcommafirst']; + $current_user_id = $current_user['user_id']; $options['user_' . $current_user_id] = $full_name; - //echo ''; - } - } + //echo ''; + } + } - /* - * Show groups - */ + /* + * 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')); + && 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) { - //echo ''; + if (count($complete_group_list_for_dropbox) > 0) { + foreach ($complete_group_list_for_dropbox as $current_group) { + if ($current_group['number_of_members'] > 0) { + //echo ''; $options['group_'.$current_group['id']] = 'G: '.$current_group['name'].' - '.$current_group['number_of_members'].' '.get_lang('Users'); - } - } - } + } + } + } } if (dropbox_cnf('allowJustUpload')) { - //echo ''; - //echo ''; + //echo ''; + //echo ''; $options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect'); } @@ -592,12 +592,12 @@ function getUserNameFromId($id) $mailingId = $id - dropbox_cnf('mailingIdBase'); if ($mailingId > 0) { - return get_lang('MailingAsUsername', '') . $mailingId; + 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'"; + FROM " . $dropbox_cnf['tbl_user'] . " + WHERE user_id='$id'"; $result = Database::query($sql); $res = Database::fetch_array($result); @@ -613,8 +613,8 @@ function getLoginFromId($id) { $id = intval($id); $sql = "SELECT username - FROM " . dropbox_cnf('tbl_user') . " - WHERE user_id='$id'"; + FROM " . dropbox_cnf('tbl_user') . " + WHERE user_id='$id'"; $result = Database::query($sql); $res = Database::fetch_array($result); if (!$res) return false; @@ -628,9 +628,9 @@ function getLoginFromId($id) 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; + $course_code = $_course['code']; + $is_course_member = CourseManager::is_user_subscribed_in_course($user_id, $course_code, true); + return $is_course_member; } /** @@ -643,20 +643,20 @@ function removeUnusedFiles() // 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 + 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 + 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 + //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 + //delete file from server @unlink( dropbox_cnf('sysPath') . '/' . $res['filename']); } } @@ -680,9 +680,9 @@ function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '') $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 + 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 "; @@ -710,19 +710,19 @@ function removeMoreIfMailing($file_id) // 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 . "'"; + 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); + $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); } } } @@ -748,67 +748,67 @@ function store_add_dropbox() $_user = api_get_user_info(); $dropbox_cnf = getDropboxConf(); - // Validating the form data + // Validating the form data // there are no recipients selected - if (!isset($_POST['recipients']) || count( $_POST['recipients']) <= 0) { + 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_')))) { - return get_lang('InvalideUserDetected'); - } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) { - return get_lang('InvalideGroupDetected'); - } + 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_')))) { + return get_lang('InvalideUserDetected'); + } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) { + return get_lang('InvalideGroupDetected'); + } } } - // we are doing a mailing but an additional recipient is selected - if ($thisIsAMailing && (count($_POST['recipients']) != 1)) { - return get_lang('MailingSelectNoOther'); - } + // we are doing a mailing but an additional recipient is selected + if ($thisIsAMailing && (count($_POST['recipients']) != 1)) { + return get_lang('MailingSelectNoOther'); + } - // 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)) { - return get_lang('MailingJustUploadSelectNoOther'); - } + // 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)) { + return get_lang('MailingJustUploadSelectNoOther'); + } - if (empty($_FILES['file']['name'])) { - $error = true; - return get_lang('NoFileSpecified'); - } + if (empty($_FILES['file']['name'])) { + $error = true; + return get_lang('NoFileSpecified'); + } - // are we overwriting a previous file or sending a new one + // 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; - } + $dropbox_overwrite = false; + if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) { + $dropbox_overwrite = true; + } - // doing the upload + // doing the upload - $dropbox_filename = $_FILES['file']['name']; - $dropbox_filesize = $_FILES['file']['size']; - $dropbox_filetype = $_FILES['file']['type']; - $dropbox_filetmpname = $_FILES['file']['tmp_name']; + $dropbox_filename = $_FILES['file']['name']; + $dropbox_filesize = $_FILES['file']['size']; + $dropbox_filetype = $_FILES['file']['type']; + $dropbox_filetmpname = $_FILES['file']['tmp_name']; - // check if the filesize does not exceed the allowed size. - if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) { - return get_lang('DropboxFileTooBig'); // TODO: The "too big" message does not fit in the case of uploading zero-sized file. - } + // check if the filesize does not exceed the allowed size. + if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) { + return get_lang('DropboxFileTooBig'); // TODO: The "too big" message does not fit in the case of uploading zero-sized file. + } - // check if the file is actually uploaded - if (!is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg. - return get_lang('TheFileIsNotUploaded'); - } + // check if the file is actually uploaded + if (!is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg. + return get_lang('TheFileIsNotUploaded'); + } $upload_ok = process_uploaded_file($_FILES['file'], true); @@ -816,84 +816,84 @@ function store_add_dropbox() 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 = replace_dangerous_char($dropbox_filename); - // Transform any .php file in .phps fo security - $dropbox_filename = php2phps($dropbox_filename); + // 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 = replace_dangerous_char($dropbox_filename); + // Transform any .php file in .phps fo security + $dropbox_filename = php2phps($dropbox_filename); - //filter extension + //filter extension if (!filter_extension($dropbox_filename)) { - return get_lang('UplUnableToSaveFileFilteredExtension'); + return get_lang('UplUnableToSaveFileFilteredExtension'); + } + + // 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) { + return get_lang('MailingNonMailingError'); + } + if (($w->recipients[0]['id'] == $_user['user_id']) xor $thisIsJustUpload) { + return get_lang('MailingJustUploadSelectNoOther'); + } + $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']; + } + } + } } - // 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) { - return get_lang('MailingNonMailingError'); - } - if (($w->recipients[0]['id'] == $_user['user_id']) xor $thisIsJustUpload) { - return get_lang('MailingJustUploadSelectNoOther'); - } - $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 = UserManager :: get_user_info_by_id($recipient_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 = UserManager :: get_user_info_by_id($recipient_id); $additional_parameters = array( - 'smsType' => 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').' '.api_get_path(WEB_CODE_PATH).'dropbox/index.php?cidReq='.$_course['sysCode']."\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, $additional_parameters); - } - } - - new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $new_work_recipients); - - Security::clear_token(); + 'smsType' => 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').' '.api_get_path(WEB_CODE_PATH).'dropbox/index.php?cidReq='.$_course['sysCode']."\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, $additional_parameters); + } + } + + new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $new_work_recipients); + + Security::clear_token(); return get_lang('FileUploadSucces'); } @@ -910,20 +910,20 @@ function store_add_dropbox() * @version march 2006 */ function display_user_link_work($user_id, $name = '') { - if ($user_id != 0) { - if (empty($name)) { - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $sql = "SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'"; - $result = Database::query($sql); - $row = Database::fetch_array($result); - return ''.api_get_person_name($row['firstname'], $row['lastname']).''; - } else { + if ($user_id != 0) { + if (empty($name)) { + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $sql = "SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'"; + $result = Database::query($sql); + $row = Database::fetch_array($result); + return ''.api_get_person_name($row['firstname'], $row['lastname']).''; + } else { $user_id = intval($user_id); - return ''.Security::remove_XSS($name).''; - } - } else { - return $name.' ('.get_lang('Anonymous').')'; - } + return ''.Security::remove_XSS($name).''; + } + } else { + return $name.' ('.get_lang('Anonymous').')'; + } } /** @@ -936,11 +936,11 @@ function display_user_link_work($user_id, $name = '') { */ function feedback($array) { $output = null; - foreach ($array as $value) { - $output .= format_feedback($value); - } - $output .= feedback_form(); - return $output; + foreach ($array as $value) { + $output .= format_feedback($value); + } + $output .= feedback_form(); + return $output; } /** @@ -954,10 +954,10 @@ function feedback($array) { */ function format_feedback($feedback) { - $output = display_user_link_work($feedback['author_user_id']); - $output .= '  '.api_convert_and_format_date($feedback['feedback_date'], DATE_TIME_FORMAT_LONG).'
'; - $output .= '
'.nl2br($feedback['feedback']).'


'; - return $output; + $output = display_user_link_work($feedback['author_user_id']); + $output .= '  '.api_convert_and_format_date($feedback['feedback_date'], DATE_TIME_FORMAT_LONG).'
'; + $output .= '
'.nl2br($feedback['feedback']).'


'; + return $output; } /** @@ -969,18 +969,18 @@ function format_feedback($feedback) */ 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; + $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) { @@ -990,28 +990,28 @@ function user_can_download_file($id, $user_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); + $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); + $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. +// 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); + $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); + $count = Database::num_rows($result); return $number_users_who_see_file > 0 || $count > 0; } @@ -1026,18 +1026,18 @@ function check_if_file_exist($id) { 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 { - $sql="INSERT INTO ".$dropbox_cnf['tbl_feedback']." (c_id, file_id, author_user_id, feedback, feedback_date) VALUES - ($course_id, '".intval($_GET['id'])."','".api_get_user_id()."','".Database::escape_string($_POST['feedback'])."', '".api_get_utc_datetime()."')"; - Database::query($sql); - return get_lang('DropboxFeedbackStored'); - } + 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 { + $sql="INSERT INTO ".$dropbox_cnf['tbl_feedback']." (c_id, file_id, author_user_id, feedback, feedback_date) VALUES + ($course_id, '".intval($_GET['id'])."','".api_get_user_id()."','".Database::escape_string($_POST['feedback'])."', '".api_get_utc_datetime()."')"; + Database::query($sql); + return get_lang('DropboxFeedbackStored'); + } } /** @@ -1053,54 +1053,54 @@ function store_feedback() */ function zip_download($fileList) { - $_course = api_get_course_info(); + $_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 + // 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 + 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); + $result = Database::query($sql); - $files = array(); - while ($row = Database::fetch_array($result)) { - $files[$row['filename']] = array( + $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"; + // 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 = 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; + $name = 'dropbox-'.api_get_utc_datetime().'.zip'; + DocumentManager::file_send_for_download($temp_zip_file, true, $name); + @unlink($temp_zip_file); + exit; } /** @@ -1114,84 +1114,84 @@ function zip_download($fileList) 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; + $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, ...) + * 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"; - } - $column[] = $columns_array_value; - } - $return .= "\n\n"; - } - $counter++; - - // Adding the content. - $return .= "\n"; - foreach ($column as $column_key => $column_value) { - if (!in_array($column_value,$dont_show_columns)) { - $return .= "\n\t"; - } - } - $return .= "\n\n"; - } - $return .= "\n
".$columns_array_value."
"; - if (in_array($column_value, $make_link)) { - $return .= ''.$value[$column_value].''; - } else { - $return .= $value[$column_value]; - } - $return .= "
\n\n"; - $return .= "\n"; - - return $return; + $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"; + } + $column[] = $columns_array_value; + } + $return .= "\n\n"; + } + $counter++; + + // Adding the content. + $return .= "\n"; + foreach ($column as $column_key => $column_value) { + if (!in_array($column_value,$dont_show_columns)) { + $return .= "\n\t"; + } + } + $return .= "\n\n"; + } + $return .= "\n
".$columns_array_value."
"; + if (in_array($column_value, $make_link)) { + $return .= ''.$value[$column_value].''; + } else { + $return .= $value[$column_value]; + } + $return .= "
\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. +* the feedback becomes user individual. * @author Patrick Cool , 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); + $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; + while ($row=Database::fetch_array($result)) { + $return[$row['file_id']] = $row['total']; + } + return $return; } @@ -1201,15 +1201,15 @@ function get_total_number_feedback($file_id = '') { * @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; - } + if (is_array($array)) { + if (array_key_exists($key, $array)) { + return $array[$key]; + } else { + return 0; + } + } else { + return 0; + } } /** @@ -1226,25 +1226,25 @@ function check_number_feedback($key, $array) { */ function get_last_tool_access($tool, $course_code = '', $user_id='') { - // The default values of the parameters - if (empty($course_code)) { + // The default values of the parameters + if (empty($course_code)) { $course_code = api_get_course_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='".Database::escape_string($user_id)."' AND - access_cours_code='".Database::escape_string($course_code)."' 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']; + } + 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='".Database::escape_string($user_id)."' AND + access_cours_code='".Database::escape_string($course_code)."' 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']; } diff --git a/main/inc/ajax/user_manager.ajax.php b/main/inc/ajax/user_manager.ajax.php index 472d35eaa0..208618f6d5 100755 --- a/main/inc/ajax/user_manager.ajax.php +++ b/main/inc/ajax/user_manager.ajax.php @@ -41,7 +41,7 @@ switch ($action) { } } break; - case 'search_tags': + case 'search_tags': if (api_is_anonymous()) { echo ''; } else { @@ -50,7 +50,7 @@ switch ($action) { } } break; - case 'generate_api_key': + case 'generate_api_key': if (api_is_anonymous()) { echo ''; } else { @@ -69,7 +69,7 @@ switch ($action) { ...) given by Dokeos "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view @@ -1480,7 +1480,7 @@ function create_course_tables($course_db_name = null) { "student_response text not null default ''," . // student response (format depends on type) "result varchar(255) not null default ''," . // textual result "latency varchar(16) not null default ''," . // time necessary for completion of the interaction - "PRIMARY KEY (c_id, id)". + "PRIMARY KEY (c_id, id)". ")" . $charset_clause; Database::query($sql); @@ -1489,7 +1489,7 @@ function create_course_tables($course_db_name = null) { Database::query($sql); $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPIVOBJECTIVE`( - $add_to_all_tables" . + $add_to_all_tables" . "id bigint unsigned auto_increment," . "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view "order_id int unsigned not null default 0,". // internal order (0->...) given by Dokeos @@ -1498,7 +1498,7 @@ function create_course_tables($course_db_name = null) { "score_max float unsigned not null default 0," . // max score "score_min float unsigned not null default 0," . // min score "status char(32) not null default 'not attempted', " . //status, just as sco status - "PRIMARY KEY (c_id, id) ". + "PRIMARY KEY (c_id, id) ". ")" . $charset_clause; Database::query($sql); @@ -1527,7 +1527,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_comments . "` ( - $add_to_all_tables + $add_to_all_tables comment_id int NOT NULL AUTO_INCREMENT , title varchar( 250 ) NOT NULL default '', comment longtext NOT NULL , @@ -1544,7 +1544,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_posts . "` ( - $add_to_all_tables + $add_to_all_tables post_id int NOT NULL AUTO_INCREMENT , title varchar( 250 ) NOT NULL default '', full_text longtext NOT NULL , @@ -1558,7 +1558,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_rating . "` ( - $add_to_all_tables + $add_to_all_tables rating_id int NOT NULL AUTO_INCREMENT , blog_id int NOT NULL default 0, rating_type enum( 'post', 'comment' ) NOT NULL default 'post', @@ -1572,7 +1572,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_rel_user . "` ( - $add_to_all_tables + $add_to_all_tables blog_id int NOT NULL default 0, user_id int NOT NULL default 0, PRIMARY KEY ( c_id, blog_id , user_id ) @@ -1582,7 +1582,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_tasks . "` ( - $add_to_all_tables + $add_to_all_tables task_id int NOT NULL AUTO_INCREMENT , blog_id int NOT NULL default 0, title varchar( 250 ) NOT NULL default '', @@ -1596,7 +1596,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_blogs_tasks_rel_user . "` ( - $add_to_all_tables + $add_to_all_tables blog_id int NOT NULL default 0, user_id int NOT NULL default 0, task_id int NOT NULL default 0, @@ -1607,7 +1607,7 @@ function create_course_tables($course_db_name = null) { Database::query($sql); $sql ="CREATE TABLE `" .$tbl_blogs_attachment."` ( - $add_to_all_tables + $add_to_all_tables id int unsigned NOT NULL auto_increment, path varchar(255) NOT NULL COMMENT 'the real filename', comment text, @@ -1623,7 +1623,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_permission_group . "` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL AUTO_INCREMENT , group_id int NOT NULL default 0, tool varchar( 250 ) NOT NULL default '', @@ -1635,7 +1635,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_permission_user . "` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL AUTO_INCREMENT , user_id int NOT NULL default 0, tool varchar( 250 ) NOT NULL default '', @@ -1647,7 +1647,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_permission_task . "` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL AUTO_INCREMENT, task_id int NOT NULL default 0, tool varchar( 250 ) NOT NULL default '', @@ -1659,7 +1659,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_role . "` ( - $add_to_all_tables + $add_to_all_tables role_id int NOT NULL AUTO_INCREMENT, role_name varchar( 250 ) NOT NULL default '', role_comment text, @@ -1671,7 +1671,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_role_group . "` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL AUTO_INCREMENT, role_id int NOT NULL default 0, scope varchar( 20 ) NOT NULL default 'course', @@ -1683,7 +1683,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_role_permissions . "` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL AUTO_INCREMENT, role_id int NOT NULL default 0, tool varchar( 250 ) NOT NULL default '', @@ -1696,7 +1696,7 @@ function create_course_tables($course_db_name = null) { $sql = " CREATE TABLE `" . $tbl_role_user . "` ( - $add_to_all_tables + $add_to_all_tables role_id int NOT NULL default 0, scope varchar( 20 ) NOT NULL default 'course', user_id int NOT NULL default 0, @@ -1730,7 +1730,7 @@ function create_course_tables($course_db_name = null) { */ $sql = "CREATE TABLE `".$TABLESURVEY."` ( - $add_to_all_tables + $add_to_all_tables survey_id int unsigned NOT NULL auto_increment, code varchar(20) default NULL, title text default NULL, @@ -1767,7 +1767,7 @@ function create_course_tables($course_db_name = null) { Database::query($sql); $sql = "CREATE TABLE `".$TABLESURVEYINVITATION."` ( - $add_to_all_tables + $add_to_all_tables survey_invitation_id int unsigned NOT NULL auto_increment, survey_code varchar(20) NOT NULL, user varchar(250) NOT NULL, @@ -1781,7 +1781,7 @@ function create_course_tables($course_db_name = null) { $result = Database::query($sql); $sql = "CREATE TABLE `".$TABLESURVEYQUESTION."` ( - $add_to_all_tables + $add_to_all_tables question_id int unsigned NOT NULL auto_increment, survey_id int unsigned NOT NULL, survey_question text NOT NULL, @@ -1799,7 +1799,7 @@ function create_course_tables($course_db_name = null) { $result = Database::query($sql); $sql ="CREATE TABLE `".$TABLESURVEYQUESTIONOPTION."` ( - $add_to_all_tables + $add_to_all_tables question_option_id int unsigned NOT NULL auto_increment, question_id int unsigned NOT NULL, survey_id int unsigned NOT NULL, @@ -1812,7 +1812,7 @@ function create_course_tables($course_db_name = null) { $result = Database::query($sql); $sql = "CREATE TABLE `".$TABLESURVEYANSWER."` ( - $add_to_all_tables + $add_to_all_tables answer_id int unsigned NOT NULL auto_increment, survey_id int unsigned NOT NULL, question_id int unsigned NOT NULL, @@ -1824,7 +1824,7 @@ function create_course_tables($course_db_name = null) { $result = Database::query($sql); $sql = "CREATE TABLE `".$TABLESURVEYGROUP."` ( - $add_to_all_tables + $add_to_all_tables id int unsigned NOT NULL auto_increment, name varchar(20) NOT NULL, description varchar(255) NOT NULL, @@ -1835,7 +1835,7 @@ function create_course_tables($course_db_name = null) { // Table glosary $sql = "CREATE TABLE `".$TBL_GLOSSARY."` ( - $add_to_all_tables + $add_to_all_tables glossary_id int unsigned NOT NULL auto_increment, name varchar(255) NOT NULL, description text not null, @@ -1850,7 +1850,7 @@ function create_course_tables($course_db_name = null) { // Table notebook $sql = "CREATE TABLE `".$TBL_NOTEBOOK."` ( - $add_to_all_tables + $add_to_all_tables notebook_id int unsigned NOT NULL auto_increment, user_id int unsigned NOT NULL, course varchar(40) not null, @@ -1869,7 +1869,7 @@ function create_course_tables($course_db_name = null) { // Attendance table $sql = " CREATE TABLE `".$TBL_ATTENDANCE."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, name text NOT NULL, description TEXT NULL, @@ -1892,7 +1892,7 @@ function create_course_tables($course_db_name = null) { // Attendance sheet table $sql = " CREATE TABLE `".$TBL_ATTENDANCE_SHEET."` ( - $add_to_all_tables + $add_to_all_tables user_id int NOT NULL, attendance_calendar_id int NOT NULL, presence tinyint NOT NULL DEFAULT 0, @@ -1906,7 +1906,7 @@ function create_course_tables($course_db_name = null) { // Attendance calendar table $sql = " CREATE TABLE `".$TBL_ATTENDANCE_CALENDAR."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, attendance_id int NOT NULL , date_time datetime NOT NULL default '0000-00-00 00:00:00', @@ -1924,7 +1924,7 @@ function create_course_tables($course_db_name = null) { // Attendance result table $sql = " CREATE TABLE `".$TBL_ATTENDANCE_RESULT."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, user_id int NOT NULL, attendance_id int NOT NULL, @@ -1941,7 +1941,7 @@ function create_course_tables($course_db_name = null) { // attendance sheet log table $sql = "CREATE TABLE `".$TBL_ATTENDANCE_SHEET_LOG."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, attendance_id int NOT NULL DEFAULT 0, lastedit_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00', @@ -1955,7 +1955,7 @@ function create_course_tables($course_db_name = null) { // Thematic table $sql = "CREATE TABLE `".$TBL_THEMATIC."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, title varchar(255) NOT NULL, content text NULL, @@ -1971,7 +1971,7 @@ function create_course_tables($course_db_name = null) { // thematic plan table $sql = "CREATE TABLE `".$TBL_THEMATIC_PLAN."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, thematic_id int NOT NULL, title varchar(255) NOT NULL, @@ -1987,7 +1987,7 @@ function create_course_tables($course_db_name = null) { // thematic advance table $sql = " CREATE TABLE `".$TBL_THEMATIC_ADVANCE."` ( - $add_to_all_tables + $add_to_all_tables id int NOT NULL auto_increment, thematic_id int NOT NULL, attendance_id int NOT NULL DEFAULT 0, @@ -2078,10 +2078,10 @@ function sort_pictures($files, $type) { /** * Fills the course repository with some example content. - * @param string Course directory name (without prefix/suffix). eg "ABC" - * @param bool Whether we want to fill it with example content or not - * @return array The (structured) list of files created - * @version 1.2 + * @param string Course directory name (without prefix/suffix). eg "ABC" + * @param bool Whether we want to fill it with example content or not + * @return array The (structured) list of files created + * @version 1.2 * @deprecated this function has been merged into the fill_db_course * @assert (null, null) === false */ @@ -2290,31 +2290,31 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex $course_id = intval($course_id); if (empty($course_id)) { - return false; + return false; } $now = api_get_utc_datetime(time()); - $tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST); - $TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO); - $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); - $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA); + $tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST); + $TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO); + $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY); + $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); + $TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA); $TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT); - $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); - $TABLETOOLLINK = Database::get_course_table(TABLE_LINK); - $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST); - $TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); - $TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION); - $TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER); - $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); - - $TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); - $TABLEFORUMS = Database::get_course_table(TABLE_FORUM); - $TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD); - $TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST); - $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); - $TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); + $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT); + $TABLETOOLLINK = Database::get_course_table(TABLE_LINK); + $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST); + $TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); + $TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION); + $TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER); + $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING); + + $TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY); + $TABLEFORUMS = Database::get_course_table(TABLE_FORUM); + $TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD); + $TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST); + $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); + $TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); include api_get_path(SYS_CODE_PATH).'lang/english/create_course.inc.php'; $file_to_include = api_get_path(SYS_CODE_PATH).'lang/'.$language.'/create_course.inc.php'; @@ -2400,7 +2400,7 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex /* Group tool */ Database::query("INSERT INTO $TABLEGROUPCATEGORIES (c_id, id , title , description , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order ) - VALUES ($course_id, '2', '".lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');"); + VALUES ($course_id, '2', '".lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');"); /* Example Material */ global $language_interface; @@ -2595,7 +2595,7 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex // We need to add the item properties too! $insert_id = Database :: insert_id(); $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) - VALUES ($course_id, '" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)"; + VALUES ($course_id, '" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)"; Database::query($sql); $add_wikipedia_link_sql = "INSERT INTO $TABLETOOLLINK (c_id, url, title, description, category_id, display_order, on_homepage, target) @@ -2610,13 +2610,13 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex /* Annoucement tool */ $sql = "INSERT INTO $TABLETOOLANNOUNCEMENTS (c_id, title,content,end_date,display_order,email_sent) - VALUES ($course_id, '".lang2db(get_lang('AnnouncementExampleTitle')) . "', '".lang2db(get_lang('AnnouncementEx')) . "', NOW(), '1','0')"; + VALUES ($course_id, '".lang2db(get_lang('AnnouncementExampleTitle')) . "', '".lang2db(get_lang('AnnouncementEx')) . "', NOW(), '1','0')"; Database::query($sql); // We need to add the item properties too! $insert_id = Database :: insert_id(); $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) - VALUES ($course_id, '" . TOOL_ANNOUNCEMENT . "',1,NOW(),NOW(),$insert_id,'AnnouncementAdded',1,0,NULL,1)"; + VALUES ($course_id, '" . TOOL_ANNOUNCEMENT . "',1,NOW(),NOW(),$insert_id,'AnnouncementAdded',1,0,NULL,1)"; Database::query($sql); /* Introduction text */ @@ -2647,7 +2647,7 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex ' "'.$html.'", "1", "0", "0", "1", "0")'); $exercise_id = Database :: insert_id(); Database::query("INSERT INTO $TABLEQUIZQUESTIONLIST (c_id, id, question, description, ponderation, position, type, picture, level) - VALUES ( '.$course_id.', '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','',1)"); + VALUES ( '.$course_id.', '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','',1)"); Database::query("INSERT INTO $TABLEQUIZQUESTION (c_id, question_id, exercice_id, question_order) VALUES ('.$course_id.', 1,1,1)"); /* Forum tool */ @@ -2655,19 +2655,19 @@ function fill_db_course($course_id, $course_repository, $language, $fill_with_ex Database::query("INSERT INTO $TABLEFORUMCATEGORIES VALUES ($course_id, 1,'".lang2db(get_lang('ExampleForumCategory'))."', '', 1, 0, 0)"); $insert_id = Database :: insert_id(); Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) - VALUES ($course_id, 'forum_category',1,NOW(),NOW(),$insert_id,'ForumCategoryAdded',1,0,NULL,1)"); + VALUES ($course_id, 'forum_category',1,NOW(),NOW(),$insert_id,'ForumCategoryAdded',1,0,NULL,1)"); Database::query("INSERT INTO $TABLEFORUMS (c_id, forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id ) - VALUES ($course_id, '".lang2db(get_lang('ExampleForum'))."', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)"); + VALUES ($course_id, '".lang2db(get_lang('ExampleForum'))."', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)"); $insert_id = Database :: insert_id(); Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) - VALUES ($course_id, '".TOOL_FORUM."', 1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)"); + VALUES ($course_id, '".TOOL_FORUM."', 1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)"); Database::query("INSERT INTO $TABLEFORUMTHREADS (c_id, thread_id, thread_title, forum_id, thread_replies, thread_poster_id, thread_poster_name, thread_views, thread_last_post, thread_date, locked, thread_qualify_max, session_id) - VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', 1, 0, 1, '', 0, 1, NOW(), 0, 10, 0)"); + VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', 1, 0, 1, '', 0, 1, NOW(), 0, 10, 0)"); $insert_id = Database :: insert_id(); Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) - VALUES ($course_id, 'forum_thread',1,NOW(),NOW(),$insert_id,'ForumThreadAdded',1,0,NULL,1)"); + VALUES ($course_id, 'forum_thread',1,NOW(),NOW(),$insert_id,'ForumThreadAdded',1,0,NULL,1)"); Database::query("INSERT INTO $TABLEFORUMPOSTS VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)"); @@ -2754,8 +2754,8 @@ function register_course($params) $teachers = isset($params['teachers']) ? $params['teachers'] : null; $status = isset($params['status']) ? $params['status'] : null; - $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE); - $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE); + $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $ok_to_register_course = true; @@ -2828,7 +2828,7 @@ function register_course($params) unsubscribe = '".intval($unsubscribe) . "', visual_code = '".Database :: escape_string($visual_code) . "'"; Database::query($sql); - $course_id = Database::insert_id(); + $course_id = Database::insert_id(); if ($course_id) { $sort = api_max_sort_value('0', api_get_user_id()); diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 9758e8b334..65888b1dea 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -34,7 +34,7 @@ class Database { */ /** - * Returns the name of the main database. + * Returns the name of the main database. */ public static function get_main_database() { global $_configuration; @@ -42,7 +42,7 @@ class Database { } /** - * Returns the name of the statistics database. + * Returns the name of the statistics database. * @todo use main_database */ public static function get_statistic_database() { @@ -51,7 +51,7 @@ class Database { } /** - * Returns the name of the database where all the personal stuff of the user is stored + * Returns the name of the database where all the personal stuff of the user is stored * @todo use main_database */ public static function get_user_personal_database() { @@ -60,7 +60,7 @@ class Database { } /** - * Returns the name of the current course database. + * Returns the name of the current course database. * @return mixed Glued database name of false if undefined */ public static function get_current_course_database() { @@ -72,7 +72,7 @@ class Database { } /** - * Returns the glued name of the current course database. + * Returns the glued name of the current course database. * @return mixed Glued database name of false if undefined */ public static function get_current_course_glued_database() { @@ -84,11 +84,11 @@ class Database { } /** - * The glue is the string needed between database and table. - * The trick is: in multiple databases, this is a period (with backticks). - * In single database, this can be e.g. an underscore so we just fake - * there are multiple databases and the code can be written independent - * of the single / multiple database setting. + * The glue is the string needed between database and table. + * The trick is: in multiple databases, this is a period (with backticks). + * In single database, this can be e.g. an underscore so we just fake + * there are multiple databases and the code can be written independent + * of the single / multiple database setting. */ public static function get_database_glue() { global $_configuration; @@ -96,11 +96,11 @@ class Database { } /** - * Returns the database prefix. - * All created COURSE databases are prefixed with this string. + * Returns the database prefix. + * All created COURSE databases are prefixed with this string. * - * TIP: This can be convenient if you have multiple system installations - * on the same physical server. + * TIP: This can be convenient if you have multiple system installations + * on the same physical server. */ public static function get_database_name_prefix() { global $_configuration; @@ -108,10 +108,10 @@ class Database { } /** - * Returns the course table prefix for single database. - * Not certain exactly when this is used. - * Do research. - * It's used in local.inc.php. + * Returns the course table prefix for single database. + * Not certain exactly when this is used. + * Do research. + * It's used in local.inc.php. */ public static function get_course_table_prefix() { global $_configuration; @@ -169,7 +169,7 @@ class Database { echo "

Dev Message: get_course_table() doesn't have a 2nd parameter

"; //exit; } - return self::format_table_name(self::get_main_database(), DB_COURSE_PREFIX.$short_table_name); + return self::format_table_name(self::get_main_database(), DB_COURSE_PREFIX.$short_table_name); //return self::format_glued_course_table_name(self::fix_database_parameter($database_name), $short_table_name); } @@ -207,8 +207,8 @@ class Database { */ /** - * @return a list (array) of all courses. - * @todo shouldn't this be in the course.lib.php script? + * @return a list (array) of all courses. + * @todo shouldn't this be in the course.lib.php script? */ public static function get_course_list() { $table = self::get_main_table(TABLE_MAIN_COURSE); @@ -216,10 +216,10 @@ class Database { } /** - * Returns an array with all database fields for the specified course. + * Returns an array with all database fields for the specified course. * - * @param string The real (system) course code (main course table ID) - * @todo shouldn't this be in the course.lib.php script? + * @param string The real (system) course code (main course table ID) + * @todo shouldn't this be in the course.lib.php script? */ public static function get_course_info($course_code) { $course_code = self::escape_string($course_code); @@ -263,19 +263,19 @@ class Database { } /** - * This method creates an abstraction layer between database field names - * and field names expected in code. + * This method creates an abstraction layer between database field names + * and field names expected in code. * - * This approach helps when changing database names. - * It's also useful now to get rid of the 'franglais'. + * This approach helps when changing database names. + * It's also useful now to get rid of the 'franglais'. * - * @todo add more array entries to abstract course info from field names - * @author Roan Embrechts + * @todo add more array entries to abstract course info from field names + * @author Roan Embrechts * - * @todo What's the use of this method. I think this is better removed. - * There should be consistency in the variable names and the + * @todo What's the use of this method. I think this is better removed. + * There should be consistency in the variable names and the * use throughout the scripts - * for the database name we should consistently use or db_name + * for the database name we should consistently use or db_name * or database (db_name probably being the better one) */ public static function generate_abstract_course_field_names($result_array) { @@ -316,25 +316,25 @@ class Database { } /** - * This method creates an abstraction layer between database field names - * and field names expected in code. + * This method creates an abstraction layer between database field names + * and field names expected in code. * - * This helps when changing database names. - * It's also useful now to get rid of the 'franglais'. + * This helps when changing database names. + * It's also useful now to get rid of the 'franglais'. * - * @todo add more array entries to abstract user info from field names - * @author Roan Embrechts - * @author Patrick Cool + * @todo add more array entries to abstract user info from field names + * @author Roan Embrechts + * @author Patrick Cool * - * @todo what's the use of this function. I think this is better removed. - * There should be consistency in the variable names and the use throughout the scripts + * @todo what's the use of this function. I think this is better removed. + * There should be consistency in the variable names and the use throughout the scripts */ public static function generate_abstract_user_field_names($result_array) { - $result_array['firstName'] = $result_array['firstname']; - $result_array['lastName'] = $result_array['lastname']; - $result_array['mail'] = $result_array['email']; - #$result_array['picture_uri'] = $result_array['picture_uri']; - #$result_array ['user_id'] = $result_array['user_id']; + $result_array['firstName'] = $result_array['firstname']; + $result_array['lastName'] = $result_array['lastname']; + $result_array['mail'] = $result_array['email']; + #$result_array['picture_uri'] = $result_array['picture_uri']; + #$result_array ['user_id'] = $result_array['user_id']; return $result_array; } @@ -355,8 +355,8 @@ class Database { /** * Returns the number of affected rows in the last database operation. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return int Returns the number of affected rows on success, and -1 if the last query failed. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return int Returns the number of affected rows on success, and -1 if the last query failed. */ public static function affected_rows($connection = null) { return self::use_default_connection($connection) ? mysql_affected_rows() : mysql_affected_rows($connection); @@ -364,8 +364,8 @@ class Database { /** * Closes non-persistent database connection. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return bool Returns TRUE on success or FALSE on failure. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return bool Returns TRUE on success or FALSE on failure. */ public static function close($connection = null) { return self::use_default_connection($connection) ? mysql_close() : mysql_close($connection); @@ -373,8 +373,8 @@ class Database { /** * Opens a connection to a database server. - * @param array $parameters (optional) An array that contains the necessary parameters for accessing the server. - * @return resource/boolean Returns a database connection on success or FALSE on failure. + * @param array $parameters (optional) An array that contains the necessary parameters for accessing the server. + * @return resource/boolean Returns a database connection on success or FALSE on failure. * Note: Currently the array could contain MySQL-specific parameters: * $parameters['server'], $parameters['username'], $parameters['password'], * $parameters['new_link'], $parameters['client_flags'], $parameters['persistent']. @@ -417,7 +417,7 @@ class Database { /** * Returns error number from the last operation done on the database server. - * @param resource $connection (optional) The database server connection, + * @param resource $connection (optional) The database server connection, * for detailed description see the method query(). * @return int Returns the error number from the last database (operation, or 0 (zero) if no error occurred. */ @@ -427,7 +427,7 @@ class Database { /** * Returns error text from the last operation done on the database server. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). * @return string Returns the error text from the last database operation, or '' (empty string) if no error occurred. */ public static function error($connection = null) { @@ -447,9 +447,9 @@ class Database { /** * Escapes a string to insert into the database as text - * @param string The string to escape - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return string The escaped string + * @param string The string to escape + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return string The escaped string * @author Yannick Warnier * @author Patrick Cool , Ghent University */ @@ -465,21 +465,21 @@ class Database { /** * Gets the array from a SQL result (as returned by Database::query) - help achieving database independence - * @param resource The result from a call to sql_query (e.g. Database::query) - * @param string Optional: "ASSOC","NUM" or "BOTH", as the constant used in mysql_fetch_array. - * @return array Array of results as returned by php + * @param resource The result from a call to sql_query (e.g. Database::query) + * @param string Optional: "ASSOC","NUM" or "BOTH", as the constant used in mysql_fetch_array. + * @return array Array of results as returned by php * @author Yannick Warnier */ public static function fetch_array($result, $option = 'BOTH') { - if ($result === false) { return array(); } + if ($result === false) { return array(); } return $option == 'ASSOC' ? mysql_fetch_array($result, MYSQL_ASSOC) : ($option == 'NUM' ? mysql_fetch_array($result, MYSQL_NUM) : mysql_fetch_array($result)); } /** * Gets an associative array from a SQL result (as returned by Database::query). * This method is equivalent to calling Database::fetch_array() with 'ASSOC' value for the optional second parameter. - * @param resource $result The result from a call to sql_query (e.g. Database::query). - * @return array Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. + * @param resource $result The result from a call to sql_query (e.g. Database::query). + * @return array Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. */ public static function fetch_assoc($result) { return mysql_fetch_assoc($result); @@ -487,11 +487,11 @@ class Database { /** * Gets the next row of the result of the SQL query (as returned by Database::query) in an object form - * @param resource The result from a call to sql_query (e.g. Database::query) - * @param string Optional class name to instanciate - * @param array Optional array of parameters - * @return object Object of class StdClass or the required class, containing the query result row - * @author Yannick Warnier + * @param resource The result from a call to sql_query (e.g. Database::query) + * @param string Optional class name to instanciate + * @param array Optional array of parameters + * @return object Object of class StdClass or the required class, containing the query result row + * @author Yannick Warnier */ public static function fetch_object($result, $class = null, $params = null) { return !empty($class) ? (is_array($params) ? mysql_fetch_object($result, $class, $params) : mysql_fetch_object($result, $class)) : mysql_fetch_object($result); @@ -499,8 +499,8 @@ class Database { /** * Gets the array from a SQL result (as returned by Database::query) - help achieving database independence - * @param resource The result from a call to sql_query (see Database::query()). - * @return array Array of results as returned by php (mysql_fetch_row) + * @param resource The result from a call to sql_query (see Database::query()). + * @return array Array of results as returned by php (mysql_fetch_row) */ public static function fetch_row($result) { return mysql_fetch_row($result); @@ -508,7 +508,7 @@ class Database { /** * Frees all the memory associated with the provided result identifier. - * @return bool Returns TRUE on success or FALSE on failure. + * @return bool Returns TRUE on success or FALSE on failure. * Notes: Use this method if you are concerned about how much memory is being used for queries that return large result sets. * Anyway, all associated result memory is automatically freed at the end of the script's execution. */ @@ -518,7 +518,7 @@ class Database { /** * Returns the database client library version. - * @return strung Returns a string that represents the client library version. + * @return strung Returns a string that represents the client library version. */ public static function get_client_info() { return mysql_get_client_info(); @@ -527,9 +527,9 @@ class Database { /** * Returns a list of databases created on the server. The list may contain all of the * available database names or filtered database names by using a pattern. - * @param string $pattern (optional) A pattern for filtering database names as if it was needed for the SQL's LIKE clause, for example 'chamilo_%'. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return array Returns in an array the retrieved list of database names. + * @param string $pattern (optional) A pattern for filtering database names as if it was needed for the SQL's LIKE clause, for example 'chamilo_%'. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return array Returns in an array the retrieved list of database names. */ public static function get_databases($pattern = '', $connection = null) { $result = array(); @@ -543,13 +543,13 @@ class Database { /** * Returns a list of the fields that a given table contains. The list may contain all of the available field names or filtered field names by using a pattern. * By using a special option, this method is able to return an indexed list of fields' properties, where field names are keys. - * @param string $table This is the examined table. - * @param string $pattern (optional) A pattern for filtering field names as if it was needed for the SQL's LIKE clause, for example 'column_%'. - * @param string $database (optional) The name of the targeted database. If it is omited, the current database is assumed, see Database::select_db(). - * @param bool $including_properties (optional) When this option is true, the returned result has the followong format: - * array(field_name_1 => array(0 => property_1, 1 => property_2, ...), fieald_name_2 => array(0 => property_1, ...), ...) - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return array Returns in an array the retrieved list of field names. + * @param string $table This is the examined table. + * @param string $pattern (optional) A pattern for filtering field names as if it was needed for the SQL's LIKE clause, for example 'column_%'. + * @param string $database (optional) The name of the targeted database. If it is omited, the current database is assumed, see Database::select_db(). + * @param bool $including_properties (optional) When this option is true, the returned result has the followong format: + * array(field_name_1 => array(0 => property_1, 1 => property_2, ...), fieald_name_2 => array(0 => property_1, ...), ...) + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return array Returns in an array the retrieved list of field names. */ public static function get_fields($table, $pattern = '', $database = '', $including_properties = false, $connection = null) { $result = array(); @@ -577,8 +577,8 @@ class Database { /** * Returns information about the type of the current connection and the server host name. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return string/boolean Returns string data on success or FALSE on failure. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return string/boolean Returns string data on success or FALSE on failure. */ public static function get_host_info($connection = null) { return self::use_default_connection($connection) ? mysql_get_host_info() : mysql_get_host_info($connection); @@ -586,8 +586,8 @@ class Database { /** * Retrieves database client/server protocol version. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return int/boolean Returns the protocol version on success or FALSE on failure. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return int/boolean Returns the protocol version on success or FALSE on failure. */ public static function get_proto_info($connection = null) { return self::use_default_connection($connection) ? mysql_get_proto_info() : mysql_get_proto_info($connection); @@ -595,8 +595,8 @@ class Database { /** * Retrieves the database server version. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return string/boolean Returns the MySQL server version on success or FALSE on failure. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return string/boolean Returns the MySQL server version on success or FALSE on failure. */ public static function get_server_info($connection = null) { return self::use_default_connection($connection) ? mysql_get_server_info() : mysql_get_server_info($connection); @@ -605,10 +605,10 @@ class Database { /** * Returns a list of tables within a database. The list may contain all of the * available table names or filtered table names by using a pattern. - * @param string $database (optional) The name of the examined database. If it is omited, the current database is assumed, see Database::select_db(). - * @param string $pattern (optional) A pattern for filtering table names as if it was needed for the SQL's LIKE clause, for example 'access_%'. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return array Returns in an array the retrieved list of table names. + * @param string $database (optional) The name of the examined database. If it is omited, the current database is assumed, see Database::select_db(). + * @param string $pattern (optional) A pattern for filtering table names as if it was needed for the SQL's LIKE clause, for example 'access_%'. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return array Returns in an array the retrieved list of table names. */ public static function get_tables($database = '', $pattern = '', $connection = null) { $result = array(); @@ -629,8 +629,8 @@ class Database { /** * Gets the ID of the last item inserted into the database * This should be updated to use ADODB at some point - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return int The last ID as returned by the DB function + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return int The last ID as returned by the DB function */ public static function insert_id($connection = null) { return self::use_default_connection($connection) ? mysql_insert_id() : mysql_insert_id($connection); @@ -638,8 +638,8 @@ class Database { /** * Gets the number of rows from the last query result - help achieving database independence - * @param resource The result - * @return integer The number of rows contained in this result + * @param resource The result + * @return integer The number of rows contained in this result * @author Yannick Warnier **/ public static function num_rows($result) { @@ -649,10 +649,10 @@ class Database { /** * Acts as the relative *_result() function of most DB drivers and fetches a * specific line and a field - * @param resource The database resource to get data from - * @param integer The row number - * @param string Optional field name or number - * @return mixed One cell of the result, or FALSE on error + * @param resource The database resource to get data from + * @param integer The row number + * @param string Optional field name or number + * @return mixed One cell of the result, or FALSE on error */ public static function result($resource, $row, $field = '') { return self::num_rows($resource) > 0 ? (!empty($field) ? mysql_result($resource, $row, $field) : mysql_result($resource, $row)) : null; @@ -663,14 +663,14 @@ class Database { * Documentation has been added by Arthur Portugal * Some adaptations have been implemented by Ivan Tcholakov, 2009, 2010 * @author Olivier Brouckaert - * @param string $query The SQL query - * @param resource $connection (optional) The database server (MySQL) connection. - * If it is not specified, the connection opened by mysql_connect() is assumed. - * If no connection is found, the server will try to create one as if mysql_connect() was called with no arguments. - * If no connection is found or established, an E_WARNING level error is generated. - * @param string $file (optional) On error it shows the file in which the error has been trigerred (use the "magic" constant __FILE__ as input parameter) - * @param string $line (optional) On error it shows the line in which the error has been trigerred (use the "magic" constant __LINE__ as input parameter) - * @return resource The returned result from the query + * @param string $query The SQL query + * @param resource $connection (optional) The database server (MySQL) connection. + * If it is not specified, the connection opened by mysql_connect() is assumed. + * If no connection is found, the server will try to create one as if mysql_connect() was called with no arguments. + * If no connection is found or established, an E_WARNING level error is generated. + * @param string $file (optional) On error it shows the file in which the error has been trigerred (use the "magic" constant __FILE__ as input parameter) + * @param string $line (optional) On error it shows the line in which the error has been trigerred (use the "magic" constant __LINE__ as input parameter) + * @return resource The returned result from the query * Note: The parameter $connection could be skipped. Here are examples of this method usage: * Database::query($query); * $result = Database::query($query); @@ -695,8 +695,8 @@ class Database { //Check if the table contains a c_ (means a course id) if (api_get_setting('server_type')==='test' && strpos($query, 'c_')) { - //Check if the table contains inner joins - if ( + //Check if the table contains inner joins + if ( strpos($query, 'assoc_handle') === false && strpos($query, 'olpc_peru_filter') === false && strpos($query, 'allow_public_certificates') === false && @@ -716,20 +716,20 @@ class Database { strpos($query, 'chamilo_electric_blue') === false && strpos($query, 'wcag_anysurfer_public_pages') === false && strpos($query, 'specific_field') === false && - strpos($query, 'down_doc_path') === false && - strpos($query, 'INNER JOIN') === false && - strpos($query, 'inner join') === false && - strpos($query, 'left join') === false && - strpos($query, 'LEFT JOIN') === false && - strpos($query, 'insert') === false && - strpos($query, 'INSERT') === false && - strpos($query, 'ALTER') === false && - strpos($query, 'alter') === false && - strpos($query, 'c_id') === false && - strpos($query, 'create table') === false && - strpos($query, 'CREATE TABLE') === false && - strpos($query, 'AUTO_INCREMENT') === false - ) { + strpos($query, 'down_doc_path') === false && + strpos($query, 'INNER JOIN') === false && + strpos($query, 'inner join') === false && + strpos($query, 'left join') === false && + strpos($query, 'LEFT JOIN') === false && + strpos($query, 'insert') === false && + strpos($query, 'INSERT') === false && + strpos($query, 'ALTER') === false && + strpos($query, 'alter') === false && + strpos($query, 'c_id') === false && + strpos($query, 'create table') === false && + strpos($query, 'CREATE TABLE') === false && + strpos($query, 'AUTO_INCREMENT') === false + ) { //@todo remove this echo '
';
                 $message = '

Dev message: please add the c_id field in this query or report this error in support.chamilo.org

'; @@ -737,7 +737,7 @@ class Database { echo $message; echo '
'; //error_log($message); - } + } } if (!($result = $use_default_connection ? mysql_query($query) : mysql_query($query, $connection))) { @@ -816,9 +816,9 @@ class Database { /** * Selects a database. - * @param string $database_name The name of the database that is to be selected. - * @param resource $connection (optional) The database server connection, for detailed description see the method query(). - * @return bool Returns TRUE on success or FALSE on failure. + * @param string $database_name The name of the database that is to be selected. + * @param resource $connection (optional) The database server connection, for detailed description see the method query(). + * @return bool Returns TRUE on success or FALSE on failure. */ public static function select_db($database_name, $connection = null) { return self::use_default_connection($connection) ? mysql_select_db($database_name) : mysql_select_db($database_name, $connection); @@ -848,8 +848,8 @@ class Database { /** * Checks whether a given encoding is supported by the database server. - * @param string $encoding The encoding (a system conventional id, for example 'UTF-8') to be checked. - * @return bool Returns a boolean value as a check-result. + * @param string $encoding The encoding (a system conventional id, for example 'UTF-8') to be checked. + * @return bool Returns a boolean value as a check-result. * @author Ivan Tcholakov */ public static function is_encoding_supported($encoding) { @@ -869,9 +869,9 @@ class Database { * Constructs a SQL clause about default character set and default collation for newly created databases and tables. * Example: Database::make_charset_clause('UTF-8', 'bulgarian') returns * DEFAULT CHARACTER SET `utf8` DEFAULT COLLATE `utf8_general_ci` - * @param string $encoding (optional) The default database/table encoding (a system conventional id) to be used. - * @param string $language (optional) Language (a system conventional id) used for choosing language sensitive collation (if it is possible). - * @return string Returns the constructed SQL clause or empty string if $encoding is not correct or is not supported. + * @param string $encoding (optional) The default database/table encoding (a system conventional id) to be used. + * @param string $language (optional) Language (a system conventional id) used for choosing language sensitive collation (if it is possible). + * @return string Returns the constructed SQL clause or empty string if $encoding is not correct or is not supported. * @author Ivan Tcholakov */ public static function make_charset_clause($encoding = null, $language = null) { @@ -896,8 +896,8 @@ class Database { /** * Converts an encoding identificator to MySQL-specific encoding identifictor, * i.e. 'UTF-8' --> 'utf8'. - * @param string $encoding The conventional encoding identificator. - * @return string Returns the corresponding MySQL-specific encoding identificator if any, otherwise returns NULL. + * @param string $encoding The conventional encoding identificator. + * @return string Returns the corresponding MySQL-specific encoding identificator if any, otherwise returns NULL. * @author Ivan Tcholakov */ public static function to_db_encoding($encoding) { @@ -918,8 +918,8 @@ class Database { /** * Converts a MySQL-specific encoding identifictor to conventional encoding identificator, * i.e. 'utf8' --> 'UTF-8'. - * @param string $encoding The MySQL-specific encoding identificator. - * @return string Returns the corresponding conventional encoding identificator if any, otherwise returns NULL. + * @param string $encoding The MySQL-specific encoding identificator. + * @return string Returns the corresponding conventional encoding identificator if any, otherwise returns NULL. * @author Ivan Tcholakov */ public static function from_db_encoding($db_encoding) { @@ -939,9 +939,9 @@ class Database { /** * Chooses the default MySQL-specific collation from given encoding and language. - * @param string $encoding A conventional encoding id, i.e. 'UTF-8' - * @param string $language (optional) A conventional for the system language id, i.e. 'bulgarian'. If it is empty, the chosen collation is the default server value corresponding to the given encoding. - * @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found. + * @param string $encoding A conventional encoding id, i.e. 'UTF-8' + * @param string $language (optional) A conventional for the system language id, i.e. 'bulgarian'. If it is empty, the chosen collation is the default server value corresponding to the given encoding. + * @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found. * @author Ivan Tcholakov */ public static function to_db_collation($encoding, $language = null) { @@ -978,18 +978,18 @@ class Database { */ /** - * Glues a course database. - * glue format from local.inc.php. + * Glues a course database. + * glue format from local.inc.php. */ private static function glue_course_database_name($database_name) { return self::get_course_table_prefix().$database_name.self::get_database_glue(); } /** - * @param string $database_name, can be empty to use current course db + * @param string $database_name, can be empty to use current course db * - * @return the glued parameter if it is not empty, - * or the current course database (glued) if the parameter is empty. + * @return the glued parameter if it is not empty, + * or the current course database (glued) if the parameter is empty. */ private static function fix_database_parameter($database_name) { if (empty($database_name)) { @@ -1000,18 +1000,18 @@ class Database { } /** - * Structures a course database and table name to ready them - * for querying. The course database parameter is considered glued: - * e.g. COURSE001`.` + * Structures a course database and table name to ready them + * for querying. The course database parameter is considered glued: + * e.g. COURSE001`.` */ private static function format_glued_course_table_name($database_name_with_glue, $table) { return '`'.$database_name_with_glue.$table.'`'; } /** - * Structures a database and table name to ready them - * for querying. The database parameter is considered not glued, - * just plain e.g. COURSE001 + * Structures a database and table name to ready them + * for querying. The database parameter is considered not glued, + * just plain e.g. COURSE001 */ private static function format_table_name($database, $table) { global $_configuration; @@ -1028,9 +1028,9 @@ class Database { * checking whether the input parameter $connection actually has been provided. * If the input parameter connection is not a resource or if it is not FALSE (in case of error) * then the default opened connection should be used by the called method. - * @param resource/boolean $connection The checked parameter $connection. - * @return boolean TRUE means that calling method should use the default connection. - * FALSE means that (valid) parameter $connection has been provided and it should be used. + * @param resource/boolean $connection The checked parameter $connection. + * @return boolean TRUE means that calling method should use the default connection. + * FALSE means that (valid) parameter $connection has been provided and it should be used. */ private static function use_default_connection($connection) { return !is_resource($connection) && $connection !== false; @@ -1039,8 +1039,8 @@ class Database { /** * This private method tackles the XSS injections. It is similar to Security::remove_XSS() and works always, * including the time of initialization when the class Security has not been loaded yet. - * @param string The input variable to be filtered from XSS, in this class it is expected to be a string. - * @return string Returns the filtered string as a result. + * @param string The input variable to be filtered from XSS, in this class it is expected to be a string. + * @return string Returns the filtered string as a result. */ private static function remove_XSS(& $var) { return class_exists('Security') ? Security::remove_XSS($var) : @htmlspecialchars($var, ENT_QUOTES, api_get_system_encoding()); @@ -1099,9 +1099,9 @@ class Database { /** * Constructs a MySQL-specific collation and checks whether it is supported by the database server. - * @param string $db_encoding A MySQL-specific encoding id, i.e. 'utf8' - * @param string $language A MySQL-compatible language id, i.e. 'bulgarian' - * @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found. + * @param string $db_encoding A MySQL-specific encoding id, i.e. 'utf8' + * @param string $language A MySQL-compatible language id, i.e. 'bulgarian' + * @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found. * @author Ivan Tcholakov */ private static function check_db_collation($db_encoding, $language) { @@ -1147,7 +1147,7 @@ class Database { $sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')'; self::query($sql); if ($show_query) { - var_dump($sql); + var_dump($sql); } return self::insert_id(); } @@ -1320,9 +1320,9 @@ class Database { /** * Experimental useful database update - * @param string table name use Database::get_main_table - * @param array array with values to updates, keys are the fields in the database: Example: $params['name'] = 'Julio'; $params['lastname'] = 'Montoya'; - * @param array where conditions i.e array('id = ?' =>'4') + * @param string table name use Database::get_main_table + * @param array array with values to updates, keys are the fields in the database: Example: $params['name'] = 'Julio'; $params['lastname'] = 'Montoya'; + * @param array where conditions i.e array('id = ?' =>'4') * @todo lot of stuff to do here */ public static function update($table_name, $attributes, $where_conditions = array(), $show_query = false) { diff --git a/main/inc/lib/mail.lib.inc.php b/main/inc/lib/mail.lib.inc.php index 32d02ef962..093296ee4a 100755 --- a/main/inc/lib/mail.lib.inc.php +++ b/main/inc/lib/mail.lib.inc.php @@ -22,8 +22,8 @@ require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php'; * * @author Bert Vanderkimpen ICT&O UGent * - * @param recipient_name name of recipient - * @param recipient_email email of recipient + * @param recipient_name name of recipient + * @param recipient_email email of recipient * @param message email body * @param subject email subject * @return returns true if mail was sent @@ -32,7 +32,7 @@ require_once api_get_path(LIBRARY_PATH).'phpmailer/class.phpmailer.php'; */ function api_mail($recipient_name, $recipient_email, $subject, $message, $sender_name = '', $sender_email = '', $extra_headers = '', $additional_parameters = array()) { - api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, + api_mail_html($recipient_name, $recipient_email, $subject, $message, $sender_name, $sender_email, $extra_headers, null, null, $additional_parameters); } @@ -113,14 +113,14 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s // Send embedded image. if ($embedded_image) { - // Get all images html inside content. + // Get all images html inside content. preg_match_all("/]*)[\"\']?[^>]*>/i", $message, $m); // Prepare new tag images. $new_images_html = array(); $i = 1; if (!empty($m[1])) { - foreach ($m[1] as $image_path) { - $real_path = realpath($image_path); + foreach ($m[1] as $image_path) { + $real_path = realpath($image_path); $filename = basename($image_path); $image_cid = $filename.'_'.$i; $encoding = 'base64'; @@ -128,17 +128,17 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); $new_images_html[] = ''; $i++; - } - } - - // Replace origin image for new embedded image html. - $x = 0; - if (!empty($m[0])) { - foreach ($m[0] as $orig_img) { - $message = str_replace($orig_img, $new_images_html[$x], $message); - $x++; - } - } + } + } + + // Replace origin image for new embedded image html. + $x = 0; + if (!empty($m[0])) { + foreach ($m[0] as $orig_img) { + $message = str_replace($orig_img, $new_images_html[$x], $message); + $x++; + } + } } $message = str_replace(array("\n\r", "\n", "\r"), '
', $message); $mail->Body = ''.$message.''; diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 6820affa37..123c883e46 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -153,24 +153,24 @@ define('LOG_COURSE_DELETE', 'course_deleted'); define('LOG_COURSE_CREATE', 'course_created'); // @todo replace 'soc_gr' with social_group -define('LOG_GROUP_PORTAL_CREATED', 'soc_gr_created'); -define('LOG_GROUP_PORTAL_UPDATED', 'soc_gr_updated'); -define('LOG_GROUP_PORTAL_DELETED', 'soc_gr_deleted'); -define('LOG_GROUP_PORTAL_USER_DELETE_ALL', 'soc_gr_delete_users'); +define('LOG_GROUP_PORTAL_CREATED', 'soc_gr_created'); +define('LOG_GROUP_PORTAL_UPDATED', 'soc_gr_updated'); +define('LOG_GROUP_PORTAL_DELETED', 'soc_gr_deleted'); +define('LOG_GROUP_PORTAL_USER_DELETE_ALL', 'soc_gr_delete_users'); -define('LOG_GROUP_PORTAL_ID', 'soc_gr_portal_id'); -define('LOG_GROUP_PORTAL_REL_USER_ARRAY', 'soc_gr_user_array'); +define('LOG_GROUP_PORTAL_ID', 'soc_gr_portal_id'); +define('LOG_GROUP_PORTAL_REL_USER_ARRAY', 'soc_gr_user_array'); -define('LOG_GROUP_PORTAL_USER_SUBSCRIBED', 'soc_gr_u_subs'); -define('LOG_GROUP_PORTAL_USER_UNSUBSCRIBED', 'soc_gr_u_unsubs'); -define('LOG_GROUP_PORTAL_USER_UPDATE_ROLE', 'soc_gr_update_role'); +define('LOG_GROUP_PORTAL_USER_SUBSCRIBED', 'soc_gr_u_subs'); +define('LOG_GROUP_PORTAL_USER_UNSUBSCRIBED', 'soc_gr_u_unsubs'); +define('LOG_GROUP_PORTAL_USER_UPDATE_ROLE', 'soc_gr_update_role'); define('LOG_USER_DELETE', 'user_deleted'); define('LOG_USER_CREATE', 'user_created'); define('LOG_USER_ENABLE', 'user_enable'); define('LOG_USER_DISABLE', 'user_disable'); -define('LOG_USER_FIELD_CREATE', 'user_field_created'); -define('LOG_USER_FIELD_DELETE', 'user_field_deleted'); +define('LOG_USER_FIELD_CREATE', 'user_field_created'); +define('LOG_USER_FIELD_DELETE', 'user_field_deleted'); define('LOG_SESSION_CREATE', 'session_created'); define('LOG_SESSION_DELETE', 'session_deleted'); define('LOG_SESSION_CATEGORY_CREATE', 'session_cat_created'); //changed in 1.9.8 @@ -200,7 +200,7 @@ define('LOG_COURSE_CODE', 'course_code'); define('LOG_COURSE_ID', 'course_id'); define('LOG_USER_ID', 'user_id'); define('LOG_USER_OBJECT', 'user_object'); -define('LOG_USER_FIELD_VARIABLE', 'user_field_variable'); +define('LOG_USER_FIELD_VARIABLE', 'user_field_variable'); define('LOG_SESSION_ID', 'session_id'); define('LOG_SESSION_CATEGORY_ID', 'session_category_id'); define('LOG_CONFIGURATION_SETTINGS_CATEGORY', 'settings_category'); @@ -288,33 +288,33 @@ define('COURSE_RELATION_TYPE_RRHH', 1); define('SESSION_RELATION_TYPE_RRHH', 1); //User image sizes -define('USER_IMAGE_SIZE_ORIGINAL', 1); -define('USER_IMAGE_SIZE_BIG', 2); -define('USER_IMAGE_SIZE_MEDIUM', 3); +define('USER_IMAGE_SIZE_ORIGINAL', 1); +define('USER_IMAGE_SIZE_BIG', 2); +define('USER_IMAGE_SIZE_MEDIUM', 3); define('USER_IMAGE_SIZE_SMALL', 4); // Relation type between users -define('USER_UNKNOW', 0); -define('USER_RELATION_TYPE_UNKNOW', 1); -define('USER_RELATION_TYPE_PARENT', 2); // should be deprecated is useless -define('USER_RELATION_TYPE_FRIEND', 3); -define('USER_RELATION_TYPE_GOODFRIEND', 4); // should be deprecated is useless -define('USER_RELATION_TYPE_ENEMY', 5); // should be deprecated is useless -define('USER_RELATION_TYPE_DELETED', 6); -define('USER_RELATION_TYPE_RRHH', 7); +define('USER_UNKNOW', 0); +define('USER_RELATION_TYPE_UNKNOW', 1); +define('USER_RELATION_TYPE_PARENT', 2); // should be deprecated is useless +define('USER_RELATION_TYPE_FRIEND', 3); +define('USER_RELATION_TYPE_GOODFRIEND', 4); // should be deprecated is useless +define('USER_RELATION_TYPE_ENEMY', 5); // should be deprecated is useless +define('USER_RELATION_TYPE_DELETED', 6); +define('USER_RELATION_TYPE_RRHH', 7); //Gradebook link constants //Please do not change existing values, they are used in the database ! -define('LINK_EXERCISE', 1); -define('LINK_DROPBOX', 2); -define('LINK_STUDENTPUBLICATION', 3); +define('LINK_EXERCISE', 1); +define('LINK_DROPBOX', 2); +define('LINK_STUDENTPUBLICATION', 3); define('LINK_LEARNPATH', 4); -define('LINK_FORUM_THREAD', 5); +define('LINK_FORUM_THREAD', 5); //define('LINK_WORK',6); -define('LINK_ATTENDANCE', 7); -define('LINK_SURVEY', 8); -define('LINK_HOTPOTATOES', 9); +define('LINK_ATTENDANCE', 7); +define('LINK_SURVEY', 8); +define('LINK_HOTPOTATOES', 9); //From display.lib.php @@ -896,37 +896,37 @@ function api_protect_course_script($print_headers = false, $allow_session_admins return true; } if (api_is_platform_admin($allow_session_admins)) { - return true; + return true; } $course_info = api_get_course_info(); if (isset($course_info) && isset($course_info['visibility'])) { - switch ($course_info['visibility']) { - default: - case COURSE_VISIBILITY_CLOSED: //Completely closed: the course is only accessible to the teachers. - 0 - if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) { - $is_visible = true; - } - break; - case COURSE_VISIBILITY_REGISTERED: //Private - access authorized to course members only - 1 - if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) { - $is_visible = true; - } - break; - case COURSE_VISIBILITY_OPEN_PLATFORM: // Open - access allowed for users registered on the platform - 2 - if (api_get_user_id() && !api_is_anonymous()) { - $is_visible = true; - } - break; - case COURSE_VISIBILITY_OPEN_WORLD: //Open - access allowed for the whole world - 3 - $is_visible = true; - break; + switch ($course_info['visibility']) { + default: + case COURSE_VISIBILITY_CLOSED: //Completely closed: the course is only accessible to the teachers. - 0 + if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) { + $is_visible = true; + } + break; + case COURSE_VISIBILITY_REGISTERED: //Private - access authorized to course members only - 1 + if (api_get_user_id() && !api_is_anonymous() && $is_allowed_in_course) { + $is_visible = true; + } + break; + case COURSE_VISIBILITY_OPEN_PLATFORM: // Open - access allowed for users registered on the platform - 2 + if (api_get_user_id() && !api_is_anonymous()) { + $is_visible = true; + } + break; + case COURSE_VISIBILITY_OPEN_WORLD: //Open - access allowed for the whole world - 3 + $is_visible = true; + break; case COURSE_VISIBILITY_HIDDEN: //Completely closed: the course is only accessible to the teachers. - 0 if (api_is_platform_admin()) { $is_visible = true; } break; - } + } //If password is set and user is not registered to the course then the course is not visible if ($is_allowed_in_course == false & isset($course_info['registration_code']) && !empty($course_info['registration_code'])) { $is_visible = false; @@ -1116,15 +1116,15 @@ function _api_format_user($user, $add_password = false) $result['complete_name_with_username'] = $result['complete_name']; if (!empty($user['username'])) { - $result['complete_name_with_username'] = $result['complete_name'].' ('.$user['username'].')'; + $result['complete_name_with_username'] = $result['complete_name'].' ('.$user['username'].')'; } - $result['firstname'] = $firstname; - $result['lastname'] = $lastname; + $result['firstname'] = $firstname; + $result['lastname'] = $lastname; // Kept for historical reasons - $result['firstName'] = $firstname; - $result['lastName'] = $lastname; + $result['firstName'] = $firstname; + $result['lastName'] = $lastname; $attributes = array( 'phone', @@ -1180,36 +1180,36 @@ function _api_format_user($user, $add_password = false) // Getting user avatar. - $picture_filename = trim($result['picture_uri']); - $avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg'; - $avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg'; + $picture_filename = trim($result['picture_uri']); + $avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg'; + $avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg'; $avatar_sys_path = api_get_path(SYS_CODE_PATH).'img/unknown.jpg'; - $dir = 'upload/users/'.$user_id.'/'; + $dir = 'upload/users/'.$user_id.'/'; - //if (!empty($picture_filename) && api_is_anonymous() ) { //Why you have to be anonymous? + //if (!empty($picture_filename) && api_is_anonymous() ) { //Why you have to be anonymous? if (!empty($picture_filename)) { - if (api_get_setting('split_users_upload_directory') === 'true') { - $dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/'; - } - } - $image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; - - if (file_exists($image_sys_path) && !is_dir($image_sys_path)) { - $avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename; - $avatar_small = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename; + if (api_get_setting('split_users_upload_directory') === 'true') { + $dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/'; + } + } + $image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; + + if (file_exists($image_sys_path) && !is_dir($image_sys_path)) { + $avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename; + $avatar_small = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename; $avatar_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; - } + } $result['avatar'] = $avatar; $result['avatar_sys_path'] = $avatar_sys_path; $result['avatar_small'] = $avatar_small; - if (isset($user['user_is_online'])) { - $result['user_is_online'] = $user['user_is_online'] == true ? 1 : 0; - } + if (isset($user['user_is_online'])) { + $result['user_is_online'] = $user['user_is_online'] == true ? 1 : 0; + } if (isset($user['user_is_online_in_chat'])) { - $result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']); - } + $result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']); + } if ($add_password) { $result['password'] = $user['password']; @@ -1236,10 +1236,10 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false, $sho $result = Database::query($sql); if (Database::num_rows($result) > 0) { $result_array = Database::fetch_array($result); - if ($check_if_user_is_online) { + if ($check_if_user_is_online) { $use_status_in_platform = user_is_online($user_id); - $result_array['user_is_online'] = $use_status_in_platform; + $result_array['user_is_online'] = $use_status_in_platform; $user_online_in_chat = 0; if ($use_status_in_platform) { @@ -1249,7 +1249,7 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false, $sho } } $result_array['user_is_online_in_chat'] = $user_online_in_chat; - } + } $user = _api_format_user($result_array, $show_password); return $user; } @@ -1343,7 +1343,7 @@ function api_get_course_path($course_code = null) function api_get_course_setting($setting_name, $course_code = null) { $course_info = api_get_course_info($course_code); - $table = Database::get_course_table(TABLE_COURSE_SETTING); + $table = Database::get_course_table(TABLE_COURSE_SETTING); $setting_name = Database::escape_string($setting_name); if (!empty($course_info['real_id']) && !empty($setting_name)) { $sql = "SELECT value FROM $table @@ -2449,21 +2449,21 @@ function api_is_course_tutor() { } function api_get_user_platform_status($user_id = false) { - $status = array(); + $status = array(); $user_id = intval($user_id); if (empty($user_id)) { - $user_id = api_get_user_id(); + $user_id = api_get_user_id(); } - if (empty($user_id)) { - return false; - } - $group_id = api_get_group_id(); - $course_id = api_get_course_int_id(); - $course_code= api_get_course_id(); - $session_id = api_get_session_id(); + if (empty($user_id)) { + return false; + } + $group_id = api_get_group_id(); + $course_id = api_get_course_int_id(); + $course_code= api_get_course_id(); + $session_id = api_get_session_id(); - //Group (in course) + //Group (in course) if ($group_id && $course_id) { $group_status = array(); $is_subscribed = GroupManager::is_subscribed($user_id, $group_id); @@ -2479,8 +2479,8 @@ function api_get_user_platform_status($user_id = false) { $status['group'] = $group_status; } - //Session - if ($session_id && $course_id) { + //Session + if ($session_id && $course_id) { $session_status = array('id' => $session_id, 'course_id' => $course_id); $session_user_status = SessionManager::get_user_status_in_course_session($user_id, $course_code, $session_id); switch ($session_user_status) { @@ -2495,12 +2495,12 @@ function api_get_user_platform_status($user_id = false) { if ($is_general_coach) { $session_status['status'] = 'general_coach'; } - $status['session'] = $session_status; + $status['session'] = $session_status; - } elseif($course_id) { - //Course - $course_status = array(); - if ($course_id) { + } elseif($course_id) { + //Course + $course_status = array(); + if ($course_id) { $user_course_status = CourseManager::get_user_in_course_status($user_id, $course_code); if ($user_course_status) { @@ -2519,8 +2519,8 @@ function api_get_user_platform_status($user_id = false) { break; } } - } - $status['course'] = $course_status; + } + $status['course'] = $course_status; } return $status; @@ -2534,7 +2534,7 @@ function api_get_user_platform_status($user_id = false) { */ function api_is_course_session_coach($user_id, $course_code, $session_id) { - $session_table = Database::get_main_table(TABLE_MAIN_SESSION); + $session_table = Database::get_main_table(TABLE_MAIN_SESSION); $session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $user_id = intval($user_id); @@ -2542,9 +2542,9 @@ function api_is_course_session_coach($user_id, $course_code, $session_id) $course_code = Database::escape_string($course_code); $sql = "SELECT DISTINCT id - FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru - ON session.id = session_rc_ru.id_session - WHERE session_rc_ru.id_user = '".$user_id."' AND + FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru + ON session.id = session_rc_ru.id_session + WHERE session_rc_ru.id_user = '".$user_id."' AND session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id'"; @@ -2577,34 +2577,34 @@ function api_is_coach($session_id = 0, $course_code = null, $check_student_view } else { $course_code = api_get_course_id(); } - $session_table = Database::get_main_table(TABLE_MAIN_SESSION); + $session_table = Database::get_main_table(TABLE_MAIN_SESSION); $session_rel_course_rel_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $sessionIsCoach = null; - if (!empty($course_code)) { - $sql = "SELECT DISTINCT id, name, date_start, date_end - FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru - ON session_rc_ru.id_user = '".api_get_user_id()."' - WHERE session_rc_ru.course_code = '$course_code' AND + if (!empty($course_code)) { + $sql = "SELECT DISTINCT id, name, date_start, date_end + FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru + ON session_rc_ru.id_user = '".api_get_user_id()."' + WHERE session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id'"; - $result = Database::query($sql); - $sessionIsCoach = Database::store_result($result); - } - - if (!empty($session_id)) { - $sql = "SELECT DISTINCT id, name, date_start, date_end - FROM $session_table - WHERE session.id_coach = '".api_get_user_id()."' AND id = '$session_id' - ORDER BY date_start, date_end, name"; - $result = Database::query($sql); - if (!empty($sessionIsCoach)) { - $sessionIsCoach = array_merge($sessionIsCoach , Database::store_result($result)); - } else { - $sessionIsCoach = Database::store_result($result); - } - - } + $result = Database::query($sql); + $sessionIsCoach = Database::store_result($result); + } + + if (!empty($session_id)) { + $sql = "SELECT DISTINCT id, name, date_start, date_end + FROM $session_table + WHERE session.id_coach = '".api_get_user_id()."' AND id = '$session_id' + ORDER BY date_start, date_end, name"; + $result = Database::query($sql); + if (!empty($sessionIsCoach)) { + $sessionIsCoach = array_merge($sessionIsCoach , Database::store_result($result)); + } else { + $sessionIsCoach = Database::store_result($result); + } + + } return (count($sessionIsCoach) > 0); } @@ -2852,9 +2852,9 @@ function api_display_debug_info($debug_info) { function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach = false, $check_student_view = true) { - $my_session_id = api_get_session_id(); - $is_allowed_coach_to_edit = api_is_coach(null, null, $check_student_view); - $session_visibility = api_get_session_visibility($my_session_id); + $my_session_id = api_get_session_id(); + $is_allowed_coach_to_edit = api_is_coach(null, null, $check_student_view); + $session_visibility = api_get_session_visibility($my_session_id); // Admins can edit anything. if (api_is_platform_admin(false)) { @@ -3307,13 +3307,13 @@ function api_get_item_visibility($_course, $tool, $id, $session = 0) $id = intval($id); $session = (int) $session; $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $course_id = intval($_course['real_id']); + $course_id = intval($_course['real_id']); $sql = "SELECT visibility FROM $TABLE_ITEMPROPERTY - WHERE c_id = $course_id AND - tool = '$tool' AND - ref = $id AND - (id_session = $session OR id_session = 0) - ORDER BY id_session DESC, lastedit_date DESC + WHERE c_id = $course_id AND + tool = '$tool' AND + ref = $id AND + (id_session = $session OR id_session = 0) + ORDER BY id_session DESC, lastedit_date DESC LIMIT 1"; $res = Database::query($sql); @@ -3447,19 +3447,19 @@ function api_item_property_update( if (!empty($session_id)) { // Check whether session id already exist into itemp_properties for updating visibility or add it. $sql = "SELECT id_session FROM $TABLE_ITEMPROPERTY - WHERE - c_id = $course_id AND - tool = '$tool' AND - ref='$item_id' AND - id_session = '$session_id'"; + WHERE + c_id = $course_id AND + tool = '$tool' AND + ref='$item_id' AND + id_session = '$session_id'"; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { $sql = "UPDATE $TABLE_ITEMPROPERTY - SET lastedit_type = '".str_replace('_', '', ucwords($tool))."Deleted', - lastedit_date = '$time', - lastedit_user_id = '$user_id', - visibility = '$visibility', - id_session = '$session_id' $set_type + SET lastedit_type = '".str_replace('_', '', ucwords($tool))."Deleted', + lastedit_date = '$time', + lastedit_user_id = '$user_id', + visibility = '$visibility', + id_session = '$session_id' $set_type WHERE $filter"; } else { $sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, id_session) @@ -3577,7 +3577,7 @@ function api_get_item_property_by_tool($tool, $course_code, $session_id = null) $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $session_id = intval($session_id); $session_condition = ' AND id_session = '.$session_id; - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $sql = "SELECT * FROM $item_property_table WHERE c_id = $course_id AND tool = '$tool' $session_condition "; @@ -3644,7 +3644,7 @@ function api_get_item_property_id($course_code, $tool, $ref) { // Definition of tables. $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $sql = "SELECT id FROM $TABLE_ITEMPROPERTY WHERE c_id = $course_id AND tool = '$tool' AND ref = '$ref'"; $rs = Database::query($sql); @@ -3700,7 +3700,7 @@ function api_get_track_item_property_history($tool, $ref) /** * Gets item property data from tool of a course id - * @param int course id + * @param int course id * @param string tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!) * @param int id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool * @param int $session_id @@ -3715,18 +3715,18 @@ function api_get_item_property_info($course_id, $tool, $ref, $session_id = 0) $tool = Database::escape_string($tool); $ref = intval($ref); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $session_id = intval($session_id); // Definition of tables. $table = Database::get_course_table(TABLE_ITEM_PROPERTY); - $sql = "SELECT * FROM $table - WHERE - c_id = $course_id AND - tool = '$tool' AND - ref = $ref AND - id_session = $session_id "; + $sql = "SELECT * FROM $table + WHERE + c_id = $course_id AND + tool = '$tool' AND + ref = $ref AND + id_session = $session_id "; $rs = Database::query($sql); $row = array(); @@ -3763,7 +3763,7 @@ function api_get_languages_combo($name = 'language', $chozen=true) { } $languages = $language_list['name']; - $folder = $language_list['folder']; + $folder = $language_list['folder']; $ret .= ''; - foreach ($values as $key => $value) { - $output .= ''; - } - $output .= ''; - return $output; + $output = ''; + return $output; } /** @@ -2409,11 +2409,11 @@ function make_select($name, $values, $checked = '') */ function make_checkbox($name, $checked = '', $label = null) { - $check = ''; - if (!empty($label)) { - $check .=""; - } - return $check; + $check = ''; + if (!empty($label)) { + $check .=""; + } + return $check; } /** @@ -2423,21 +2423,21 @@ function make_checkbox($name, $checked = '', $label = null) */ function draw_date_picker($prefix, $default = '') { - if (empty($default)) { - $default = api_get_local_time(); - } - $parts = explode(' ', $default); - list($d_year, $d_month, $d_day) = explode('-', $parts[0]); - list($d_hour, $d_minute) = explode(':', $parts[1]); - - $minute = range(10, 59); - array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09'); - $date_form = make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day); - $date_form .= make_select($prefix.'_month', array_combine(range(1, 12), api_get_months_long()), $d_month); - $date_form .= make_select($prefix.'_year', array($d_year => $d_year, $d_year + 1 => $d_year + 1), $d_year).'    '; - $date_form .= make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : '; - $date_form .= make_select($prefix.'_minute', $minute, $d_minute); - return $date_form; + if (empty($default)) { + $default = api_get_local_time(); + } + $parts = explode(' ', $default); + list($d_year, $d_month, $d_day) = explode('-', $parts[0]); + list($d_hour, $d_minute) = explode(':', $parts[1]); + + $minute = range(10, 59); + array_unshift($minute, '00', '01', '02', '03', '04', '05', '06', '07', '08', '09'); + $date_form = make_select($prefix.'_day', array_combine(range(1, 31), range(1, 31)), $d_day); + $date_form .= make_select($prefix.'_month', array_combine(range(1, 12), api_get_months_long()), $d_month); + $date_form .= make_select($prefix.'_year', array($d_year => $d_year, $d_year + 1 => $d_year + 1), $d_year).'    '; + $date_form .= make_select($prefix.'_hour', array_combine(range(0, 23), range(0, 23)), $d_hour).' : '; + $date_form .= make_select($prefix.'_minute', $minute, $d_minute); + return $date_form; } /** @@ -2448,7 +2448,7 @@ function draw_date_picker($prefix, $default = '') */ function get_date_from_select($prefix, $array = array()) { - return + return $array[$prefix]['year'].'-'. two_digits($array[$prefix]['month']).'-'. two_digits($array[$prefix]['day']).' '. @@ -2516,45 +2516,45 @@ function user_is_author($itemId, $userId = null, $courseId = null, $sessionId = */ function get_list_users_without_publication($task_id, $studentId = null) { - $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); - $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - $table_user = Database::get_main_table(TABLE_MAIN_USER); - $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - - //condition for the session - $session_id = api_get_session_id(); - $course_id = api_get_course_int_id(); - - $task_id = intval($task_id); - - if ($session_id == 0) { - $sql = "SELECT user_id as id FROM $work_table - WHERE - c_id = $course_id AND - parent_id='$task_id' AND - active IN (0, 1)"; - } else { - $sql = "SELECT user_id as id FROM $work_table - WHERE - c_id = $course_id AND - parent_id='$task_id' AND - session_id='".$session_id."' AND - active IN (0, 1)"; - } - - $result = Database::query($sql); - $users_with_tasks = array(); - while($row = Database::fetch_array($result)) { - $users_with_tasks[] = $row['id']; - } - - if ($session_id == 0) { - $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u - WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.user_id"; - } else { - $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u - WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.id_user and cu.id_session = '".$session_id."'"; - } + $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + + //condition for the session + $session_id = api_get_session_id(); + $course_id = api_get_course_int_id(); + + $task_id = intval($task_id); + + if ($session_id == 0) { + $sql = "SELECT user_id as id FROM $work_table + WHERE + c_id = $course_id AND + parent_id='$task_id' AND + active IN (0, 1)"; + } else { + $sql = "SELECT user_id as id FROM $work_table + WHERE + c_id = $course_id AND + parent_id='$task_id' AND + session_id='".$session_id."' AND + active IN (0, 1)"; + } + + $result = Database::query($sql); + $users_with_tasks = array(); + while($row = Database::fetch_array($result)) { + $users_with_tasks[] = $row['id']; + } + + if ($session_id == 0) { + $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u + WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.user_id"; + } else { + $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u + WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.id_user and cu.id_session = '".$session_id."'"; + } if (!empty($studentId)) { $sql_users.= " AND u.user_id = ".intval($studentId); @@ -2573,25 +2573,25 @@ function get_list_users_without_publication($task_id, $studentId = null) } } - $result_users = Database::query($sql_users); - $users_without_tasks = array(); - while ($row_users = Database::fetch_row($result_users)) { + $result_users = Database::query($sql_users); + $users_without_tasks = array(); + while ($row_users = Database::fetch_row($result_users)) { - if (in_array($row_users[0], $users_with_tasks)) { + if (in_array($row_users[0], $users_with_tasks)) { continue; } - if ($group_id && !in_array($row_users[0], $new_group_user_list)) { + if ($group_id && !in_array($row_users[0], $new_group_user_list)) { continue; } $userId = $row_users[0]; $row_users[0] = $row_users[1]; $row_users[1] = $row_users[2]; - $row_users[2] = Display::encrypted_mailto_link($row_users[3]); + $row_users[2] = Display::encrypted_mailto_link($row_users[3]); $row_users[3] = $userId; - $users_without_tasks[] = $row_users; - } - return $users_without_tasks; + $users_without_tasks[] = $row_users; + } + return $users_without_tasks; } /** @@ -2605,35 +2605,35 @@ function get_list_users_without_publication($task_id, $studentId = null) */ function display_list_users_without_publication($task_id, $studentId = null) { - global $origin; - $table_header[] = array(get_lang('LastName'), true); - $table_header[] = array(get_lang('FirstName'), true); - $table_header[] = array(get_lang('Email'), true); - - $data = get_list_users_without_publication($task_id); - - $sorting_options = array(); - $sorting_options['column'] = 1; - $paging_options = array(); - $my_params = array(); - - if (isset($_GET['curdirpath'])) { - $my_params['curdirpath'] = Security::remove_XSS($_GET['curdirpath']); - } - if (isset($_GET['edit_dir'])) { - $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']); - } - if (isset($_GET['list'])) { - $my_params['list'] = Security::remove_XSS($_GET['list']); - } - $my_params['origin'] = $origin; + global $origin; + $table_header[] = array(get_lang('LastName'), true); + $table_header[] = array(get_lang('FirstName'), true); + $table_header[] = array(get_lang('Email'), true); + + $data = get_list_users_without_publication($task_id); + + $sorting_options = array(); + $sorting_options['column'] = 1; + $paging_options = array(); + $my_params = array(); + + if (isset($_GET['curdirpath'])) { + $my_params['curdirpath'] = Security::remove_XSS($_GET['curdirpath']); + } + if (isset($_GET['edit_dir'])) { + $my_params['edit_dir'] = Security::remove_XSS($_GET['edit_dir']); + } + if (isset($_GET['list'])) { + $my_params['list'] = Security::remove_XSS($_GET['list']); + } + $my_params['origin'] = $origin; $my_params['id'] = intval($_GET['id']); - //$column_show - $column_show[] = 1; - $column_show[] = 1; - $column_show[] = 1; - Display::display_sortable_config_table('work', $table_header, $data, $sorting_options, $paging_options, $my_params, $column_show); + //$column_show + $column_show[] = 1; + $column_show[] = 1; + $column_show[] = 1; + Display::display_sortable_config_table('work', $table_header, $data, $sorting_options, $paging_options, $my_params, $column_show); } /** @@ -3169,8 +3169,8 @@ function getWorkDateValidationStatus($homework) { $time_now = time(); if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') { - $time_expires = api_strtotime($homework['expires_on'], 'UTC'); - $difference = $time_expires - $time_now; + $time_expires = api_strtotime($homework['expires_on'], 'UTC'); + $difference = $time_expires - $time_now; if ($difference < 0) { $has_expired = true; } @@ -3181,14 +3181,14 @@ function getWorkDateValidationStatus($homework) { } if (!empty($homework['ends_on']) && $homework['ends_on'] != '0000-00-00 00:00:00') { - $time_ends = api_strtotime($homework['ends_on'], 'UTC'); - $difference2 = $time_ends - $time_now; + $time_ends = api_strtotime($homework['ends_on'], 'UTC'); + $difference2 = $time_ends - $time_now; if ($difference2 < 0) { $has_ended = true; } } - $ends_on = api_convert_and_format_date($homework['ends_on']); + $ends_on = api_convert_and_format_date($homework['ends_on']); $expires_on = api_convert_and_format_date($homework['expires_on']); } @@ -3374,19 +3374,19 @@ function event_upload($docId, $userId, $courseCode, $sessionId) $courseCode = Database::escape_string($courseCode); $sql = "INSERT INTO ".$table." - ( upload_user_id, - upload_cours_id, - upload_work_id, - upload_date, - upload_session_id - ) - VALUES ( - ".$userId.", - '".$courseCode."', - '".$docId."', - '".$reallyNow."', - '".$sessionId."' - )"; + ( upload_user_id, + upload_cours_id, + upload_work_id, + upload_date, + upload_session_id + ) + VALUES ( + ".$userId.", + '".$courseCode."', + '".$docId."', + '".$reallyNow."', + '".$sessionId."' + )"; Database::query($sql); return 1; } @@ -3437,18 +3437,18 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, if ($saveWork) { $active = '1'; $sql = "INSERT INTO ".$work_table." SET - c_id = $courseId , - url = '".$url . "', - title = '".Database::escape_string($title)."', - description = '".Database::escape_string($description)."', + c_id = $courseId , + url = '".$url . "', + title = '".Database::escape_string($title)."', + description = '".Database::escape_string($description)."', contains_file = '".$contains_file."', - active = '".$active."', - accepted = '1', + active = '".$active."', + accepted = '1', post_group_id = '".$groupId."', - sent_date = '".api_get_utc_datetime()."', - parent_id = '".$workInfo['id']."' , - session_id = '".$sessionId."', - user_id = '".$userId."'"; + sent_date = '".api_get_utc_datetime()."', + parent_id = '".$workInfo['id']."' , + session_id = '".$sessionId."', + user_id = '".$userId."'"; Database::query($sql); $workId = Database::insert_id(); @@ -3507,33 +3507,33 @@ function addDir($params, $user_id, $courseInfo, $group_id, $session_id) $base_work_dir = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work'; $course_id = $courseInfo['real_id']; - $directory = replace_dangerous_char($params['new_dir']); - $directory = disable_dangerous_file($directory); - $created_dir = create_unexisting_work_directory($base_work_dir, $directory); + $directory = replace_dangerous_char($params['new_dir']); + $directory = disable_dangerous_file($directory); + $created_dir = create_unexisting_work_directory($base_work_dir, $directory); if (!empty($created_dir)) { $dir_name_sql = '/'.$created_dir; $today = api_get_utc_datetime(); $sql = "INSERT INTO " . $work_table . " SET - c_id = $course_id, - url = '".Database::escape_string($dir_name_sql)."', + c_id = $course_id, + url = '".Database::escape_string($dir_name_sql)."', title = '".Database::escape_string($params['new_dir'])."', - description = '".Database::escape_string($params['description'])."', - author = '', + description = '".Database::escape_string($params['description'])."', + author = '', active = '1', - accepted = '1', + accepted = '1', filetype = 'folder', post_group_id = '".$group_id."', sent_date = '".$today."', qualification = '".(($params['qualification'] != '') ? Database::escape_string($params['qualification']) : '') ."', parent_id = '', qualificator_id = '', - date_of_qualification = '0000-00-00 00:00:00', + date_of_qualification = '0000-00-00 00:00:00', weight = '".Database::escape_string($params['weight'])."', session_id = '".$session_id."', allow_text_assignment = '".Database::escape_string($params['allow_text_assignment'])."', contains_file = 0, - user_id = '".$user_id."'"; + user_id = '".$user_id."'"; Database::query($sql); @@ -3623,7 +3623,7 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) if (!empty($params['enableExpiryDate'])) { $end_date = $params['expires_on']; - $date = $end_date; + $date = $end_date; } $title = sprintf(get_lang('HandingOverOfTaskX'), $params['new_dir']); @@ -3669,11 +3669,11 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) $sql = "INSERT INTO $table SET c_id = $course_id , - expires_on = '".Database::escape_string($expiryDate)."', - ends_on = '".Database::escape_string($endDate)."', - add_to_calendar = $agendaId, - enable_qualification = '$qualification', - publication_id = '$workId'"; + expires_on = '".Database::escape_string($expiryDate)."', + ends_on = '".Database::escape_string($endDate)."', + add_to_calendar = $agendaId, + enable_qualification = '$qualification', + publication_id = '$workId'"; Database::query($sql); $my_last_id = Database::insert_id(); @@ -3955,7 +3955,7 @@ function updateSettings($courseInfo, $showScore, $studentDeleteOwnPublication) { $showScore = intval($showScore); $courseId = api_get_course_int_id(); - $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); + $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); $table_course_setting = Database :: get_course_table(TOOL_COURSE_SETTING); $query = "UPDATE ".$main_course_table." SET show_score = '".$showScore."' @@ -4259,7 +4259,7 @@ function getFileContents($id, $course_info, $sessionId = 0) /* field show_score in table course : - 0 => New documents are visible for all users + 0 => New documents are visible for all users 1 => New documents are only visible for the teacher(s) field visibility in table item_property : 0 => eye closed, invisible for all students