function showUpdate($id = 0) { $this->data['id'] = $id; $this->data['groups'] = UserGroup::get(); // WHEN UPDATE SHOW CURRENT INFOMATION if ($id != 0) { $item = $this->model->find($id); // CHECK SUPER USER if ($item->isSuperUser()) { return Redirect::to($this->moduleURL . 'show-list'); } // END SUPER USER $item->group = $item->getGroups()->first(); if ($item) { $this->data['item'] = $item; } else { return Redirect::to($this->moduleURL . 'show-list'); } } if (Request::isMethod('post')) { if ($this->postUpdate($id, $this->data)) { return $this->redirectAfterSave(Input::get('save')); } } $this->layout->content = View::make('showUpdate', $this->data); }
public function action_plugin_activation() { ACL::create_token('private', 'Permission to read posts marked as "private"', 'Private Posts'); // Deny the anonymous group access to the private token, if the group hasn't been removed (why would you remove it ??) $anon = UserGroup::get('anonymous'); if (false != $anon) { $anon->deny('private'); } }
public function test_get_all() { $groups_before = UserGroups::get_all(); UserGroup::create(array('name' => 'testcasegroup')); $groups_after = UserGroups::get_all(); $this->assert_not_equal(count($groups_before), count($groups_after)); $this->assert_not_identical($groups_before, $groups_after); UserGroup::get('testcasegroup')->delete(); }
function test_deletegroup() { $group = UserGroup::get('new test group'); $this->assert_true($group instanceof UserGroup, 'Could not retrieve group named "new test group".'); $group->delete(); $this->assert_true(DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new group')) == 0, 'Was not able to delete a created group.'); $user = User::get('testcaseuser'); $user->delete(); }
Display::display_warning_message(Security::remove_XSS($values['name']) . ': ' . get_lang('AlreadyExists')); } $usergroup->display(); } else { echo '<div class="actions">'; echo '<a href="' . api_get_self() . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) { $id = intval($_GET['id']); $form = new FormValidator('usergroup', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&id=' . $id); $defaults = $usergroup->get($id); $usergroup->setForm($form, 'edit', $defaults); // Setting the form elements $form->addElement('hidden', 'id', $id); // Setting the defaults $form->setDefaults($defaults); // The validation or display. if ($form->validate()) { $values = $form->getSubmitValues(); $res = $usergroup->update($values); if ($res) { Display::display_confirmation_message(get_lang('Updated')); } else { Display::display_warning_message(Security::remove_XSS($values['name']) . ': ' . get_lang('AlreadyExists')); } $usergroup->display();
/** * Sends a message to a user/group * * @param int receiver user id * @param string subject * @param string content * @param array attachment files array($_FILES) (optional) * @param array comments about attachment files (optional) * @param int group id (optional) * @param int parent id (optional) * @param int message id for updating the message (optional) * @param int sender id (optional) the default value is the current user_id * @return bool */ public static function send_message($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0, $topic_id = 0, $sender_id = null, $text_content = null) { $table_message = Database::get_main_table(TABLE_MESSAGE); $group_id = intval($group_id); $receiver_user_id = intval($receiver_user_id); $parent_id = intval($parent_id); $edit_message_id = intval($edit_message_id); $topic_id = intval($topic_id); /* Saving the user id for the chamilo inbox, if the sender is null we asume that the current user is the one that sent the message */ if (empty($sender_id)) { $user_sender_id = api_get_user_id(); } else { $user_sender_id = intval($sender_id); } $total_filesize = 0; if (is_array($file_attachments)) { foreach ($file_attachments as $file_attach) { $total_filesize += $file_attach['size']; } } // Validating fields if (empty($subject) && empty($group_id)) { return get_lang('YouShouldWriteASubject'); } else { if ($total_filesize > intval(api_get_setting('message_max_upload_filesize'))) { return sprintf(get_lang("FilesSizeExceedsX"), Text::format_file_size(api_get_setting('message_max_upload_filesize'))); } } $inbox_last_id = null; // Just in case we replace the and \n and \n\r while saving in the DB. $content = str_replace(array("\n", "\n\r"), '<br />', $content); $now = api_get_utc_datetime(); if (!empty($receiver_user_id) || !empty($group_id)) { // message for user friend $clean_subject = Database::escape_string($subject); $clean_content = Database::escape_string($content); //message in inbox for user friend //@todo it's possible to edit a message? yes, only for groups if ($edit_message_id) { $query = " UPDATE {$table_message} SET update_date = '" . $now . "', content = '{$clean_content}' WHERE id = '{$edit_message_id}' "; Database::query($query); $inbox_last_id = $edit_message_id; } else { $query = "INSERT INTO {$table_message}(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) " . "VALUES ('{$user_sender_id}', '{$receiver_user_id}', '1', '" . $now . "','{$clean_subject}','{$clean_content}','{$group_id}','{$parent_id}', '" . $now . "')"; Database::query($query); $inbox_last_id = Database::insert_id(); } // Save attachment file for inbox messages if (is_array($file_attachments)) { $i = 0; foreach ($file_attachments as $file_attach) { if ($file_attach['error'] == 0) { $comments = isset($file_comments[$i]) ? $file_comments[$i] : null; self::save_message_attachment_file($file_attach, $comments, $inbox_last_id, null, $receiver_user_id, $group_id); } $i++; } } if (empty($group_id)) { //message in outbox for user friend or group $sql = "INSERT INTO {$table_message} (user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) " . " VALUES ('{$user_sender_id}', '{$receiver_user_id}', '4', '" . $now . "','{$clean_subject}','{$clean_content}', '{$group_id}', '{$parent_id}', '" . $now . "')"; Database::query($sql); $outbox_last_id = Database::insert_id(); // save attachment file for outbox messages if (is_array($file_attachments)) { $o = 0; foreach ($file_attachments as $file_attach) { if ($file_attach['error'] == 0) { self::save_message_attachment_file($file_attach, $file_comments[$o], $outbox_last_id, $user_sender_id); } $o++; } } } // Load user settings. $notification = new Notification(); $sender_info = array(); if (empty($group_id)) { if (!empty($user_sender_id)) { $sender_info = api_get_user_info($user_sender_id); } $notification->save_notification(Notification::NOTIFICATION_TYPE_MESSAGE, array($receiver_user_id), $subject, $content, $sender_info, $text_content); } else { $usergroup = new UserGroup(); $group_info = $usergroup->get($group_id); $group_info['topic_id'] = $topic_id; $group_info['msg_id'] = $inbox_last_id; $user_list = $usergroup->get_users_by_group($group_id, false, array(), 0, 1000); // Adding sense to the message group. $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'), $group_info['name']); $new_user_list = array(); foreach ($user_list as $user_data) { $new_user_list[] = $user_data['user_id']; } $group_info = array('group_info' => $group_info, 'user_info' => $sender_info); $notification->save_notification(Notification::NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info, $text_content); } return $inbox_last_id; } return false; }
if (isset($_POST['form_sent']) && $_POST['form_sent']) { $form_sent = $_POST['form_sent']; $elements_posted = isset($_POST['elements_in_name']) ? $_POST['elements_in_name'] : null; $first_letter_user = $_POST['firstLetterUser']; if (!is_array($elements_posted)) { $elements_posted = array(); } if ($form_sent == 1) { //added a parameter to send emails when registering a user $usergroup->subscribe_users_to_usergroup($id, $elements_posted, true, $relation); header('Location: usergroups.php'); exit; } } if (isset($_GET['action']) && $_GET['action'] == 'export') { $groupInfo = $usergroup->get($id); $users = $usergroup->getUserListByUserGroup($id); if (!empty($users)) { $data = array(array('UserName', 'ClassName')); foreach ($users as $user) { $data[] = array($user['username'], $groupInfo['name']); } $filename = 'export_user_class_' . api_get_local_time(); Export::arrayToCsv($data, $filename); exit; } } // Filter by Extra Fields $use_extra_fields = false; if (is_array($extra_field_list)) { if (is_array($new_field_list) && count($new_field_list) > 0) {
/** * @return string */ public function return_classes_block() { $html = ''; if (api_get_setting('show_groups_to_users') == 'true') { $usergroup = new UserGroup(); $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id()); $classes = ''; if (!empty($usergroup_list)) { foreach ($usergroup_list as $group_id) { $data = $usergroup->get($group_id); $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH) . 'user/classes.php?id=' . $data['id']); $classes .= Display::tag('li', $data['name']); } } if (api_is_platform_admin()) { $classes .= Display::tag('li', Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH) . 'admin/usergroups.php?action=add')); } if (!empty($classes)) { $classes = Display::tag('ul', $classes, array('class' => 'nav nav-pills nav-stacked')); $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block'); } } return $html; }
/** * function remove_from_group * removes this user from a group * @param mixed $group A group ID or name **/ public function remove_from_group($group) { $group = UserGroup::get($group); if ($group instanceof UserGroup) { $group->remove($this->id); EventLog::log(_t(' User %1$s: Removed from %2$s group.', array($this->username, $group->name)), 'notice', 'user', 'habari'); } }
*/ // Language files that should be included $language_file = array('userInfo'); $cidReset = true; require_once '../inc/global.inc.php'; api_block_anonymous_users(); if (api_get_setting('allow_social_tool') != 'true') { api_not_allowed(); } $this_section = SECTION_SOCIAL; $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']); $tool_name = get_lang('GroupEdit'); $interbreadcrumb[] = array('url' => 'home.php', 'name' => get_lang('Social')); $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups')); $usergroup = new UserGroup(); $group_data = $usergroup->get($group_id); if (empty($group_data)) { header('Location: groups.php?id=' . $group_id); exit; } //only group admins can edit the group if (!$usergroup->is_group_admin($group_id)) { api_not_allowed(); } // Create the form $form = new FormValidator('group_edit', 'post', '', ''); $form->addElement('hidden', 'id', $group_id); $usergroup->setGroupType($usergroup::SOCIAL_CLASS); $usergroup->setForm($form, 'edit', $group_data); // Set default values $form->setDefaults($group_data);
/** * Sends a message to a user/group * * @param int $receiver_user_id * @param string $subject * @param string $content * @param array $file_attachments files array($_FILES) (optional) * @param array $file_comments about attachment files (optional) * @param int $group_id (optional) * @param int $parent_id (optional) * @param int $edit_message_id id for updating the message (optional) * @param int $topic_id (optional) the default value is the current user_id * @param int $sender_id * @return bool */ public static function send_message($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0, $topic_id = 0, $sender_id = null, $directMessage = false) { $table_message = Database::get_main_table(TABLE_MESSAGE); $group_id = intval($group_id); $receiver_user_id = intval($receiver_user_id); $parent_id = intval($parent_id); $edit_message_id = intval($edit_message_id); $topic_id = intval($topic_id); if (!empty($receiver_user_id)) { $receiverUserInfo = api_get_user_info($receiver_user_id); // Disabling messages for inactive users. if ($receiverUserInfo['active'] == 0) { return false; } } if (empty($sender_id)) { $user_sender_id = api_get_user_id(); } else { $user_sender_id = intval($sender_id); } $total_filesize = 0; if (is_array($file_attachments)) { foreach ($file_attachments as $file_attach) { $total_filesize += $file_attach['size']; } } // Validating fields if (empty($subject) && empty($group_id)) { Display::addFlash(Display::return_message(get_lang('YouShouldWriteASubject'), 'warning')); return false; } else { if ($total_filesize > intval(api_get_setting('message.message_max_upload_filesize'))) { $warning = sprintf(get_lang("FilesSizeExceedsX"), format_file_size(api_get_setting('message.message_max_upload_filesize'))); Display::addFlash(Display::return_message($warning, 'warning')); return false; } } $inbox_last_id = null; //Just in case we replace the and \n and \n\r while saving in the DB $content = str_replace(array("\n", "\n\r"), '<br />', $content); $now = api_get_utc_datetime(); if (!empty($receiver_user_id) || !empty($group_id)) { // message for user friend $clean_subject = Database::escape_string($subject); $clean_content = Database::escape_string($content); //message in inbox for user friend //@todo it's possible to edit a message? yes, only for groups if ($edit_message_id) { $query = " UPDATE {$table_message} SET\n update_date = '" . $now . "',\n content = '{$clean_content}'\n WHERE id = '{$edit_message_id}' "; Database::query($query); $inbox_last_id = $edit_message_id; } else { $params = ['user_sender_id' => $user_sender_id, 'user_receiver_id' => $receiver_user_id, 'msg_status' => '1', 'send_date' => $now, 'title' => $subject, 'content' => $content, 'group_id' => $group_id, 'parent_id' => $parent_id, 'update_date' => $now]; $inbox_last_id = Database::insert($table_message, $params); } // Save attachment file for inbox messages if (is_array($file_attachments)) { $i = 0; foreach ($file_attachments as $file_attach) { if ($file_attach['error'] == 0) { self::save_message_attachment_file($file_attach, $file_comments[$i], $inbox_last_id, null, $receiver_user_id, $group_id); } $i++; } } if (empty($group_id)) { // message in outbox for user friend or group $params = ['user_sender_id' => $user_sender_id, 'user_receiver_id' => $receiver_user_id, 'msg_status' => '4', 'send_date' => $now, 'title' => $subject, 'content' => $content, 'group_id' => $group_id, 'parent_id' => $parent_id, 'update_date' => $now]; $outbox_last_id = Database::insert($table_message, $params); // save attachment file for outbox messages if (is_array($file_attachments)) { $o = 0; foreach ($file_attachments as $file_attach) { if ($file_attach['error'] == 0) { self::save_message_attachment_file($file_attach, $file_comments[$o], $outbox_last_id, $user_sender_id); } $o++; } } } // Load user settings. $notification = new Notification(); $sender_info = api_get_user_info($user_sender_id); if (empty($group_id)) { $type = Notification::NOTIFICATION_TYPE_MESSAGE; if ($directMessage) { $type = Notification::NOTIFICATION_TYPE_DIRECT_MESSAGE; } $notification->save_notification($type, array($receiver_user_id), $subject, $content, $sender_info); } else { $usergroup = new UserGroup(); $group_info = $usergroup->get($group_id); $group_info['topic_id'] = $topic_id; $group_info['msg_id'] = $inbox_last_id; $user_list = $usergroup->get_users_by_group($group_id, false, array(), 0, 1000); // Adding more sense to the message group $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'), $group_info['name']); $new_user_list = array(); foreach ($user_list as $user_data) { $new_user_list[] = $user_data['user_id']; } $group_info = array('group_info' => $group_info, 'user_info' => $sender_info); $notification->save_notification(Notification::NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info); } return $inbox_last_id; } return false; }
//require_once '../inc/global.inc.php'; api_block_anonymous_users(); // setting breadcrumbs $this_section = SECTION_SOCIAL; // Database Table Definitions $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_group_rel_user = Database::get_main_table(TABLE_USERGROUP_REL_USER); // setting the name of the tool $tool_name = get_lang('SubscribeUsersToGroup'); $group_id = intval($_REQUEST['id']); $usergroup = new UserGroup(); // todo @this validation could be in a function in group_portal_manager if (empty($group_id)) { api_not_allowed(); } else { $group_info = $usergroup->get($group_id); if (empty($group_info)) { api_not_allowed(); } //only admin or moderator can do that if (!$usergroup->is_group_member($group_id)) { api_not_allowed(); } } $interbreadcrumb[] = array('url' => 'groups.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array('url' => 'group_view.php?id=' . $group_id, 'name' => $group_info['name']); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('SubscribeUsersToGroup')); $form_sent = 0; $errorMsg = $firstLetterUser = $firstLetterSession = ''; $UserList = $SessionList = array(); $users = $sessions = array();
public function test_member() { $group = UserGroup::get("new test group"); // Add Alice to the group. $group->add('alice'); $this->assert_true($group->member($this->user_alice->id), 'Unable to find user added to test group.'); $this->assert_true($group->member('alice'), 'Unable to find user added to test group.'); // Bob should not have been added to the group. $this->assert_false($group->member($this->user_bob->id), 'User not in test group should not be a member.'); $this->assert_false($group->member('bob'), 'User not in test group should not be a member.'); }
/** * Shows the avatar block in social pages * * @param string highlight link possible values: * group_add, * home, * messages, * messages_inbox, * messages_compose, * messages_outbox, * invitations, * shared_profile, * friends, * groups search * @param int group id * @param int user id * */ public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) { if (empty($user_id)) { $user_id = api_get_user_id(); } $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); $template = new Template(null, false, false, false, false, false); if (in_array($show, $show_groups) && !empty($group_id)) { // Group image $userGroup = new UserGroup(); $group_info = $userGroup->get($group_id); $userGroupImage = $userGroup->get_picture_group($group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG); $template->assign('show_group', true); $template->assign('group_id', $group_id); $template->assign('user_group_image', $userGroupImage); $template->assign('user_group', $group_info); $template->assign('user_is_group_admin', $userGroup->is_group_admin($group_id, api_get_user_id())); } else { $template->assign('show_user', true); $template->assign('user_image', ['big' => UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_BIG), 'normal' => UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_MEDIUM)]); } $skillBlock = $template->get_template('social/avatar_block.tpl'); return $template->fetch($skillBlock); }
$form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) { // Action handling: Editing a note // Initialize the object $form = new FormValidator('career', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&id=' . Security::remove_XSS($_GET['id'])); // Setting the form elements $form->addElement('header', '', get_lang('Modify')); $form->addElement('hidden', 'id', intval($_GET['id'])); $form->addElement('text', 'name', get_lang('Name'), array('size' => '70')); $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250')); $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"'); // Setting the defaults $defaults = $usergroup->get($_GET['id']); $form->setDefaults($defaults); // Setting the rules. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); // The validation or display. if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); $res = $usergroup->update($values); if ($res) { Display::display_confirmation_message(get_lang('Updated')); } else { Display::display_warning_message(Security::remove_XSS($values['name']) . ': ' . get_lang('AlreadyExists')); } }
/** * Create a new permission token, and save it to the permission tokens table * @param string $name The name of the permission * @param string $description The description of the permission * @param string $group The token group for organizational purposes * @param bool $crud Indicates if the token is a CRUD or boolean type token (default is boolean) * @return mixed the ID of the newly created permission, or boolean false */ public static function create_token($name, $description, $group, $crud = false) { $name = self::normalize_token($name); $crud = $crud ? 1 : 0; // first, make sure this isn't a duplicate if (ACL::token_exists($name)) { return false; } $allow = true; // Plugins have the opportunity to prevent adding this token $allow = Plugins::filter('token_create_allow', $allow, $name, $description, $group, $crud); if (!$allow) { return false; } Plugins::act('token_create_before', $name, $description, $group, $crud); $result = DB::query('INSERT INTO {tokens} (name, description, token_group, token_type) VALUES (?, ?, ?, ?)', array($name, $description, $group, $crud)); if (!$result) { // if it didn't work, don't bother trying to log it return false; } self::clear_caches(); // Add the token to the admin group $token = ACL::token_id($name); $admin = UserGroup::get('admin'); if ($admin) { ACL::grant_group($admin->id, $token, 'full'); } EventLog::log('New permission token created: ' . $name, 'info', 'default', 'habari'); Plugins::act('permission_create_after', $name, $description, $group, $crud); return $result; }
public static function getByID($id) { $group = new UserGroup(); $group->get(["id" => $id]); return $group; }
$filterData = array(); if ($searchForm->validate()) { $filterData = $searchForm->getSubmitValues(); } $conditions = array(); if (!empty($filters) && !empty($filterData)) { foreach ($filters as $filter) { if (isset($filter['name']) && isset($filterData[$filter['name']])) { $value = $filterData[$filter['name']]; if (!empty($value)) { $conditions[$filter['name']] = $value; } } } } $data = $usergroup->get($id); $course_list_in = $usergroup->get_courses_by_usergroup($id, true); $course_list = CourseManager::get_courses_list(0, 0, 'title', 'asc', -1, null, api_get_current_access_url_id(), false, $conditions); $elements_not_in = $elements_in = array(); foreach ($course_list_in as $course) { $elements_in[$course['id']] = $course['title'] . " (" . $course['visual_code'] . ")"; } if (!empty($course_list)) { foreach ($course_list as $item) { $elements_not_in[$item['id']] = $item['title'] . " (" . $item['visual_code'] . ")"; } } $ajax_search = $add_type == 'unique' ? true : false; //checking for extra field with filter on function search($needle, $type) {
/** * Shows the right menu of the Social Network tool * * @param string highlight link possible values: group_add, home, messages, messages_inbox, messages_compose ,messages_outbox ,invitations, shared_profile, friends, groups search * @param int group id * @param int user id * @param bool show profile or not (show or hide the user image/information) * */ public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false) { if (empty($user_id)) { $user_id = api_get_user_id(); } $usergroup = new UserGroup(); $user_info = api_get_user_info($user_id, true); $current_user_id = api_get_user_id(); $current_user_info = api_get_user_info($current_user_id, true); if ($current_user_id == $user_id) { $user_friend_relation = null; } else { $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id); } $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); // get count unread message and total invitations $count_unread_message = MessageManager::get_number_of_messages(true); $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : ''; $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); $group_pending_invitations = $usergroup->get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false); $group_pending_invitations = count($group_pending_invitations); $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; $total_invitations = !empty($total_invitations) ? Display::badge($total_invitations) : ''; $html = '<div class="social-menu">'; if (in_array($show, $show_groups) && !empty($group_id)) { //--- Group image $group_info = $usergroup->get($group_id); $big = $usergroup->get_picture_group($group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG); $html .= '<div class="social-content-image">'; $html .= '<div class="well social-background-content">'; $html .= Display::url('<img src=' . $big['file'] . ' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH) . 'main/social/groups.php?id=' . $group_id); if ($usergroup->is_group_admin($group_id, api_get_user_id())) { $html .= '<div id="edit_image" class="hidden_message" style="display:none"><a href="' . api_get_path(WEB_PATH) . 'main/social/group_edit.php?id=' . $group_id . '">' . get_lang('EditGroup') . '</a></div>'; } $html .= '</div>'; $html .= '</div>'; } else { $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true); $big_image = UserManager::get_picture_user($user_id, $img_array['file'], '', USER_IMAGE_SIZE_BIG); $big_image = $big_image['file']; $normal_image = $img_array['dir'] . $img_array['file']; //--- User image $html .= '<div class="well social-background-content">'; if ($img_array['file'] != 'unknown.jpg') { $html .= '<a class="thumbnail ajax" href="' . $big_image . '"><img src=' . $normal_image . ' /> </a>'; } else { $html .= '<img src=' . $normal_image . ' width="110px" />'; } if (api_get_user_id() == $user_id) { $html .= '<div id="edit_image" class="hidden_message" style="display:none">'; $html .= '<a href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php">' . get_lang('EditProfile') . '</a></div>'; } $html .= '</div>'; } if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) { $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">'; $active = $show == 'home' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>'; if (api_get_setting('allow_message_tool') == 'true') { $active = $show == 'messages' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>'; } // Invitations if (api_get_setting('allow_message_tool') == 'true') { $active = $show == 'invitations' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>'; } //Shared profile and groups $active = $show == 'shared_profile' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array()) . get_lang('ViewMySharedProfile') . '</a></li>'; $active = $show == 'friends' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li>'; $active = $show == 'browse_groups' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>'; //Search users $active = $show == 'search' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>'; $html .= '</ul> </div>'; } if (in_array($show, $show_groups) && !empty($group_id)) { $html .= $usergroup->show_group_column_information($group_id, api_get_user_id(), $show); } if ($show == 'shared_profile') { //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('Menu').'</span></div>'; $html .= '<div class="well sidebar-nav"> <ul class="nav nav-list">'; // My own profile if ($show_full_profile && $user_id == intval(api_get_user_id())) { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/home.php">' . Display::return_icon('home.png', get_lang('Home'), array()) . get_lang('Home') . '</a></li>'; if (api_get_setting('allow_message_tool') == 'true') { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/messages/inbox.php?f=social">' . Display::return_icon('instant_message.png', get_lang('Messages'), array()) . get_lang('Messages') . $count_unread_message . '</a></li>'; $active = $show == 'invitations' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('Invitations'), array()) . get_lang('Invitations') . $total_invitations . '</a></li>'; } $html .= '<li class="active"><a href="' . api_get_path(WEB_PATH) . 'main/social/profile.php">' . Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array('style' => 'float:left')) . '' . get_lang('ViewMySharedProfile') . '</a></li> <li><a href="' . api_get_path(WEB_PATH) . 'main/social/friends.php">' . Display::return_icon('friend.png', get_lang('Friends'), array()) . get_lang('Friends') . '</a></li> <li><a href="' . api_get_path(WEB_PATH) . 'main/social/groups.php">' . Display::return_icon('group_s.png', get_lang('SocialGroups'), array()) . get_lang('SocialGroups') . '</a></li>'; $active = $show == 'search' ? 'active' : null; $html .= '<li class="' . $active . '"><a href="' . api_get_path(WEB_PATH) . 'main/social/search.php">' . Display::return_icon('zoom.png', get_lang('Search'), array()) . get_lang('Search') . '</a></li>'; } // My friend profile if (api_get_setting('allow_message_tool') == 'true') { if ($user_id != api_get_user_id()) { $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_message_to_user(\'' . $user_id . '\');" title="' . get_lang('SendMessage') . '">'; $html .= Display::return_icon('compose_message.png', get_lang('SendMessage')) . ' ' . get_lang('SendMessage') . '</a></li>'; } //check if I already sent an invitation message $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id()); if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) { $html .= '<li><a href="' . api_get_path(WEB_PATH) . 'main/social/invitations.php">' . Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')) . ' ' . get_lang('YouAlreadySentAnInvitation') . '</a></li>'; } else { if (!$show_full_profile) { $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\'' . $user_id . '\');" title="' . get_lang('SendInvitation') . '">' . Display::return_icon('invitation.png', get_lang('SocialInvitationToFriends')) . ' ' . get_lang('SendInvitation') . '</a></li>'; } } } //@todo check if user is online and if it's a friend to show the chat link if (api_is_global_chat_enabled()) { $user_name = $user_info['complete_name']; if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) { if ($user_id != api_get_user_id()) { //Only show chat if I'm available to talk if ($current_user_info['user_is_online_in_chat'] == 1) { $options = array('onclick' => "javascript:chatWith('" . $user_id . "', '" . Security::remove_XSS($user_name) . "', '" . $user_info['user_is_online_in_chat'] . "')"); $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline')); $html .= Display::tag('li', Display::url($chat_icon . ' ' . get_lang('Chat'), 'javascript:void(0);', $options)); } } } else { // Do something? if ($user_id != api_get_user_id()) { if ($current_user_info['user_is_online_in_chat'] == 1) { $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name)); $options = array('onclick' => "javascript:chatNotYetWith('" . $message . "')"); $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline')); $html .= Display::tag('li', Display::url($chat_icon . ' ' . get_lang('Chat'), 'javascript:void(0);', $options)); } } } } $html .= '</ul></div>'; if ($show_full_profile && $user_id == intval(api_get_user_id())) { $personal_course_list = UserManager::get_personal_session_course_list($user_id); $course_list_code = array(); $i = 1; if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i <= 10) { $course_list_code[] = array('code' => $my_course['code']); } else { break; } $i++; } //to avoid repeted courses $course_list_code = ArrayClass::array_unique_dimensional($course_list_code); } //-----Announcements $my_announcement_by_user_id = intval($user_id); $announcements = array(); foreach ($course_list_code as $course) { $course_info = api_get_course_info($course['code']); if (!empty($course_info)) { $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id); if (!empty($content)) { $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')) . $course_info['name'] . ' (' . $content['count'] . ')', api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?cidReq=' . $course['code']); $announcements[] = Display::tag('li', $url); } } } if (!empty($announcements)) { //echo '<div align="center" class="social-menu-title" ><span class="social-menu-text1">'.get_lang('ToolAnnouncement').'</span></div>'; $html .= '<div class="social_menu_items">'; $html .= '<ul>'; foreach ($announcements as $announcement) { $html .= $announcement; } $html .= '</ul>'; $html .= '</div>'; } } } if ($show_delete_account_button) { $html .= '<div class="sidebar-nav"><ul><li>'; $url = api_get_path(WEB_CODE_PATH) . 'auth/unsubscribe_account.php'; $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY) . get_lang('Unsubscribe'), $url); $html .= '</li></ul></div>'; } $html .= '</div>'; return $html; }
function validate_data($users) { global $defined_auth_sources; $errors = array(); $usernames = array(); // 1. Check if mandatory fields are set. $mandatory_fields = array('LastName', 'FirstName'); if (api_get_setting('registration', 'email') == 'true') { $mandatory_fields[] = 'Email'; } $classExistList = array(); $usergroup = new UserGroup(); foreach ($users as $user) { foreach ($mandatory_fields as $field) { if (isset($user[$field])) { if (empty($user[$field])) { $user['error'] = get_lang($field . 'Mandatory'); $errors[] = $user; } } } // 2. Check username, first, check whether it is empty. if (isset($user['NewUserName'])) { if (!UserManager::is_username_empty($user['NewUserName'])) { // 2.1. Check whether username is too long. if (UserManager::is_username_too_long($user['NewUserName'])) { $user['error'] = get_lang('UserNameTooLong'); $errors[] = $user; } // 2.2. Check whether the username was used twice in import file. if (isset($usernames[$user['NewUserName']])) { $user['error'] = get_lang('UserNameUsedTwice'); $errors[] = $user; } $usernames[$user['UserName']] = 1; // 2.3. Check whether username is allready occupied. if (!UserManager::is_username_available($user['NewUserName']) && $user['NewUserName'] != $user['UserName']) { $user['error'] = get_lang('UserNameNotAvailable'); $errors[] = $user; } } } // 3. Check status. if (isset($user['Status']) && !api_status_exists($user['Status'])) { $user['error'] = get_lang('WrongStatus'); $errors[] = $user; } // 4. Check ClassId if (!empty($user['ClassId'])) { $classId = explode('|', trim($user['ClassId'])); foreach ($classId as $id) { if (in_array($id, $classExistList)) { continue; } $info = $usergroup->get($id); if (empty($info)) { $user['error'] = sprintf(get_lang('ClassIdDoesntExists'), $id); $errors[] = $user; } else { $classExistList[] = $info['id']; } } } // 5. Check authentication source if (!empty($user['AuthSource'])) { if (!in_array($user['AuthSource'], $defined_auth_sources)) { $user['error'] = get_lang('AuthSourceNotAvailable'); $errors[] = $user; } } } return $errors; }
/** * Shows the avatar block in social pages * * @param string highlight link possible values: * group_add, * home, * messages, * messages_inbox, * messages_compose, * messages_outbox, * invitations, * shared_profile, * friends, * groups search * @param int group id * @param int user id * */ public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) { if (empty($user_id)) { $user_id = api_get_user_id(); } $show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups'); $template = Container::getTwig(); if (in_array($show, $show_groups) && !empty($group_id)) { // Group image $userGroup = new UserGroup(); $group_info = $userGroup->get($group_id); $userGroupImage = $userGroup->get_picture_group($group_id, $group_info['picture'], 160, GROUP_IMAGE_SIZE_BIG); $template->addGlobal('show_group', true); $template->addGlobal('group_id', $group_id); $template->addGlobal('user_group_image', $userGroupImage); $template->addGlobal('user_group', $group_info); $template->addGlobal('user_is_group_admin', $userGroup->is_group_admin($group_id, api_get_user_id())); } else { $template->addGlobal('show_group', false); $template->addGlobal('show_user', true); $template->addGlobal('user_image', ['big' => UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_BIG), 'normal' => UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_MEDIUM)]); } $content = $template->render('@template_style/social/avatar_block.html.twig'); return $content; }
function manage_form($default, $select_from_user_list = null, $sent_to = null) { $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null; $form = new FormValidator('compose_message', null, api_get_self() . '?f=' . $param_f, null, array('enctype' => 'multipart/form-data')); if (empty($group_id)) { if (isset($select_from_user_list)) { $form->addText('id_text_name', get_lang('SendMessageTo'), true, array('id' => 'id_text_name', 'onkeyup' => 'send_request_and_search()', 'autocomplete' => 'off')); $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('html', '<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>'); $form->addElement('hidden', 'user_list', 0, array('id' => 'user_list')); } else { if (!empty($sent_to)) { $form->addLabel(get_lang('SendMessageTo'), $sent_to); } if (empty($default['users'])) { //fb select $form->addElement('select_ajax', 'users', get_lang('SendMessageTo'), array(), ['multiple' => 'multiple', 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users']); } else { $form->addElement('hidden', 'hidden_user', $default['users'][0], array('id' => 'hidden_user')); } } } else { $userGroup = new UserGroup(); $group_info = $userGroup->get($group_id); $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name'])); $form->addElement('hidden', 'group_id', $group_id); $form->addElement('hidden', 'parent_id', $message_id); } $form->addText('title', get_lang('Subject'), true); $form->addHtmlEditor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250')); if (isset($_GET['re_id'])) { $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_reply_info['title']; $form->addElement('hidden', 're_id', intval($_GET['re_id'])); $form->addElement('hidden', 'save_form', 'save_form'); //adding reply mail $user_reply_info = api_get_user_info($message_reply_info['user_sender_id']); $default['content'] = '<p><br/></p>' . sprintf(get_lang('XWroteY'), $user_reply_info['complete_name'], Security::filter_terms($message_reply_info['content'])); } if (empty($group_id)) { $form->addElement('label', '', '<div id="filepaths" class="form-group"> <div id="filepath_1"> <label>' . get_lang('FilesAttachment') . '</label> <input type="file" name="attach_1"/> <label>' . get_lang('Description') . '</label> <input id="file-descrtiption" type="text" name="legend[]" class="form-control"/> </div> </div>'); $form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</a></span> (' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message.message_max_upload_filesize'))) . ')'); } $form->addButtonSend(get_lang('SendMessage'), 'compose'); $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>'); if (!empty($group_id) && !empty($message_id)) { $message_info = MessageManager::get_message_by_id($message_id); $default['title'] = get_lang('MailSubjectReplyShort') . " " . $message_info['title']; } $form->setDefaults($default); $html = ''; if ($form->validate()) { $check = Security::check_token('post'); if ($check) { $user_list = $default['users']; $file_comments = $_POST['legend']; $title = $default['title']; $content = $default['content']; $group_id = isset($default['group_id']) ? $default['group_id'] : null; $parent_id = isset($default['parent_id']) ? $default['parent_id'] : null; if (is_array($user_list) && count($user_list) > 0) { //all is well, send the message foreach ($user_list as $user) { $res = MessageManager::send_message($user, $title, $content, $_FILES, $file_comments, $group_id, $parent_id); if ($res) { $html .= MessageManager::display_success_message($user); } } } else { Display::display_error_message('ErrorSendingMessage'); } } Security::clear_token(); } else { $token = Security::get_token(); $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $html .= $form->returnForm(); } return $html; }
public function register_user($form) { $group = UserGroup::get($form->get_option('group_name')); $user = new User(array('username' => $form->username, 'email' => $form->email, 'password' => Utils::crypt($form->password))); if ($user->insert()) { $group->add($user); if ($form->get_option('standalone')) { $user->remember(); $redirect = URL::get('register_success'); } else { Session::notice(sprintf(_t("Added user '%s'", __CLASS__), $form->username)); $redirect = ""; } // Let plugins alter the redirect location. Yes, the string is loooong, but it's propably unique, too. $redirect = Plugins::filter('register_user_success_redirect_location', $redirect, $form); Utils::redirect($redirect); } else { $dberror = DB::get_last_error(); Session::error($dberror[2], 'adduser'); } }