diff --git a/main/admin/add_users_to_group.php b/main/admin/add_users_to_group.php new file mode 100644 index 0000000000..f30b46287b --- /dev/null +++ b/main/admin/add_users_to_group.php @@ -0,0 +1,673 @@ +debugOn(); +$xajax -> registerFunction ('search_users'); + +// setting the section (for the tabs) +$this_section = SECTION_PLATFORM_ADMIN; + +// Access restrictions +api_protect_admin_script(true); + +// setting breadcrumbs +$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); +$interbreadcrumb[]=array('url' => 'group_list.php','name' => get_lang('GroupList')); + +// Database Table Definitions +$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); +$tbl_user = Database::get_main_table(TABLE_MAIN_USER); +$tbl_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); + +// setting the name of the tool +$tool_name = get_lang('SubscribeUsersToGroup'); +$group_id = intval($_GET['id']); + +$add_type = 'single'; +if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){ + $add_type = Security::remove_XSS($_REQUEST['add_type']); +} + +/* +if (!api_is_platform_admin()) { + $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session; + $rs = Database::query($sql,__FILE__,__LINE__); + if(Database::result($rs,0,0)!=$_user['user_id']) { + api_not_allowed(true); + } +}*/ + +//checking for extra field with filter on +include_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); +include_once (api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'); + +function search_users($needle,$type) +{ + global $tbl_user,$tbl_group_rel_user,$group_id; + $xajax_response = new XajaxResponse(); + $return = ''; + + if (!empty($needle) && !empty($type)) { + + // xajax send utf8 datas... datas in db can be non-utf8 datas + $charset = api_get_setting('platform_charset'); + $needle = Database::escape_string($needle); + $needle = api_convert_encoding($needle, $charset, 'utf-8'); + $user_anonymous=api_get_anonymous_id(); + + $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; + $cond_user_id = ''; + if (!empty($id_session)) { + $group_id = Database::escape_string($group_id); + // check id_user from session_rel_user table + $sql = 'SELECT id_user FROM '.$tbl_group_rel_user.' WHERE group_id ="'.(int)$group_id.'"'; + $res = Database::query($sql,__FILE__,__LINE__); + $user_ids = array(); + if (Database::num_rows($res) > 0) { + while ($row = Database::fetch_row($res)) { + $user_ids[] = (int)$row[0]; + } + } + if (count($user_ids) > 0){ + $cond_user_id = ' AND user_id NOT IN('.implode(",",$user_ids).')'; + } + } + + if ($type == 'single') { + // search users where username or firstname or lastname begins likes $needle + $sql = 'SELECT user_id, username, lastname, firstname FROM '.$tbl_user.' user + WHERE (username LIKE "'.$needle.'%" + OR firstname LIKE "'.$needle.'%" + OR lastname LIKE "'.$needle.'%") AND user_id<>"'.$user_anonymous.'"'. + $order_clause. + ' LIMIT 11'; + } else { + $sql = 'SELECT user_id, username, lastname, firstname FROM '.$tbl_user.' user + WHERE '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user_id<>"'.$user_anonymous.'"'.$cond_user_id. + $order_clause; + } + + global $_configuration; + if ($_configuration['multiple_access_urls']==true) { + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1){ + if ($type == 'single') { + $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user + INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id) + WHERE access_url_id = '.$access_url_id.' AND (username LIKE "'.$needle.'%" + OR firstname LIKE "'.$needle.'%" + OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'"'. + $order_clause. + ' LIMIT 11'; + } else { + $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user + INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id) + WHERE access_url_id = '.$access_url_id.' + AND '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.user_id<>"'.$user_anonymous.'"'.$cond_user_id. + $order_clause; + } + + } + } + + $rs = Database::query($sql, __FILE__, __LINE__); + $i=0; + if ($type=='single') { + while ($user = Database :: fetch_array($rs)) { + $i++; + if ($i<=10) { + $person_name = api_get_person_name($user['firstname'], $user['lastname']); + $return .= ''.$person_name.' ('.$user['username'].')
'; + } else { + $return .= '...
'; + } + } + + $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return)); + + } else { + global $nosessionUsersList; + $return .= ''; + $xajax_response -> addAssign('ajax_list_users_multiple','innerHTML',api_utf8_encode($return)); + } + } + + return $xajax_response; +} + +$xajax -> processRequests(); + +$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); +$htmlHeadXtra[] = ' +'; + +$form_sent=0; +$errorMsg=$firstLetterUser=$firstLetterSession=''; +$UserList=$SessionList=array(); +$users=$sessions=array(); +$noPHP_SELF=true; + +if($_POST['form_sent']) { + $form_sent = $_POST['form_sent']; + $firstLetterUser = $_POST['firstLetterUser']; + $firstLetterSession = $_POST['firstLetterSession']; + $UserList = $_POST['sessionUsersList']; + $ClassList = $_POST['sessionClassesList']; + + if(!is_array($UserList)) { + $UserList=array(); + } + + if ($form_sent == 1) { + //added a parameter to send emails when registering a user + // SessionManager::suscribe_users_to_session($id_session,$UserList,true,true); + + //adding the session to the access_url_rel_session table + /*global $_configuration; + require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php'); + if ($_configuration['multiple_access_urls']==true) { + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + UrlManager::add_session_to_url($id_session,$access_url_id); + } else { + // we are filling by default the access_url_rel_session table + UrlManager::add_session_to_url($id_session,1); + }*/ + //if(empty($_GET['add'])) + //header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session); + //else + header('Location: group_list.php'); + } +} + +$group_info = GroupPortalManager::get_group_data($group_id); +Display::display_header($tool_name); +//api_display_tool_title($tool_name.' ('.$session_info['name'].')'); + +$nosessionUsersList = $sessionUsersList = array(); +/*$sql = 'SELECT COUNT(1) FROM '.$tbl_user; +$rs = Database::query($sql, __FILE__, __LINE__); +$count_courses = Database::result($rs, 0, 0);*/ +$ajax_search = $add_type == 'unique' ? true : false; +global $_configuration; + +$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; + +if ($ajax_search) { + $sql="SELECT u.user_id, lastname, firstname, username, group_id + FROM $tbl_user u + LEFT JOIN $tbl_group_rel_user gu + ON (gu.user_id = u.user_id) WHERE gu.group_id = $group_id ". + $order_clause; + + if ($_configuration['multiple_access_urls']==true) { + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1){ + $sql="SELECT u.user_id, lastname, firstname, username, id_session + FROM $tbl_user u + INNER JOIN $tbl_session_rel_user + ON $tbl_session_rel_user.id_user = u.user_id + AND $tbl_session_rel_user.id_session = ".intval($id_session)." + INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id) + WHERE access_url_id = $access_url_id + $order_clause"; + } + } + $result=Database::query($sql,__FILE__,__LINE__); + $Users=Database::store_result($result); + foreach ($Users as $user) { + $sessionUsersList[$user['user_id']] = $user ; + } +} else { + /* + //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 ) { + $result_list=array(); + foreach ($new_field_list as $new_field) { + $varname = 'field_'.$new_field['variable']; + if (Usermanager::is_extra_field_available($new_field['variable'])) { + if (isset($_POST[$varname]) && $_POST[$varname]!='0') { + $use_extra_fields = true; + $extra_field_result[]= Usermanager::get_extra_user_data_by_value($new_field['variable'], $_POST[$varname]); + } + } + } + } + } + */ + $use_extra_fields =false; + + if ($use_extra_fields) { + $final_result = array(); + if (count($extra_field_result)>1) { + for($i=0;$i0) { + $where_filter = " AND u.user_id IN ('".implode("','",$final_result)."') "; + } else { + //no results + $where_filter = " AND u.user_id = -1"; + } + } else { + if (is_array($final_result) && count($final_result)>0) { + $where_filter = " WHERE u.user_id IN ('".implode("','",$final_result)."') "; + } else { + //no results + $where_filter = " WHERE u.user_id = -1"; + } + } + } + + if ($use_extra_fields) { + $sql="SELECT user_id, lastname, firstname, username, group_id + FROM $tbl_user u + LEFT JOIN $tbl_session_rel_user + ON $tbl_session_rel_user.id_user = u.user_id AND id_session = '$id_session' + $where_filter + $order_clause"; + + } else { + + $sql="SELECT u.user_id, lastname, firstname, username, group_id + FROM $tbl_user u + LEFT JOIN $tbl_group_rel_user gu + ON (gu.user_id = u.user_id) WHERE gu.group_id = $group_id + $order_clause"; + } + + if ($_configuration['multiple_access_urls']==true) { + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1){ + $sql="SELECT u.user_id, lastname, firstname, username, id_session + FROM $tbl_user u + LEFT JOIN $tbl_session_rel_user + ON $tbl_session_rel_user.id_user = u.user_id AND id_session = '$id_session' + INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id) + WHERE access_url_id = $access_url_id $where_filter + $order_clause"; + } + } + + $result = Database::query($sql,__FILE__,__LINE__); + $Users = Database::store_result($result); + + foreach ($Users as $user) { + if($user['group_id'] != $group_id) + $nosessionUsersList[$user['user_id']] = $user ; + } + var_dump($nosessionUsersList); + $user_anonymous=api_get_anonymous_id(); + /* foreach($nosessionUsersList as $key_user_list =>$value_user_list) { + if ($nosessionUsersList[$key_user_list]['user_id']==$user_anonymous) { + unset($nosessionUsersList[$key_user_list]); + } + }*/ + + //filling the correct users in list + $sql="SELECT u.user_id, lastname, firstname, username, group_id + FROM $tbl_user u + LEFT JOIN $tbl_group_rel_user + ON $tbl_group_rel_user.user_id = u.user_id AND group_id = '$group_id' + $order_clause"; + + if ($_configuration['multiple_access_urls']==true) { + $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1){ + $sql="SELECT u.user_id, lastname, firstname, username, id_session + FROM $tbl_user u + LEFT JOIN $tbl_session_rel_user + ON $tbl_session_rel_user.id_user = u.user_id AND id_session = '$id_session' + INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id) + WHERE access_url_id = $access_url_id + $order_clause"; + } + } + $result=Database::query($sql,__FILE__,__LINE__); + $Users=Database::store_result($result); + + foreach($Users as $key_user_list =>$value_user_list) { + if ($Users[$key_user_list]['user_id']==$user_anonymous) { + unset($Users[$key_user_list]); + } + } + + foreach ($Users as $user) { + if($user['group_id'] == $group_id){ + $sessionUsersList[$user['user_id']] = $user; + if (array_key_exists($user['user_id'],$nosessionUsersList)) + unset($nosessionUsersList[$user['user_id']]); + } + } +} + +if ($add_type == 'multiple') { + //$link_add_type_unique = ''.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').''; + //$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); +} else { + //$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); + //$link_add_type_multiple = ''.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').''; + /* + *
+  |  +
+ */ +} + + +?> + + +
'.$tool_name.' ('.$session_info['name'].')

'; ?> + +
> + +0 ) { + echo '

'.get_lang('FilterUsers').'

'; + foreach ($new_field_list as $new_field) { + echo $new_field['name']; + $varname = 'field_'.$new_field['variable']; + echo ' '; + echo '  '; + } + echo ''; + echo '

'; + } + } +} +?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
: + :
+ + : + + 
+
+ + +
+ +
+ +
+ +
+
+ + + + +

+ + +





+
+
+
+ '.get_lang('FinishSessionCreation').''; + } else { + //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed) + echo ''; + + } + ?> +
+
+ + + diff --git a/main/admin/group_add.php b/main/admin/group_add.php new file mode 100644 index 0000000000..b7314d17e4 --- /dev/null +++ b/main/admin/group_add.php @@ -0,0 +1,148 @@ + 'index.php', 'name' => get_lang('PlatformAdmin')); +$tool_name = get_lang('AddGroup'); + +// Create the form +$form = new FormValidator('group_add'); +$form->addElement('header', '', $tool_name); + +// name +$form->addElement('text', 'name', get_lang('Name')); +$form->applyFilter('name', 'html_filter'); +$form->applyFilter('name', 'trim'); +$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); + +// Description +$form->addElement('text', 'description', get_lang('Description')); +$form->applyFilter('description', 'html_filter'); +$form->applyFilter('description', 'trim'); + + +// url +$form->addElement('text', 'url', get_lang('URL')); +$form->applyFilter('url', 'html_filter'); +$form->applyFilter('url', 'trim'); + +// Picture +$form->addElement('file', 'picture', get_lang('AddPicture')); +$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); +$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); + +// Status +$status = array(); +$status[GROUP_PERMISSION_OPEN] = get_lang('Open'); +$status[GROUP_PERMISSION_CLOSED] = get_lang('Closed'); +$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status); + +// Set default values +$defaults['status'] = GROUP_PERMISSION_OPEN; + +$form->setDefaults($defaults); + +// Submit button +$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"'); + +// Validate form +if( $form->validate()) { + $check = Security::check_token('post'); + if ($check) { + $values = $form->exportValues(); + + $picture_element = & $form->getElement('picture'); + $picture = $picture_element->getValue(); + $picture_uri = ''; + $name = $values['name']; + $description = $values['description']; + $url = $values['url']; + $status = intval($values['visibility']); + $picture = $_FILES['picture']; + + $group_id = GroupPortalManager::add($name, $description, $url, $status); + + if (!empty($picture['name'])) { + $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']); + GroupPortalManager::update($group_id, $name, $description, $url,$status, $picture_uri); + } + + //@todo send emails + +/* if (!empty($email) && $send_mail) { + $recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS); + $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName'); + + $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); + $email_admin = api_get_setting('emailAdministrator'); + + if ($_configuration['multiple_access_urls'] == true) { + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $url = api_get_access_url($access_url_id); + $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator'); + } + } + else { + $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator'); + } + @api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin); + }*/ + + Security::clear_token(); + $tok = Security::get_token(); + header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupAdded')).'&sec_token='.$tok); + exit (); + } +} else { + if (isset($_POST['submit'])) { + Security::clear_token(); + } + $token = Security::get_token(); + $form->addElement('hidden', 'sec_token'); + $form->setConstants(array('sec_token' => $token)); +} + +// Display form +Display::display_header($tool_name); +//api_display_tool_title($tool_name); +if(!empty($message)){ + Display::display_normal_message(stripslashes($message)); +} +$form->display(); + +// Footer +Display::display_footer(); diff --git a/main/admin/group_edit.php b/main/admin/group_edit.php new file mode 100644 index 0000000000..43244b1bb7 --- /dev/null +++ b/main/admin/group_edit.php @@ -0,0 +1,143 @@ + 'index.php','name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => 'group_list.php','name' => get_lang('GroupList')); + +$table_group = Database::get_main_table(TABLE_MAIN_GROUP); + +$sql = "SELECT * FROM $table_group WHERE id = '".$group_id."'"; +$res = Database::query($sql, __FILE__, __LINE__); +if (Database::num_rows($res) != 1) { + header('Location: group_list.php'); + exit; +} + +$group_data = Database::fetch_array($res, 'ASSOC'); + +// Create the form +$form = new FormValidator('group_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))); +$form->addElement('header', '', $tool_name); +$form->addElement('hidden', 'id', $group_id); + +// name +$form->addElement('text', 'name', get_lang('Name')); +$form->applyFilter('name', 'html_filter'); +$form->applyFilter('name', 'trim'); +$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); + +// Description +$form->addElement('text', 'description', get_lang('Description')); +$form->applyFilter('description', 'html_filter'); +$form->applyFilter('description', 'trim'); + +// url +$form->addElement('text', 'url', get_lang('URL')); +$form->applyFilter('url', 'html_filter'); +$form->applyFilter('url', 'trim'); + +// Picture +$form->addElement('file', 'picture', get_lang('AddPicture')); +$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); +$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); +if (strlen($group_data['picture_uri']) > 0) { + $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage')); +} + + +// Status +$status = array(); +$status[GROUP_PERMISSION_OPEN] = get_lang('Open'); +$status[GROUP_PERMISSION_CLOSED] = get_lang('Closed'); + +$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status, array()); + +// Submit button +$form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"'); + +// Set default values +$form->setDefaults($group_data); + +// Validate form +if ( $form->validate()) { + $group = $form->exportValues(); + + $picture_element = & $form->getElement('picture'); + $picture = $picture_element->getValue(); + + $picture_uri = $group_data['picture_uri']; + if ($group['delete_picture']) { + $picture_uri = GroupPortalManager::delete_group_picture($group_id); + } + elseif (!empty($picture['name'])) { + $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']); + } + + $name = $group['name']; + $description = $group['description']; + $url = $group['url']; + $status = intval($group['visibility']); + + GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri); + $tok = Security::get_token(); + header('Location: group_list.php?action=show_message&message='.urlencode(get_lang('GroupUpdated')).'&sec_token='.$tok); + exit(); +} + +Display::display_header($tool_name); + +// Group picture +$image_path = GroupPortalManager::get_group_picture_path_by_id($group_id,'web'); +$image_dir = $image_path['dir']; +$image = $image_path['file']; +$image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown_group.jpg'); +$image_size = api_getimagesize($image_file); + +$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' + .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' + .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; + +if ($image_size[0] > 300) { //limit display width to 300px + $img_attributes .= 'width="300" '; +} + +// get the path,width and height from original picture +$big_image = $image_dir.'big_'.$image; +$big_image_size = api_getimagesize($big_image); +$big_image_width = $big_image_size[0]; +$big_image_height = $big_image_size[1]; +$url_big_image = $big_image.'?rnd='.time(); + +if ($image == '') { + echo ''; +} else { + echo ''; +} + +// Display form +$form->display(); + +// Footer +Display::display_footer(); diff --git a/main/admin/group_list.php b/main/admin/group_list.php new file mode 100644 index 0000000000..57392b22be --- /dev/null +++ b/main/admin/group_list.php @@ -0,0 +1,439 @@ +total_number_of_items; +} +/** + * Get the users to display on the current page (fill the sortable-table) + * @param int offset of first user to recover + * @param int Number of users to get + * @param int Column to sort on + * @param string Order (ASC,DESC) + * @see SortableTable#get_table_data($from) + */ +function get_group_data($from, $number_of_items, $column, $direction) +{ + $group_table = Database :: get_main_table(TABLE_MAIN_GROUP); + + $sql = "SELECT + g.id AS col0, + g.name AS col1, + g.description AS col2, + g.visibility AS col3, + g.id AS col4 + FROM $group_table g "; + + // adding the filter to see the user's only of the current access_url + /*global $_configuration; + if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; + }*/ + + if (isset ($_GET['keyword'])) { + $keyword = Database::escape_string($_GET['keyword']); + $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )"; + } + /* + // adding the filter to see the user's only of the current access_url + if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); + }*/ + + if (!in_array($direction, array('ASC','DESC'))) { + $direction = 'ASC'; + } + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $res = Database::query($sql, __FILE__, __LINE__); + + $users = array (); + $t = time(); + while ($group = Database::fetch_row($res)) { + // forget about the expiration date field + $groups[] = $group; + } + return $groups; +} + + +function get_recent_group_data($from =0 , $number_of_items = 5, $column, $direction) +{ + $group_table = Database :: get_main_table(TABLE_MAIN_GROUP); + + $sql = "SELECT + g.id AS col0, + g.name AS col1, + g.description AS col2, + g.visibility AS col3, + g.id AS col4 + FROM $group_table g "; + + // adding the filter to see the user's only of the current access_url + /*global $_configuration; + if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; + }*/ + + if (isset ($_GET['keyword'])) { + $keyword = Database::escape_string($_GET['keyword']); + $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )"; + } + /* + // adding the filter to see the user's only of the current access_url + if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); + }*/ + + if (!in_array($direction, array('ASC','DESC'))) { + $direction = 'ASC'; + } + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $res = Database::query($sql, __FILE__, __LINE__); + + $users = array (); + $t = time(); + while ($group = Database::fetch_row($res)) { + // forget about the expiration date field + $groups[] = $group; + } + return $groups; +} + + +/** + * Build the modify-column of the table + * @param int The user id + * @param string URL params to add to table links + * @param array Row of elements to alter + * @return string Some HTML-code with modify-buttons + */ +function modify_filter($group_id,$url_params,$row) +{ + global $charset; + global $_user; + global $_admins_list; + if (api_is_platform_admin()) { + $result .= ''.Display::return_icon('add_user_big.gif',get_lang('AddUsersToGroup')).''; + $result .= ''.Display::return_icon('edit.gif', get_lang('Edit')).'  '; + $result .= ''.Display::return_icon('delete.gif', get_lang('Delete')).''; + + + } + return $result; +} + + +/** + * Build the active-column of the table to lock or unlock a certain user + * lock = the user can no longer use this account + * @author Patrick Cool , Ghent University + * @param int $active the current state of the account + * @param int $user_id The user id + * @param string $url_params + * @return string Some HTML-code with the lock/unlock button + */ +function active_filter($active, $url_params, $row) { + global $_user; + + if ($active=='1') { + $action='lock'; + $image='right'; + } elseif ($active=='-1') { + $action='edit'; + $image='expired'; + } elseif ($active=='0') { + $action='unlock'; + $image='wrong'; + } + + if ($action=='edit') { + $result = Display::return_icon($image.'.gif', get_lang('AccountExpired')); + }elseif ($row['0']<>$_user['user_id']) { // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore. + $result = ''.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).''; + } + return $result; +} + +/** + * Lock or unlock a user + * @author Patrick Cool , Ghent University + * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock) + * @param int $user_id The user id + * @return language variable + */ +function lock_unlock_user($status,$user_id) +{ + $user_table = Database :: get_main_table(TABLE_MAIN_USER); + if ($status=='lock') + { + $status_db='0'; + $return_message=get_lang('UserLocked'); + } + if ($status=='unlock') + { + $status_db='1'; + $return_message=get_lang('UserUnlocked'); + } + + if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id)) + { + $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'"; + $result = Database::query($sql, __FILE__, __LINE__); + } + + if ($result) + { + return $return_message; + } +} + +/** + * Instead of displaying the integer of the status, we give a translation for the status + * + * @param integer $status + * @return string translation + * + * @version march 2008 + * @author Patrick Cool , Ghent University, Belgium + */ +function status_filter($status) +{ + $statusname = api_get_status_langvars(); + return $statusname[$status]; +} + + +/** +============================================================================== + INIT SECTION +============================================================================== +*/ +$action = $_GET["action"]; + +if (isset ($_GET['search']) && $_GET['search'] == 'advanced') { + $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); + $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList')); + $tool_name = get_lang('SearchAUser'); + Display :: display_header($tool_name); + //api_display_tool_title($tool_name); + $form = new FormValidator('advanced_search','get'); + $form->addElement('header', '', $tool_name); + $form->add_textfield('keyword_firstname',get_lang('FirstName'),false); + $form->add_textfield('keyword_lastname',get_lang('LastName'),false); + $form->add_textfield('keyword_username',get_lang('LoginName'),false); + $form->add_textfield('keyword_email',get_lang('Email'),false); + $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false); + $status_options = array(); + $status_options['%'] = get_lang('All'); + $status_options[STUDENT] = get_lang('Student'); + $status_options[COURSEMANAGER] = get_lang('Teacher'); + $status_options[SESSIONADMIN] = get_lang('Administrator');// + $form->addElement('select','keyword_status',get_lang('Status'),$status_options); + $active_group = array(); + $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active')); + $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive')); + $form->addGroup($active_group,'',get_lang('ActiveAccount'),'
',false); + $form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"'); + $defaults['keyword_active'] = 1; + $defaults['keyword_inactive'] = 1; + $form->setDefaults($defaults); + $form->display(); +} +else +{ + $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); + $tool_name = get_lang('UserList'); + Display :: display_header($tool_name, ""); + + //api_display_tool_title($tool_name); + if (isset ($_GET['action'])) { + $check = Security::check_token('get'); + if($check) { + switch ($_GET['action']) { + case 'show_message' : + if (!empty($_GET['warn'])) { + // to prevent too long messages + if ($_GET['warn'] == 'session_message'){ + $_GET['warn'] = $_SESSION['session_message_import_users']; + } + Display::display_warning_message(urldecode($_GET['warn']),false); + } + if (!empty($_GET['message'])) { + Display :: display_confirmation_message(stripslashes($_GET['message'])); + } + break; + case 'delete_group' : + if (api_is_platform_admin()) { + if (GroupPortalManager :: delete($_GET['group_id'])) { + Display :: display_confirmation_message(get_lang('GroupDeleted')); + } else { + Display :: display_error_message(get_lang('CannotDeleteGroup')); + } + } + break; + case 'lock' : + $message=lock_unlock_user('lock',$_GET['user_id']); + Display :: display_normal_message($message); + break; + case 'unlock'; + $message=lock_unlock_user('unlock',$_GET['user_id']); + Display :: display_normal_message($message); + break; + + } + Security::clear_token(); + } + } + if (isset ($_POST['action'])) + { + $check = Security::check_token('get'); + if($check) + { + switch ($_POST['action']) + { + case 'delete' : + if (api_is_platform_admin()) { + $number_of_selected_users = count($_POST['id']); + $number_of_deleted_users = 0; + if (is_array($_POST['id'])) { + foreach ($_POST['id'] as $index => $user_id) + { + if($user_id != $_user['user_id']) + { + if(UserManager :: delete_user($user_id)) + { + $number_of_deleted_users++; + } + } + } + } + if($number_of_selected_users == $number_of_deleted_users) + { + Display :: display_confirmation_message(get_lang('SelectedUsersDeleted')); + } + else + { + Display :: display_error_message(get_lang('SomeUsersNotDeleted')); + } + } + break; + } + Security::clear_token(); + } + } + // Create a search-box + $form = new FormValidator('search_simple','get','','',null,false); + $renderer =& $form->defaultRenderer(); + $renderer->setElementTemplate('{element} '); + $form->addElement('text','keyword',get_lang('keyword')); + $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"'); + //$form->addElement('static','search_advanced_link',null,''.get_lang('AdvancedSearch').''); + echo '
'; + if (api_is_platform_admin()) { + echo ''. + ''.Display::return_icon('add_user_big.gif',get_lang('AddUsers')).get_lang('AddGroup').''. + ''; + } + $form->display(); + echo '
'; + if (isset ($_GET['keyword'])) { + $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword'])); + } + // Create a sortable table with user-data + $parameters['sec_token'] = Security::get_token(); + + // get the list of all admins to mark them in the users list + $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); + $sql_admin = "SELECT user_id FROM $admin_table"; + $res_admin = Database::query($sql_admin); + $_admins_list = array(); + while ($row_admin = Database::fetch_row($res_admin)) { + $_admins_list[] = $row_admin[0]; + } + + $table = new SortableTable('users', 'get_number_of_groups', 'get_group_data', 2); + $table->set_additional_parameters($parameters); + $table->set_header(0, '', false); + $table->set_header(1, get_lang('Name')); + $table->set_header(2, get_lang('Description')); + $table->set_header(3, get_lang('Visibility')); + $table->set_header(4, '', false); + $table->set_column_filter(4, 'modify_filter'); + //$table->set_column_filter(6, 'status_filter'); + //$table->set_column_filter(7, 'active_filter'); + //$table->set_column_filter(8, 'modify_filter'); + if (api_is_platform_admin()) + $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform'))); + $table->display(); +} +/* +============================================================================== + FOOTER +============================================================================== +*/ +Display :: display_footer(); +?> diff --git a/main/admin/index.php b/main/admin/index.php index 3a5cd50542..25fcf2ed43 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -1,26 +1,5 @@
  • + +
  • +
  • 0){ ?> diff --git a/main/auth/inscription.php b/main/auth/inscription.php index babd35667a..c8b4c540d8 100644 --- a/main/auth/inscription.php +++ b/main/auth/inscription.php @@ -156,8 +156,8 @@ if ($display_all_form === true) { $form->addRule('username', get_lang('UsernameWrong'), 'username'); $form->addRule('username', get_lang('UserTaken'), 'username_available'); // PASSWORD - $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 40)); - $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 40)); + $form->addElement('password', 'pass1', get_lang('Pass'), array('size' => 20)); + $form->addElement('password', 'pass2', get_lang('Confirmation'), array('size' => 20)); $form->addRule('pass1', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('pass2', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule(array('pass1', 'pass2'), get_lang('PassTwo'), 'compare'); @@ -165,7 +165,7 @@ if ($display_all_form === true) { $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password'); // PHONE - $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 40)); + $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20)); if (api_get_setting('registration', 'phone') == 'true') $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required'); diff --git a/main/auth/profile.php b/main/auth/profile.php index 1bad98b10a..15c64e422c 100644 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -17,18 +17,8 @@ // Language files that should be included. $language_file = array('registration', 'messages', 'userInfo'); - $cidReset = true; - require_once '../inc/global.inc.php'; - -if (!isset($_GET['show'])) { - if (api_get_setting('allow_social_tool') == 'true' || api_get_setting('allow_message_tool') == 'true') { - header('Location:../social/index.php'); - exit; - } -} - require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; $this_section = SECTION_MYPROFILE; @@ -39,7 +29,6 @@ if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user[ } $htmlHeadXtra[] = ''; //jQuery - $htmlHeadXtra[] = ''; //jQuery $htmlHeadXtra[] = ''; @@ -714,15 +703,23 @@ Display :: display_header(''); if (api_get_setting('extended_profile') == 'true') { echo '
    '; + + if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') { + echo ''.Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).' '.get_lang('ViewSharedProfile').''; + } + if (api_get_setting('allow_message_tool') == 'true') { + echo ''.Display::return_icon('inbox.png').' '.get_lang('Messages').''; + } $show = isset($_GET['show']) ? '&show='.Security::remove_XSS($_GET['show']) : ''; + echo ''; + if (isset($_GET['type']) && $_GET['type'] == 'extended') { echo ''.Display::return_icon('edit.gif', get_lang('EditNormalProfile')).' '.get_lang('EditNormalProfile').''; } else { echo ''.Display::return_icon('edit.gif', get_lang('EditExtendProfile')).' '.get_lang('EditExtendProfile').''; } - if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') { - echo ''.Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).' '.get_lang('ViewSharedProfile').''; - } + echo ''; + echo '
    '; } @@ -797,7 +794,7 @@ if (api_get_setting('allow_message_tool') == 'true') { $number_of_outbox_message = MessageManager::get_number_of_messages_sent(); $cant_out_box = ' ('.$number_of_outbox_message.')'; $cant_msg = ' ('.$number_of_new_messages.')'; - $number_of_new_messages_of_friend = UserFriend::get_message_number_invitation_by_user_id(api_get_user_id()); + $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); //echo ''; echo '

    '.get_lang('Messages').'

    diff --git a/main/inc/banner.inc.php b/main/inc/banner.inc.php index 4ceb0f6332..1d3a5c6c73 100644 --- a/main/inc/banner.inc.php +++ b/main/inc/banner.inc.php @@ -233,6 +233,16 @@ if ($_user['user_id'] && !api_is_anonymous()) { $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress']; } } + + + // Social Networking + //if (api_get_setting('show_tabs', 'social') == 'true') { + if (1) { + $navigation['social'] = $possible_tabs['social']; + } else{ + $menu_navigation['social'] = $possible_tabs['social']; + } + if(api_is_platform_admin(true)) { @@ -520,6 +530,13 @@ function get_tabs() { $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php'; $navigation['session_my_progress']['title'] = get_lang('MyProgress'); } + + // Social + if (api_get_setting('allow_social_tool')=='true') { + $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/profile.php'; + $navigation['social']['title'] = get_lang('SocialNetwork'); + } + // Platform administration if (api_is_platform_admin(true)) { diff --git a/main/inc/header.inc.php b/main/inc/header.inc.php index a6764d1933..9d53f87b19 100644 --- a/main/inc/header.inc.php +++ b/main/inc/header.inc.php @@ -219,4 +219,4 @@ include(api_get_path(LIBRARY_PATH).'/javascript/email_links.lib.js.php'); set_additional_parameters($query_vars); } - foreach ($header as $index => $header_item) - { - $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]); - } - $table->set_form_actions($form_actions); - if ($style=='table') - $table->display(); - else - $table->display_grid(); + if ($style=='table') { + if (is_array($header) && count($header)>0 ) { + foreach ($header as $index => $header_item) { + $table->set_header($index, $header_item[0], $header_item[1], $header_item[2], $header_item[3]); + } + } + $table->set_form_actions($form_actions); + $table->display(); + } else { + $table->display_grid(); + } + } + /** + * Shows a nice grid + * @param string grid name (important to create css) + * @param array header content + * @param array array with the information to show + * @param array $paging_options Keys are: + * 'per_page_default' = items per page when switching from + * full- list to per-page-view + * 'per_page' = number of items to show per page + * 'page_nr' = The page to display + * 'hide_navigation' = true to hide the navigation + * @param array $query_vars Additional variables to add in the query-string + * @param array $form actions Additional variables to add in the query-string + * @param mixed An array with bool values to know which columns show. i.e: $vibility_options= array(true, false) we will only show the first column + * Can be also only a bool value. TRUE: show all columns, FALSE: show nothing + */ + + public static function display_sortable_grid ($name, $header, $content, $paging_options = array (), $query_vars = null, $form_actions=array(), $vibility_options = true) { + global $origin; + $column = 0; + $default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20; + $table = new SortableTableFromArray($content, $column, $default_items_per_page, $name); + if (is_array($query_vars)) { + $table->set_additional_parameters($query_vars); + } + $table->display_simple_grid($vibility_options, $paging_options['hide_navigation']); } + /** diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php new file mode 100755 index 0000000000..54250239fa --- /dev/null +++ b/main/inc/lib/group_portal_manager.lib.php @@ -0,0 +1,1054 @@ +, + * + * @param string The URL of the site + * @param string The description of the site + * @param int is active or not + * @param int the user_id of the owner + * @return boolean if success + */ + function add($name, $description, $url, $visibility, $picture='') + { + $tms = time(); + $table = Database :: get_main_table(TABLE_MAIN_GROUP); + $sql = "INSERT INTO $table + SET name = '".Database::escape_string($name)."', + description = '".Database::escape_string($description)."', + picture_uri = '".Database::escape_string($picture)."', + url = '".Database::escape_string($url)."', + visibility = '".Database::escape_string($visibility)."', + created_on = FROM_UNIXTIME(".$tms."), + updated_on = FROM_UNIXTIME(".$tms.")"; + $result = Database::query($sql, __FILE__, __LINE__); + $return = Database::insert_id(); + return $return; + } + + /** + * Updates a group + * @author Julio Montoya , + * + * @param int The id + * @param string The description of the site + * @param int is active or not + * @param int the user_id of the owner + * @return boolean if success + */ + function update($group_id, $name, $description, $url, $visibility, $picture_uri) + { + $group_id = intval($group_id); + $table = Database::get_main_table(TABLE_MAIN_GROUP); + $tms = time(); + $sql = "UPDATE $table + SET name = '".Database::escape_string($name)."', + description = '".Database::escape_string($description)."', + picture_uri = '".Database::escape_string($picture_uri)."', + url = '".Database::escape_string($url)."', + visibility = '".Database::escape_string($visibility)."', + updated_on = FROM_UNIXTIME(".$tms.") + WHERE id = '$group_id'"; + $result = Database::query($sql, __FILE__, __LINE__); + return $result; + } + + + /** + * Deletes a group + * @author Julio Montoya + * @param int id + * @return boolean true if success + * */ + function delete($id) + { + $id = intval($id); + $table = Database :: get_main_table(TABLE_MAIN_GROUP); + $sql= "DELETE FROM $table WHERE id = ".Database::escape_string($id); + $result = Database::query($sql, __FILE__, __LINE__); + return $result; + } + + /** + * + * */ + function url_exist($url) + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."' "; + $res = Database::query($sql,__FILE__,__LINE__); + $num = Database::num_rows($res); + return $num; + } + + /** + * + * */ + function url_id_exist($url) + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id FROM $table_access_url WHERE id = '".Database::escape_string($url)."' "; + $res = Database::query($sql,__FILE__,__LINE__); + $num = Database::num_rows($res); + return $num; + } + + /** + * This function get the quantity of URLs + * @author Julio Montoya + * @return int count of urls + * */ + function url_count() + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT count(id) as count_result FROM $table_access_url"; + $res = Database::query($sql, __FILE__, __LINE__); + $url = Database::fetch_array($res,'ASSOC'); + $result = $url['count_result']; + return $result; + } + + /** + * Gets the id, url, description, and active status of ALL URLs + * @author Julio Montoya + * @return array + * */ + function get_url_data() + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id, url, description, active FROM $table_access_url"; + $res = Database::query($sql, __FILE__, __LINE__); + $urls = array (); + while ($url = Database::fetch_array($res)) { + $urls[] = $url; + } + return $urls; + } + + /** + * Gets data of all groups + * @author Julio Montoya + * @return array + * */ + function get_all_group_data($visibility = GROUP_PERMISSION_OPEN, $from=0, $number_of_items=10) + { + $table = Database :: get_main_table(TABLE_MAIN_GROUP); + $visibility = intval($visibility); + $user_condition = ''; + $sql = "SELECT name, description, picture_uri FROM $table WHERE visibility = $visibility "; + $res = Database::query($sql, __FILE__, __LINE__); + $data = array (); + while ($item = Database::fetch_array($res)) { + $data[] = $item; + } + return $data; + } + + function get_group_data($group_id) + { + $table = Database :: get_main_table(TABLE_MAIN_GROUP); + $group_id = intval($group_id); + $user_condition = ''; + $sql = "SELECT name, description, picture_uri, visibility FROM $table WHERE id = $group_id "; + $res = Database::query($sql, __FILE__, __LINE__); + $item = array(); + if (Database::num_rows($res)>0) { + $item = Database::fetch_array($res,'ASSOC'); + } + return $item; + } + + function get_group_tags($group_id, $show_tag_links = true) + { + $tag = Database :: get_main_table(TABLE_MAIN_TAG); + $table_group_rel_tag = Database :: get_main_table(TABLE_MAIN_GROUP_REL_TAG); + $group_id = intval($group_id); + $user_condition = ''; + + $sql = "SELECT tag FROM $tag t INNER JOIN $table_group_rel_tag gt ON (gt.tag_id= t.id) WHERE gt.group_id = $group_id "; + $res = Database::query($sql, __FILE__, __LINE__); + $tags = array(); + if (Database::num_rows($res)>0) { + while ($row = Database::fetch_array($res,'ASSOC')) { + $tags[] = $row; + } + } + + if ($show_tag_links == true) { + if (is_array($tags) && count($tags)>0) { + foreach ($tags as $tag) { + $tag_tmp[] = ''.$tag['tag'].''; + } + if (is_array($tags) && count($tags)>0) { + $tags= implode(', ',$tag_tmp); + } + } else { + $tags = ''; + } + } + return $tags; + } + + + + /** + * Gets the id, url, description, and active status of ALL URLs + * @author Julio Montoya + * @return array + * */ + function get_url_data_from_id($url_id) + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id, url, description, active FROM $table_access_url WHERE id = ".Database::escape_string($url_id); + $res = Database::query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); + return $row; + } + + /** Gets the inner join of users and group table + * @author Julio Montoya + * @return int access url id + * @return array Database::store_result of the result + * */ + function get_groups_by_user($user_id='', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) + { + $where = ''; + $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); + $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); + $user_id = intval($user_id); + + if ($relation_type == 0) { + $where_relation_condition = ''; + } else { + $relation_type = intval($relation_type); + $where_relation_condition = "AND gu.relation_type = $relation_type "; + } + + $sql = "SELECT g.picture_uri, g.name, g.description, g.id + FROM $tbl_group g + INNER JOIN $table_group_rel_user gu + ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition "; + + $result=Database::query($sql,__FILE__,__LINE__); + $array = array(); + while ($row = Database::fetch_array($result, 'ASSOC')) { + if ($with_image == true) { + $picture = self::get_picture_group($row['id'], $row['picture_uri'],80); + $img = ''; + $row['picture_uri'] = $img; + } + $array[$row['id']] = $row; + } + return $array; + } + + function get_users_by_group($group_id='', $with_image = false) + { + $where = ''; + $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); + $tbl_user = Database::get_main_table(TABLE_MAIN_USER); + $group_id = intval($group_id); + + if ($relation_type == 0) { + $where_relation_condition = ''; + } else { + $relation_type = intval($relation_type); + $where_relation_condition = "AND gu.relation_type = $relation_type "; + } + + $sql="SELECT u.user_id, u.firstname, u.lastname, picture_uri, relation_type FROM $tbl_user u + INNER JOIN $table_group_rel_user gu + ON (gu.user_id = u.user_id) WHERE gu.group_id= $group_id $where_relation_condition ORDER BY relation_type, firstname"; + + $result=Database::query($sql,__FILE__,__LINE__); + $array = array(); + while ($row = Database::fetch_array($result, 'ASSOC')) { + if ($with_image == true) { + $picture = UserManager::get_picture_user($row['user_id'], $row['picture_uri'],80); + $img = ''; + $row['picture_uri'] = $img; + } + $array[$row['user_id']] = $row; + } + return $array; + } + + + + /** Gets the inner join of access_url and the course table + * @author Julio Montoya + * @return int access url id + * @return array Database::store_result of the result + * */ + function get_url_rel_course_data($access_url_id='') + { + $where =''; + $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); + + if (!empty($access_url_id)) + $where ="WHERE $table_url_rel_course.access_url_id = ".Database::escape_string($access_url_id); + + $sql="SELECT course_code, title, access_url_id + FROM $tbl_course u + INNER JOIN $table_url_rel_course + ON $table_url_rel_course.course_code = code + $where + ORDER BY title, code"; + + $result=Database::query($sql,__FILE__,__LINE__); + $courses=Database::store_result($result); + return $courses; + } + + /** Gets the inner join of access_url and the session table + * @author Julio Montoya + * @return int access url id + * @return array Database::store_result of the result + * */ + function get_url_rel_session_data($access_url_id='') + { + $where =''; + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); + + if (!empty($access_url_id)) + $where ="WHERE $table_url_rel_session.access_url_id = ".Database::escape_string($access_url_id); + + $sql="SELECT id, name, access_url_id + FROM $tbl_session u + INNER JOIN $table_url_rel_session + ON $table_url_rel_session.session_id = id + $where + ORDER BY name, id"; + + $result=Database::query($sql,__FILE__,__LINE__); + $sessions=Database::store_result($result); + return $sessions; + } + + + + /** + * Sets the status of an URL 1 or 0 + * @author Julio Montoya + * @param string lock || unlock + * @param int url id + * */ + function set_url_status($status, $url_id) + { + $url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + if ($status=='lock') { + $status_db='0'; + } + if ($status=='unlock') { + $status_db='1'; + } + if(($status_db=='1' OR $status_db=='0') AND is_numeric($url_id)) { + $sql="UPDATE $url_table SET active='".Database::escape_string($status_db)."' WHERE id='".Database::escape_string($url_id)."'"; + $result = Database::query($sql, __FILE__, __LINE__); + } + } + + /** + * Gets the relationship between a group and a User + * @author Julio Montoya + * @param int user id + * @param int group_id + * @return boolean true if success + * */ + function get_user_group_role($user_id, $group_id) + { + $table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP); + $return_value = 0; + if (!empty($user_id) && !empty($group_id)) { + $sql = "SELECT relation_type FROM $table_group_rel_user WHERE id = ".intval($group_id)." AND user_id = ".intval($user_id)." "; + $result = Database::query($sql, __FILE__, __LINE__); + if (Database::num_rows($result)>0) { + $row = Database::fetch_row($result); + $return_value = $row['relation_type']; + } + } + return $return_value; + } + + /** + * Checks the relationship between an URL and a Course (return the num_rows) + * @author Julio Montoya + * @param int user id + * @param int url id + * @return boolean true if success + * */ + function relation_url_course_exist($course_id, $url_id) + { + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $sql= "SELECT course_code FROM $table_url_rel_course WHERE access_url_id = ".Database::escape_string($url_id)." AND course_code = '".Database::escape_string($course_id)."'"; + $result = Database::query($sql, __FILE__, __LINE__); + $num = Database::num_rows($result); + return $num; + } + + + /** + * Checks the relationship between an URL and a Session (return the num_rows) + * @author Julio Montoya + * @param int user id + * @param int url id + * @return boolean true if success + * */ + function relation_url_session_exist($session_id, $url_id) + { + $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $sql= "SELECT session_id FROM $table_url_rel_session WHERE access_url_id = ".Database::escape_string($url_id)." AND session_id = ".Database::escape_string($session_id); + $result = Database::query($sql, __FILE__, __LINE__); + $num = Database::num_rows($result); + return $num; + } + + + /** + * Add a group of users into a group of URLs + * @author Julio Montoya + * @param array of user_ids + * @param array of url_ids + * */ + function add_users_to_urls($user_list, $url_list) + { + $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $result_array=array(); + + if (is_array($user_list) && is_array($url_list)){ + foreach ($url_list as $url_id) { + foreach ($user_list as $user_id) { + $count = UrlManager::relation_url_user_exist($user_id,$url_id); + if ($count==0) { + $sql = "INSERT INTO $table_url_rel_user + SET user_id = ".Database::escape_string($user_id).", access_url_id = ".Database::escape_string($url_id); + $result = Database::query($sql, __FILE__, __LINE__); + if($result) + $result_array[$url_id][$user_id]=1; + else + $result_array[$url_id][$user_id]=0; + } + } + } + } + return $result_array; + } + + + /** + * Add a group of courses into a group of URLs + * @author Julio Montoya + * @param array of course ids + * @param array of url_ids + * */ + function add_courses_to_urls($course_list,$url_list) + { + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $result_array=array(); + + if (is_array($course_list) && is_array($url_list)){ + foreach ($url_list as $url_id) { + foreach ($course_list as $course_code) { + $count = UrlManager::relation_url_course_exist($course_code,$url_id); + if ($count==0) { + $sql = "INSERT INTO $table_url_rel_course + SET course_code = '".Database::escape_string($course_code)."', access_url_id = ".Database::escape_string($url_id); + $result = Database::query($sql, __FILE__, __LINE__); + if($result) + $result_array[$url_id][$course_code]=1; + else + $result_array[$url_id][$course_code]=0; + } + } + } + } + return $result_array; + } + + + /** + * Add a group of sessions into a group of URLs + * @author Julio Montoya + * @param array of session ids + * @param array of url_ids + * */ + function add_sessions_to_urls($session_list,$url_list) + { + $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $result_array=array(); + + if (is_array($session_list) && is_array($url_list)){ + foreach ($url_list as $url_id) { + foreach ($session_list as $session_id) { + $count = UrlManager::relation_url_session_exist($session_id,$url_id); + if ($count==0) { + $sql = "INSERT INTO $table_url_rel_session + SET session_id = ".Database::escape_string($session_id).", access_url_id = ".Database::escape_string($url_id); + $result = Database::query($sql, __FILE__, __LINE__); + if($result) + $result_array[$url_id][$session_id]=1; + else + $result_array[$url_id][$session_id]=0; + } + } + } + } + return $result_array; + } + + + + /** + * Add a user into a url + * @author Julio Montoya + * @param user_id + * @param url_id + * @return boolean true if success + * */ + function add_user_to_group($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER) + { + $table_url_rel_group = Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP); + if (!empty($user_id) && !empty($group_id)) { + $role = self::get_user_group_role($user_id,$group_id); + if ($role==0) { + $sql = "INSERT INTO $table_url_rel_group + SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type); + $result = Database::query($sql, __FILE__, __LINE__); + } + } + return $result; + } + + function add_course_to_url($course_code, $url_id=1) + { + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + if (empty($url_id)) $url_id=1; + $count = UrlManager::relation_url_course_exist($course_code,$url_id); + if (empty($count)) { + $sql = "INSERT INTO $table_url_rel_course + SET course_code = '".Database::escape_string($course_code)."', access_url_id = ".Database::escape_string($url_id); + $result = Database::query($sql, __FILE__, __LINE__); + } + return $result; + } + + + function add_session_to_url($session_id, $url_id=1) + { + $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + if (empty($url_id)) $url_id=1; + $count = UrlManager::relation_url_session_exist($session_id,$url_id); + if (empty($count)) { + $sql = "INSERT INTO $table_url_rel_session + SET session_id = ".Database::escape_string($session_id).", access_url_id = ".Database::escape_string($url_id); + $result = Database::query($sql, __FILE__, __LINE__); + } + return $result; + } + + + /** + * Deletes an url and user relationship + * @author Julio Montoya + * @param int user id + * @param int url id + * @return boolean true if success + * */ + function delete_url_rel_user($user_id, $url_id) + { + $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql= "DELETE FROM $table_url_rel_user WHERE user_id = ".Database::escape_string($user_id)." AND access_url_id=".Database::escape_string($url_id)." "; + $result = Database::query($sql, __FILE__, __LINE__); + return $result; + } + + /** + * Deletes an url and course relationship + * @author Julio Montoya + * @param char course code + * @param int url id + * @return boolean true if success + * */ + function delete_url_rel_course($course_code, $url_id) + { + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $sql= "DELETE FROM $table_url_rel_course WHERE course_code = '".Database::escape_string($course_code)."' AND access_url_id=".Database::escape_string($url_id)." "; + $result = Database::query($sql, __FILE__, __LINE__); + return $result; + } + + /** + * Deletes an url and session relationship + * @author Julio Montoya + * @param char course code + * @param int url id + * @return boolean true if success + * */ + function delete_url_rel_session($session_id, $url_id) + { + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $sql= "DELETE FROM $table_url_rel_session WHERE session_id = ".Database::escape_string($session_id)." AND access_url_id=".Database::escape_string($url_id)." "; + $result = Database::query($sql, __FILE__, __LINE__); + return $result; + } + + + /** + * Updates the access_url_rel_user table with a given user list + * @author Julio Montoya + * @param array user list + * @param int access_url_id + * */ + function update_urls_rel_user($user_list,$access_url_id) + { + $table_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + + $sql = "SELECT user_id FROM $table_url_rel_user WHERE access_url_id=".Database::escape_string($access_url_id); + $result = Database::query($sql,__FILE__,__LINE__ ); + $existingUsers = array(); + + while($row = Database::fetch_array($result)){ + $existingUsers[] = $row['user_id']; + } + + //adding users + foreach($user_list as $enreg_user) { + if(!in_array($enreg_user, $existingUsers)) { + UrlManager::add_user_to_url($enreg_user,$access_url_id); + } + } + //deleting old users + foreach($existingUsers as $existing_user) { + if(!in_array($existing_user, $user_list)) { + UrlManager::delete_url_rel_user($existing_user,$access_url_id); + } + } + } + + + /** + * Updates the access_url_rel_course table with a given user list + * @author Julio Montoya + * @param array user list + * @param int access_url_id + * */ + function update_urls_rel_course($course_list,$access_url_id) + { + $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); + $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + + $sql = "SELECT course_code FROM $table_url_rel_course WHERE access_url_id=".Database::escape_string($access_url_id); + $result = Database::query($sql,__FILE__,__LINE__ ); + $existing_courses = array(); + + while($row = Database::fetch_array($result)){ + $existing_courses[] = $row['course_code']; + } + + //adding courses + foreach($course_list as $course) { + if(!in_array($course, $existing_courses)) { + UrlManager::add_course_to_url($course,$access_url_id); + } + } + + //deleting old courses + foreach($existing_courses as $existing_course) { + if(!in_array($existing_course, $course_list)) { + UrlManager::delete_url_rel_course($existing_course,$access_url_id); + } + } + } + + /** + * Updates the access_url_rel_session table with a given user list + * @author Julio Montoya + * @param array user list + * @param int access_url_id + * */ + function update_urls_rel_session($session_list,$access_url_id) + { + $table_session = Database :: get_main_table(TABLE_MAIN_SESSION); + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + + $sql = "SELECT session_id FROM $table_url_rel_session WHERE access_url_id=".Database::escape_string($access_url_id); + $result = Database::query($sql,__FILE__,__LINE__ ); + $existing_sessions = array(); + + while($row = Database::fetch_array($result)){ + $existing_sessions[] = $row['session_id']; + } + + //adding users + foreach($session_list as $session) { + if(!in_array($session, $existing_sessions)) { + UrlManager::add_session_to_url($session,$access_url_id); + } + } + + //deleting old users + foreach($existing_sessions as $existing_session) { + if(!in_array($existing_session, $session_list)) { + UrlManager::delete_url_rel_session($existing_session,$access_url_id); + } + } + } + + + function get_access_url_from_user($user_id) { + $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT url, access_url_id FROM $table_url_rel_user url_rel_user INNER JOIN $table_url u + ON (url_rel_user.access_url_id = u.id) + WHERE user_id = ".Database::escape_string($user_id); + $result = Database::query($sql, __FILE__, __LINE__); + $url_list = Database::store_result($result); + return $url_list; + } + + /** + * + * */ + function get_url_id($url) + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."'"; + $result = Database::query($sql); + $access_url_id = Database::result($result, 0, 0); + return $access_url_id; + } + + + public static function get_all_group_tags($tag, $from=0, $number_of_items=10) { + // database table definition + + $group_table = Database::get_main_table(TABLE_MAIN_GROUP); + $table_tag = Database::get_main_table(TABLE_MAIN_TAG); + $table_group_tag_values = Database::get_main_table(TABLE_MAIN_GROUP_REL_TAG); + + //default field_id == 1 + + $field_id = 5; + + $tag = Database::escape_string($tag); + $from = intval($from); + $number_of_items = intval($number_of_items); + + // all the information of the field + $sql = "SELECT g.id, g.name, g.description, g.picture_uri FROM $table_tag t INNER JOIN $table_group_tag_values tv ON (tv.tag_id=t.id) + INNER JOIN $group_table g ON(tv.group_id =g.id) + WHERE tag LIKE '$tag%' AND field_id= $field_id ORDER BY tag"; + + $sql .= " LIMIT $from,$number_of_items"; + + $result = Database::query($sql, __FILE__, __LINE__); + $return = array(); + if (Database::num_rows($result)> 0) { + while ($row = Database::fetch_array($result,'ASSOC')) { + $return[$row['id']] = $row; + } + } + + $keyword = $tag; + $sql = "SELECT g.id, g.name, g.description, g.url, g.picture_uri FROM $group_table g"; + + //@todo implement groups + multiple urls + + /* + global $_configuration; + if ($_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; + }*/ + + //@todo implement visibility + + if (isset ($keyword)) { + $keyword = Database::escape_string($keyword); + $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )"; + } + + $direction = 'ASC'; + if (!in_array($direction, array('ASC','DESC'))) { + $direction = 'ASC'; + } + + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + + //$sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $res = Database::query($sql, __FILE__, __LINE__); + if (Database::num_rows($res)> 0) { + while ($row = Database::fetch_array($res,'ASSOC')) { + if (!in_array($row['id'], $return)) { + $return[$row['id']] = $row; + } + } + } + return $return; + } + + + /** + * Creates new user pfotos in various sizes of a user, or deletes user pfotos. + * Note: This method relies on configuration setting from dokeos/main/inc/conf/profile.conf.php + * @param int $user_id The user internal identitfication number. + * @param string $file The common file name for the newly created pfotos. It will be checked and modified for compatibility with the file system. + * If full name is provided, path component is ignored. + * If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() as the prefered way for deletion. + * @param string $source_file The full system name of the image from which user photos will be created. + * @return string/bool Returns the resulting common file name of created images which usually should be stored in database. + * When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE. + */ + public static function update_group_picture($group_id, $file = null, $source_file = null) { + + // Validation 1. + if (empty($group_id)) { + return false; + } + $delete = empty($file); + if (empty($source_file)) { + $source_file = $file; + } + + // Configuration options about user photos. + require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; + + // User-reserved directory where photos have to be placed. + $path_info = self::get_group_picture_path_by_id($group_id, 'system', true); + $path = $path_info['dir']; + // If this directory does not exist - we create it. + if (!file_exists($path)) { + $perm = api_get_setting('permissions_for_new_directories'); + $perm = octdec(!empty($perm) ? $perm : '0770'); + @mkdir($path, $perm, true); + } + + // The old photos (if any). + $old_file = $path_info['file']; + + // Let us delete them. + if (!empty($old_file)) { + if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) { + $prefix = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_'; + @rename($path.'small_'.$old_file, $path.$prefix.'small_'.$old_file); + @rename($path.'medium_'.$old_file, $path.$prefix.'medium_'.$old_file); + @rename($path.'big_'.$old_file, $path.$prefix.'big_'.$old_file); + @rename($path.$old_file, $path.$prefix.$old_file); + } else { + @unlink($path.'small_'.$old_file); + @unlink($path.'medium_'.$old_file); + @unlink($path.'big_'.$old_file); + @unlink($path.$old_file); + } + } + + // Exit if only deletion has been requested. Return an empty picture name. + if ($delete) { + return ''; + } + + // Validation 2. + $allowed_types = array('jpg', 'jpeg', 'png', 'gif'); + $file = str_replace('\\', '/', $file); + $filename = (($pos = strrpos($file, '/')) !== false) ? substr($file, $pos + 1) : $file; + $extension = strtolower(substr(strrchr($filename, '.'), 1)); + if (!in_array($extension, $allowed_types)) { + return false; + } + + // This is the common name for the new photos. + if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) { + $old_extension = strtolower(substr(strrchr($old_file, '.'), 1)); + $filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file; + $filename = (substr($filename, -1) == '.') ? $filename.$extension : $filename.'.'.$extension; + } else { + $filename = replace_dangerous_char($filename); + if (PREFIX_IMAGE_FILENAME_WITH_UID) { + $filename = uniqid('').'_'.$filename; + } + // We always prefix user photos with user ids, so on setting + // api_get_setting('split_users_upload_directory') === 'true' + // the correspondent directories to be found successfully. + $filename = $group_id.'_'.$filename; + } + + // Storing the new photos in 4 versions with various sizes. + + $picture_info = @getimagesize($source_file); + $type = $picture_info[2]; + $small = self::resize_picture($source_file, 22); + $medium = self::resize_picture($source_file, 85); + $normal = self::resize_picture($source_file, 200); + $big = new image($source_file); // This is the original picture. + + $ok = false; + $detected = array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG'); + if (in_array($type, array_keys($detected))) { + $ok = $small->send_image($detected[$type], $path.'small_'.$filename) + && $medium->send_image($detected[$type], $path.'medium_'.$filename) + && $normal->send_image($detected[$type], $path.$filename) + && $big->send_image($detected[$type], $path.'big_'.$filename); + } + return $ok ? $filename : false; + } + + /** + * Get user picture URL or path from user ID (returns an array). + * The return format is a complete path, enabling recovery of the directory + * with dirname() or the file with basename(). This also works for the + * functions dealing with the user's productions, as they are located in + * the same directory. + * @param integer User ID + * @param string Type of path to return (can be 'none', 'system', 'rel', 'web') + * @param bool Whether we want to have the directory name returned 'as if' there was a file or not (in the case we want to know which directory to create - otherwise no file means no split subdir) + * @param bool If we want that the function returns the /main/img/unknown.jpg image set it at true + * @return array Array of 2 elements: 'dir' and 'file' which contain the dir and file as the name implies if image does not exist it will return the unknow image if anonymous parameter is true if not it returns an empty er's + */ + public static function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) { + + switch ($type) { + case 'system': // Base: absolute system path. + $base = api_get_path(SYS_CODE_PATH); + break; + case 'rel': // Base: semi-absolute web path (no server base). + $base = api_get_path(REL_CODE_PATH); + break; + case 'web': // Base: absolute web path. + $base = api_get_path(WEB_CODE_PATH); + break; + case 'none': + default: // Base: empty, the result path below will be relative. + $base = ''; + } + + if (empty($id) || empty($type)) { + return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => ''); + } + + $id = intval($id); + + $group_table = Database :: get_main_table(TABLE_MAIN_GROUP); + $sql = "SELECT picture_uri FROM $group_table WHERE id=".$id; + $res = Database::query($sql, __FILE__, __LINE__); + + if (!Database::num_rows($res)) { + return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => ''); + } + + $user = Database::fetch_array($res); + $picture_filename = trim($user['picture_uri']); + + if (api_get_setting('split_users_upload_directory') === 'true') { + if (!empty($picture_filename)) { + $dir = $base.'upload/users/groups/'.substr($picture_filename, 0, 1).'/'.$id.'/'; + } elseif ($preview) { + $dir = $base.'upload/users/groups/'.substr((string)$id, 0, 1).'/'.$id.'/'; + } else { + $dir = $base.'upload/users/groups/'.$id.'/'; + } + } else { + $dir = $base.'upload/users/groups/'.$id.'/'; + } + if (empty($picture_filename) && $anonymous) { + return array('dir' => $base.'img/', 'file' => 'unknown.jpg'); + } + return array('dir' => $dir, 'file' => $picture_filename); + } + + /** + * Resize a picture + * + * @param string file picture + * @param int size in pixels + * @return obj image object + */ + public static function resize_picture($file, $max_size_for_picture) { + if (!class_exists('image')) { + require_once api_get_path(LIBRARY_PATH).'image.lib.php'; + } + $temp = new image($file); + $picture_infos = api_getimagesize($file); + if ($picture_infos[0] > $max_size_for_picture) { + $thumbwidth = $max_size_for_picture; + if (empty($thumbwidth) or $thumbwidth == 0) { + $thumbwidth = $max_size_for_picture; + } + $new_height = round(($thumbwidth / $picture_infos[0]) * $picture_infos[1]); + if ($new_height > $max_size_for_picture) + $new_height = $thumbwidth; + $temp->resize($thumbwidth, $new_height, 0); + } + return $temp; + } + /** + * Gets the current user image + * @param string user id + * @param string picture user name + * @param string height + * @param string picture size it can be small_, medium_ or big_ + * @param string style css + * @return array with the file and the style of an image i.e $array['file'] $array['style'] + */ + public static function get_picture_group($id, $picture_file, $height, $size_picture = 'medium_', $style = '') { + $patch_profile = 'upload/users/groups/'; + $picture = array(); + $picture['style'] = $style; + if ($picture_file == 'unknown.jpg') { + $picture['file'] = api_get_path(WEB_CODE_PATH).'img/'.$picture_file; + return $picture; + } + $image_array_sys = self::get_group_picture_path_by_id($id, 'system', false, true); + $image_array = self::get_group_picture_path_by_id($id, 'web', false, true); + $file = $image_array_sys['dir'].$size_picture.$picture_file; + if (file_exists($file)) { + $picture['file'] = $image_array['dir'].$size_picture.$picture_file; + $picture['style'] = ''; + if ($height > 0) { + $dimension = api_getimagesize($picture['file']); + $margin = (($height - $dimension[1]) / 2); + //@ todo the padding-top should not be here + $picture['style'] = ' style="padding-top:'.$margin.'px; width:'.$dimension[0].'px; height:'.$dimension[1].';" '; + } + } else { + //$file = api_get_path(SYS_CODE_PATH).$patch_profile.$user_id.'/'.$picture_file; + $file = $image_array_sys['dir'].$picture_file; + if (file_exists($file) && !is_dir($file)) { + $picture['file'] = $image_array['dir'].$picture_file; + } else { + $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_group.png'; + } + } + return $picture; + } + + public static function delete_group_picture($user_id) { + return self::update_group_picture($user_id); + } +} +?> \ No newline at end of file diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 71521069c0..02b3589d80 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -143,6 +143,7 @@ define('SECTION_COURSE_ADMIN', 'course_admin'); define('SECTION_PLATFORM_ADMIN', 'platform_admin'); define('SECTION_MYGRADEBOOK', 'mygradebook'); define('SECTION_TRACKING','session_my_space'); +define('SECTION_SOCIAL', 'social'); // CONSTANT name for local authentication source define('PLATFORM_AUTH_SOURCE', 'platform'); @@ -2285,8 +2286,6 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us $time = date("Y-m-d H:i:s", $time); if (!empty($session_id)) { $session_id = intval($session_id); - } else { - $session_id = api_get_session_id(); } // Definition of tables diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 9d6f5addbb..fb945a1d0d 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -25,70 +25,63 @@ require_once api_get_path(LIBRARY_PATH).'online.inc.php'; require_once api_get_path(SYS_CODE_PATH).'messages/message.class.php'; function inbox_display() { - global $charset; - echo ''; - $charset = api_get_setting('platform_charset'); - $table_message = Database::get_main_table(TABLE_MESSAGE); - $request=api_is_xml_http_request(); - if ($_SESSION['social_exist']===true) { - $redirect="#remote-tab-2"; - if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') { - $success= get_lang('SelectedMessagesDeleted'); - } else { - $success= get_lang('SelectedMessagesDeleted'); - } + global $charset; +// $charset = api_get_setting('platform_charset'); + $table_message = Database::get_main_table(TABLE_MESSAGE); + $request=api_is_xml_http_request(); + if ($_SESSION['social_exist']===true) { + $redirect="#remote-tab-2"; + if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') { + $success= get_lang('SelectedMessagesDeleted'); } else { $success= get_lang('SelectedMessagesDeleted'); } - if (isset ($_REQUEST['action'])) { - switch ($_REQUEST['action']) { - case 'delete' : - $number_of_selected_messages = count($_POST['id']); - foreach ($_POST['id'] as $index => $message_id) { - MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id); - } - Display::display_normal_message(api_xml_http_response_encode($success),false); - break; - case 'deleteone' : - MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']); - Display::display_confirmation_message(api_xml_http_response_encode($success),false); - echo '
    '; - break; - } + } else { + $success= get_lang('SelectedMessagesDeleted'); + } + if (isset ($_REQUEST['action'])) { + switch ($_REQUEST['action']) { + case 'delete' : + $number_of_selected_messages = count($_POST['id']); + foreach ($_POST['id'] as $index => $message_id) { + MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id); + } + Display::display_normal_message(api_xml_http_response_encode($success),false); + break; + case 'deleteone' : + MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']); + Display::display_confirmation_message(api_xml_http_response_encode($success),false); + echo '
    '; + break; } - // display sortable table with messages of the current user - $table = new SortableTable('messages', 'get_number_of_messages_mask', 'get_message_data_mask', 3, get_number_of_messages_mask(),'DESC'); - $table->set_header(0, '', false,array ('style' => 'width:20px;')); - $title=api_xml_http_response_encode(get_lang('Title')); - $action=api_xml_http_response_encode(get_lang('Actions')); - $table->set_header(1,api_xml_http_response_encode(get_lang('Status')),false,array('style' => 'width:30px;')); - $table->set_header(2,api_xml_http_response_encode(get_lang('From')),false); - $table->set_header(3,$title,false); - $table->set_header(4,api_xml_http_response_encode(get_lang('Date')),false,array('style' => 'width:150px;')); - $table->set_header(5,$action,false,array ('style' => 'width:100px;')); - echo '
    '; - if ($request===true) { - echo '
    '; - echo ''; - $table->display(); - echo '
    '; - if (get_number_of_messages_mask() > 0) { - echo ''.api_xml_http_response_encode(get_lang('SelectAll')).'   '; - echo ''.api_xml_http_response_encode(get_lang('UnSelectAll')).'   '; - echo ''; + } + // display sortable table with messages of the current user + $table = new SortableTable('messages', 'get_number_of_messages_mask', 'get_message_data_mask', 3, get_number_of_messages_mask(),'DESC'); + $table->set_header(0, '', false,array ('style' => 'width:20px;')); + $title=api_xml_http_response_encode(get_lang('Title')); + $action=api_xml_http_response_encode(get_lang('Actions')); + $table->set_header(1,api_xml_http_response_encode(get_lang('Status')),false,array('style' => 'width:30px;')); + $table->set_header(2,api_xml_http_response_encode(get_lang('From')),false); + $table->set_header(3,$title,false); + $table->set_header(4,api_xml_http_response_encode(get_lang('Date')),false,array('style' => 'width:150px;')); + $table->set_header(5,$action,false,array ('style' => 'width:100px;')); + echo '
    '; + if ($request===true) { + echo '
    '; + echo ''; + $table->display(); + echo '
    '; + if (get_number_of_messages_mask() > 0) { + echo ''.api_xml_http_response_encode(get_lang('SelectAll')).'   '; + echo ''.api_xml_http_response_encode(get_lang('UnSelectAll')).'   '; + echo ''; - } - } else { - $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages'))); - $table->display(); } - echo '
    '; + } else { + $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages'))); + $table->display(); + } + echo '
    '; } function get_number_of_messages_mask() { return MessageManager::get_number_of_messages(); diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index c6032c5986..6f8a32e0d6 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -7,8 +7,9 @@ define(SOCIALFRIEND,3); define(SOCIALGOODFRIEND,4); define(SOCIALENEMY,5); define(SOCIALDELETED,6); +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; -class UserFriend extends UserManager { +class SocialManager extends UserManager { private function __construct() { @@ -332,4 +333,248 @@ class UserFriend extends UserManager { } } } + + /** + * Get user's feeds + * @param int User ID + * @param int Limit of posts per feed + * @return string HTML section with all feeds included + * @author Yannick Warnier + * @since Dokeos 1.8.6.1 + */ + function get_user_feeds($user,$limit=5) { + if (!function_exists('fetch_rss')) { return '';} + $fields = UserManager::get_extra_fields(); + $feed_fields = array(); + $feeds = array(); + $res = '
    '.get_lang('RSSFeeds').'
    '; + $res .= ''; + $res .= '

    '; + return $res; + } + + /** + * Helper functions definition + */ + function get_logged_user_course_html($my_course, $count) { + global $nosession; + if (api_get_setting('use_session_mode')=='true' && !$nosession) { + global $now, $date_start, $date_end; + } + //initialise + $result = ''; + // Table definitions + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); + $course_database = $my_course['db']; + $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database); + $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database); + + $user_id = api_get_user_id(); + $course_system_code = $my_course['k']; + $course_visual_code = $my_course['c']; + $course_title = $my_course['i']; + $course_directory = $my_course['d']; + $course_teacher = $my_course['t']; + $course_teacher_email = isset($my_course['email'])?$my_course['email']:''; + $course_info = Database :: get_course_info($course_system_code); + //error_log(print_r($course_info,true)); + $course_access_settings = CourseManager :: get_access_settings($course_system_code); + + $course_visibility = $course_access_settings['visibility']; + + $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code); + //function logic - act on the data + $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']); + if ($is_virtual_course) { + // If the current user is also subscribed in the real course to which this + // virtual course is linked, we don't need to display the virtual course entry in + // the course list - it is combined with the real course entry. + $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code); + $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); + if ($is_subscribed_in_target_course) { + return; //do not display this course entry + } + } + $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id()); + if ($has_virtual_courses) { + $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); + $course_display_title = $return_result['title']; + $course_display_code = $return_result['code']; + } else { + $course_display_title = $course_title; + $course_display_code = $course_visual_code; + } + $s_course_status=$my_course['s']; + $s_htlm_status_icon=""; + + if ($s_course_status==1) { + $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher')); + } + if ($s_course_status==2) { + $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach')); + } + if ($s_course_status==5) { + $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student')); + } + + //display course entry + $result .= '
    '; + //$result .= ''; + $result .= '

    '; + $result .= $s_htlm_status_icon; + + //show a hyperlink to the course, unless the course is closed and user is not course admin + if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { + $result .= ' '.$course_title.'

    '; + /* + if(api_get_setting('use_session_mode')=='true' && !$nosession) { + if(empty($my_course['id_session'])) { + $my_course['id_session'] = 0; + } + if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') { + //$result .= ''.$course_display_title.''; + $result .= ''.$course_display_title.''; + } + } else { + //$result .= ''.$course_display_title.''; + $result .= ''.$course_display_title.''; + }*/ + } else { + $result .= $course_display_title." "." ".get_lang('CourseClosed').""; + } + // show the course_code and teacher if chosen to display this + // we dont need this! + /* + if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= '
    '; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + $result .= $course_display_code; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= ' – '; + } + if (api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= $course_teacher; + if(!empty($course_teacher_email)) { + $result .= ' ('.$course_teacher_email.')'; + } + } + */ + $current_course_settings = CourseManager :: get_access_settings($my_course['k']); + // display the what's new icons + // $result .= show_notification($my_course); + if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) { + reset($digest); + $result .= '
      '; + while (list ($key2) = each($digest[$thisCourseSysCode])) { + $result .= '
    • '; + if ($orderKey[1] == 'keyTools') { + $result .= ""; + $result .= "$toolsList[$key2][\"name\"]"; + } else { + $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2)); + } + $result .= '
    • '; + $result .= '
        '; + reset($digest[$thisCourseSysCode][$key2]); + while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) { + $result .= '
      • '; + if ($orderKey[2] == 'keyTools') { + $result .= ""; + $result .= "$toolsList[$key3][\"name\"]"; + } else { + $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3)); + } + $result .= '
          '; + reset($digest[$thisCourseSysCode][$key2][$key3]); + while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) { + $result .= '
        • '; + $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT)); + $result .= '
        • '; + } + $result .= '
        '; + $result .= '
      • '; + } + $result .= '
      '; + $result .= ''; + } + $result .= '
    '; + } + $result .= ''; + $result .= '
    '; + + if (api_get_setting('use_session_mode')=='true' && !$nosession) { + $session = ''; + $active = false; + if (!empty($my_course['session_name'])) { + + // Request for the name of the general coach + $sql = 'SELECT lastname, firstname + FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu + ON ts.id_coach = tu.user_id + WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1'; + $rs = Database::query($sql, __FILE__, __LINE__); + $sessioncoach = Database::store_result($rs); + $sessioncoach = $sessioncoach[0]; + + $session = array(); + $session['title'] = $my_course['session_name']; + if ( $my_course['date_start']=='0000-00-00' ) { + $session['dates'] = get_lang('WithoutTimeLimits'); + if ( api_get_setting('show_session_coach') === 'true' ) { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = true; + } else { + $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end']; + if ( api_get_setting('show_session_coach') === 'true' ) { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = ($date_start <= $now && $date_end >= $now)?true:false; + } + } + $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active); + } else { + $output = array ($my_course['user_course_cat'], $result); + } + //$my_course['creation_date']; + return $output; + } + + public static function show_social_menu() { + echo ''; + } } \ No newline at end of file diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index 46575e8032..e5e4c61a1a 100644 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -378,10 +378,7 @@ class SortableTable extends HTML_Table { $html .= '
    '; } } - $items = $this->get_clean_html(); // getting the items of the table - - - + $items = $this->get_clean_html(); // getting the items of the table // the generating of style classes must be improved. Maybe we need a a table name to create style on the fly: // i.e: .whoisonline_table_grid_container instead of .grid_container // where whoisonline is the table's name like drupal's template engine @@ -432,6 +429,103 @@ class SortableTable extends HTML_Table { echo $html; } + public function display_simple_grid($vibility_options, $hide_navigation) { + global $charset; + $empty_table = false; + $html = ''; + if ($this->get_total_number_of_items() == 0) { + $cols = $this->getColCount(); + //$this->setCellAttributes(1, 0, 'style="font-style: italic;text-align:center;" colspan='.$cols); + if (api_is_xml_http_request()===true) { + $message_empty=api_utf8_encode(get_lang('TheListIsEmpty')); + } else { + $message_empty=get_lang('TheListIsEmpty'); + } + $this->setCellContents(1, 0,$message_empty); + $empty_table = true; + } + $html=''; + + if (!$empty_table) { + //if we show the pagination + if ($hide_navigation == false ) { + $form = $this->get_page_select_form(); + $nav = $this->get_navigation_html(); + + //this also must be moved + $html = '
    '; + $html .= '
    '.$form.'
    '; + $html .= '
    '.$this->get_table_title().'
    '; + $html .= '
    '.$nav.'
    '; + $html .= '
    '; + } + $html .= '
    '; + if (count($this->form_actions) > 0) { + $script= ''; + $params = $this->get_sortable_table_param_string().'&'.$this->get_additional_url_paramstring(); + $html .= ''; + } + } + + // @todo This style css must be moved to default.css only for dev + echo ''; + + $items = $this->get_clean_html(); // getting the items of the table + // the generating of style classes must be improved. Maybe we need a a table name to create style on the fly: + // i.e: .whoisonline_table_grid_container instead of .grid_container + // where whoisonline is the table's name like drupal's template engine + + if (is_array($vibility_options)) { + $filter = false; // the 2nd condition of the if will be loaded + } else { + if ($vibility_options === false) { + $filter = false; + } else { + $filter = true; + } + } + + $html .= '
    '; + if (is_array($items) && count($items)>0 ) { + foreach($items as $row) { + $html.= '
    '; + $i=0; + foreach($row as $element) { + if ( $filter === true || $vibility_options[$i] == true) { + $html.='
    '.$element.'
    '; + } + $i++; + } + $html.='
    '; + } + } + $html.='
    '; + $html .= '
    '; + echo $html; + } + /** * Get the HTML-code with the navigational buttons to browse through the * data-pages. diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index d68547e0b5..12d80cc23e 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -639,13 +639,12 @@ class UserManager } else { $dir = $base.'upload/users/'.$user_id.'/'; } - if (empty($picture_filename) && $anonymous) { return array('dir' => $base.'img/', 'file' => 'unknown.jpg'); } - return array('dir' => $dir, 'file' => $picture_filename); } + /** * Creates new user pfotos in various sizes of a user, or deletes user pfotos. @@ -687,7 +686,7 @@ class UserManager // Let us delete them. if (!empty($old_file)) { - if (api_get_setting('permanently_remove_deleted_files') == 'false') { + if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) { $prefix = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_'; @rename($path.'small_'.$old_file, $path.$prefix.'small_'.$old_file); @rename($path.'medium_'.$old_file, $path.$prefix.'medium_'.$old_file); @@ -2206,10 +2205,10 @@ class UserManager } } else { //$file = api_get_path(SYS_CODE_PATH).$patch_profile.$user_id.'/'.$picture_file; - $file = $image_array_sys['dir'].$picture_file; - if (file_exists($file)) { + $file = $image_array_sys['dir'].$picture_file; + if (file_exists($file) && !is_dir($file)) { $picture['file'] = $image_array['dir'].$picture_file; - } else { + } else { $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown.jpg'; } } @@ -2272,7 +2271,7 @@ class UserManager */ public static function get_tags($tag, $field_id, $return_format='json',$limit=10) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $field_id = intval($field_id); //like '%$tag%' $limit = intval($limit); @@ -2295,10 +2294,10 @@ class UserManager public static function get_top_tags($field_id, $limit=100) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); - $field_id = intval($field_id); - $limit = intval($limit); + $field_id = intval($field_id); + $limit = intval($limit); // all the information of the field $sql = "SELECT count(*) count, tag FROM $table_user_tag_values uv INNER JOIN $table_user_tag ut ON(ut.id = uv.tag_id) WHERE field_id = $field_id GROUP BY tag_id ORDER BY count DESC LIMIT $limit"; @@ -2320,7 +2319,7 @@ class UserManager */ public static function get_user_tags($user_id,$field_id) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $field_id = intval($field_id); $user_id = intval($user_id); @@ -2338,34 +2337,38 @@ class UserManager return $return; } - /** - * Searchs user with a specific tag - * @param string the tag - * @param int field id of the tag + + /** + * Get user's tags + * @param int field_id + * @param int user_id * @return array */ - public static function get_all_user_tags($tag, $field_id, $from, $number_of_items) { + public static function get_user_tags_to_string($user_id,$field_id) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $field_id = intval($field_id); - $tag = Database::escape_string($tag); - $from = intval($from); - $number_of_items = intval($number_of_items); - + $user_id = intval($user_id); + // all the information of the field - $sql = "SELECT u.user_id,u.username,firstname, lastname, tag FROM $table_user_tag ut INNER JOIN $table_user_tag_values uv ON (uv.tag_id=ut.ID) - INNER JOIN user u ON(uv.user_id =u.user_id) - WHERE field_id = $field_id AND tag LIKE '$tag%' ORDER BY tag"; - - $sql .= " LIMIT $from,$number_of_items"; + $sql = "SELECT ut.id, tag,count FROM $table_user_tag ut INNER JOIN $table_user_tag_values uv ON (uv.tag_id=ut.ID) + WHERE field_id = $field_id AND user_id = $user_id ORDER BY tag"; $result = Database::query($sql, __FILE__, __LINE__); $return = array(); if (Database::num_rows($result)> 0) { while ($row = Database::fetch_array($result,'ASSOC')) { - $return[$row['user_id']] = $row; + $return[$row['id']] = array('tag'=>$row['tag'],'count'=>$row['count']); } } + $user_tags = $return; + $tag_tmp = array(); + foreach ($user_tags as $tag) { + $tag_tmp[] = ''.$tag['tag'].''; + } + if (is_array($user_tags) && count($user_tags)>0) { + $return = implode(', ',$tag_tmp); + } return $return; } @@ -2377,7 +2380,7 @@ class UserManager * @return int 0 if fails otherwise the tag id */ public function get_tag_id($tag, $field_id) { - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $tag = Database::escape_string($tag); $field_id = intval($field_id); //with COLLATE latin1_bin to select query in a case sensitive mode @@ -2398,7 +2401,7 @@ class UserManager * @return int 0 if fails otherwise the tag id */ public function get_tag_id_from_id($tag_id, $field_id) { - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $tag_id = intval($tag_id); $field_id = intval($field_id); $sql = "SELECT id FROM $table_user_tag WHERE id = '$tag_id' AND field_id = $field_id"; @@ -2421,7 +2424,7 @@ class UserManager */ public function add_tag($tag, $user_id, $field_id) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $tag = Database::escape_string($tag); $user_id = intval($user_id); @@ -2483,7 +2486,7 @@ class UserManager */ public function delete_user_tags($user_id, $field_id) { // database table definition - $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_TAG); + $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $tags = UserManager::get_user_tags($user_id, $field_id); //echo '
    ';var_dump($tags);
    @@ -2518,7 +2521,8 @@ class UserManager
     			UserManager::add_tag($tags,$user_id, $field_id);
     		}
     		return true;
    -	}	
    +	}
    +	
     	/**
     	 * Gives a list of emails from all administrators
     	 * @author cvargas carlos.vargas@dokeos.com
    @@ -2538,5 +2542,192 @@ class UserManager
     		}
     		return $return;
     	 }	
    +
     	
    +	/**
    +	 * Searchs an user (tags, firstname, lastname and email )
    +	 * @param string the tag
    +	 * @param int field id of the tag
    +	 * @return array
    +	 */
    +	public static function get_all_user_tags($tag, $field_id = 0, $from=0, $number_of_items=10) {
    +		// database table definition
    +		
    +		$user_table 			= Database::get_main_table(TABLE_MAIN_USER);
    +		$table_user_tag			= Database::get_main_table(TABLE_MAIN_TAG);
    +		$table_user_tag_values	= Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
    +		$field_id = intval($field_id);
    +		$tag = Database::escape_string($tag);
    +		$from = intval($from);
    +    	$number_of_items = intval($number_of_items);
    +    	$where_field = "";
    +		if ($field_id != 0) {
    +			$where_field = " field_id = $field_id AND ";
    +		}
    +		// all the information of the field
    +		 $sql = "SELECT u.user_id,u.username,firstname, lastname, email, tag, picture_uri FROM $table_user_tag ut INNER JOIN $table_user_tag_values uv ON (uv.tag_id=ut.id)
    +				INNER JOIN $user_table u ON(uv.user_id =u.user_id)
    +				WHERE $where_field tag LIKE '$tag%' ORDER BY tag";
    +				
    +		$sql .= " LIMIT $from,$number_of_items";
    +		
    +		$result = Database::query($sql, __FILE__, __LINE__);
    +		$return = array();
    +		if (Database::num_rows($result)> 0) {
    +			while ($row = Database::fetch_array($result,'ASSOC')) {
    +				$return[$row['user_id']] = $row;
    +			}
    +		}
    +		 
    +		$keyword = $tag;
    +		$sql = "SELECT u.user_id, u.username, firstname, lastname, email, picture_uri FROM $user_table u";
    +		global $_configuration;
    +		if ($_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
    +			$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
    +			$sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
    +		}
    +		
    +		if (isset ($keyword)) {
    +				$keyword = Database::escape_string($keyword);
    +				//OR u.official_code LIKE '%".$keyword."%' 
    +				// OR u.email LIKE '%".$keyword."%'
    +				$sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%'  OR u.username LIKE '%".$keyword."%'  )";
    +			}
    +		$keyword_active = true;
    +		//only active users
    +		if ($keyword_active) {
    +			$sql .= " AND u.active='1'";
    +		} 
    +	
    +	    // adding the filter to see the user's only of the current access_url
    +		if ($_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
    +	    		$sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
    +	    }
    +		$direction = 'ASC';
    +	    if (!in_array($direction, array('ASC','DESC'))) {
    +	    	$direction = 'ASC';
    +	    }
    +	    
    +	    $column = intval($column);
    +	    $from = intval($from);
    +	    $number_of_items = intval($number_of_items);
    +	
    +		//$sql .= " ORDER BY col$column $direction ";
    +		$sql .= " LIMIT $from,$number_of_items";
    +
    +		$res = Database::query($sql, __FILE__, __LINE__);
    +		if (Database::num_rows($res)> 0) {
    +			while ($row = Database::fetch_array($res,'ASSOC')) { 
    +				if (!in_array($row['user_id'], $return)) {			
    +					$return[$row['user_id']] = $row;
    +				}
    +			}
    +		}
    +		return $return;
    +	}
    +	
    +	/**
    +	 * Show the search form
    +	 * @param string the value of the search box
    +	 * 
    +	 */
    +	public function get_search_form($query) {
    +		echo'
    +
    +		
    +		
    +		
    +		
    +		
    +
    +
    + Search (Users, Groups) +
    +
    + + +
    +
    '; + } + //deprecated + public function get_public_users($keyword, $from = 0, $number_of_items= 20, $column=2, $direction='ASC') { + + $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); + $sql = "SELECT + u.user_id AS col0, + u.official_code AS col1, + ".(api_is_western_name_order() + ? "u.firstname AS col2, + u.lastname AS col3," + : "u.lastname AS col2, + u.firstname AS col3,")." + u.username AS col4, + u.email AS col5, + u.status AS col6, + u.active AS col7, + u.user_id AS col8 ". + ", u.expiration_date AS exp ". + " FROM $user_table u "; + + // adding the filter to see the user's only of the current access_url + global $_configuration; + if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; + } + + if (isset ($keyword)) { + $keyword = Database::escape_string($keyword); + //OR u.official_code LIKE '%".$keyword."%' + $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' )"; + } + $keyword_active = true; + //only active users + if ($keyword_active) { + $sql .= " AND u.active='1'"; + } + + // adding the filter to see the user's only of the current access_url + if ($_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { + $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); + } + + if (!in_array($direction, array('ASC','DESC'))) { + $direction = 'ASC'; + } + + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + $res = Database::query($sql, __FILE__, __LINE__); + + $users = array (); + $t = time(); + while ($user = Database::fetch_row($res)) { + if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') { + // check expiration date + $expiration_time = convert_mysql_date($user[9]); + // if expiration date is passed, store a special value for active field + if ($expiration_time < $t) { + $user[7] = '-1'; + } + } + // forget about the expiration date field + $users[] = array($user[0],$user[1],$user[2],$user[3],$user[4],$user[5],$user[6],$user[7],$user[8]); + } + return $users; + } + function show_menu(){ + echo ''; + } } diff --git a/main/install/dokeos_main.sql b/main/install/dokeos_main.sql index 3e108d850c..4383aa861d 100644 --- a/main/install/dokeos_main.sql +++ b/main/install/dokeos_main.sql @@ -2271,7 +2271,7 @@ CREATE TABLE session_category ( -- -CREATE TABLE user_tag ( +CREATE TABLE tag ( id int NOT NULL auto_increment, tag varchar(255) NOT NULL, field_id int NOT NULL, @@ -2287,3 +2287,34 @@ CREATE TABLE user_rel_tag ( PRIMARY KEY (id) ); +-- +-- Table structure for user platform groups +-- + +CREATE TABLE `group` ( + id int NOT NULL AUTO_INCREMENT, + name varchar(255) NOT NULL, + description varchar(255) NOT NULL, + picture_uri varchar(255) NOT NULL, + url varchar(255) NOT NULL, + visibility int NOT NULL, + updated_on varchar(255) NOT NULL, + created_on varchar(255) NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE group_rel_tag ( + id int NOT NULL AUTO_INCREMENT, + tag_id int NOT NULL, + group_id int NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE group_rel_user ( + id int NOT NULL AUTO_INCREMENT, + group_id int NOT NULL, + user_id int NOT NULL, + relation_type int NOT NULL, + PRIMARY KEY (id) +); + diff --git a/main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql b/main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql index c8edcf7ea4..89aa7df8f8 100755 --- a/main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql +++ b/main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql @@ -1,77 +1,74 @@ --- This script updates the databases structure before migrating the data from --- version 1.8.6.1 to version 1.8.6.2 --- it is intended as a standalone script, however, because of the multiple --- databases related difficulties, it should be parsed by a PHP script in --- order to connect to and update the right databases. --- There is one line per query, allowing the PHP function file() to read --- all lines separately into an array. The xxMAINxx-type markers are there --- to tell the PHP script which database we're talking about. --- By always using the keyword "TABLE" in the queries, we should be able --- to retrieve and modify the table name from the PHP script if needed, which --- will allow us to deal with the unique-database-type installations --- --- This first part is for the main database --- xxMAINxx -ALTER TABLE gradebook_evaluation ADD COLUMN type varchar(40) NOT NULL; -ALTER TABLE session ADD COLUMN visibility int NOT NULL default 1; -ALTER TABLE session ADD COLUMN session_category_id INT NOT NULL; - -ALTER TABLE session_rel_course_rel_user ADD COLUMN visibility int NOT NULL default 1; -ALTER TABLE session_rel_course_rel_user ADD COLUMN status int NOT NULL default 0; -CREATE TABLE session_category (id int(11) NOT NULL auto_increment, name varchar(100) default NULL, date_start date default NULL, date_end date default NULL, PRIMARY KEY (id)); - - -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_coach_to_edit_course_session', NULL, 'radio', 'Course', 'false', 'AllowCoachsToEditInsideTrainingSessions', 'AllowCoachsToEditInsideTrainingSessionsComment', NULL, NULL, 0); -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable) VALUES ('show_courses_descriptions_in_catalog', NULL, 'radio', 'Course', 'true', 'ShowCoursesDescriptionsInCatalogTitle', 'ShowCoursesDescriptionsInCatalogComment', NULL, NULL, 1, 1); -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable) VALUES ('show_glossary_in_extra_tools', NULL, 'radio', 'Course', 'false', 'ShowGlossaryInExtraToolsTitle', 'ShowGlossaryInExtraToolsComment', NULL, NULL,1,0); - -INSERT INTO settings_options (variable, value, display_text) VALUES ('show_courses_descriptions_in_catalog', 'true', 'Yes'); -INSERT INTO settings_options (variable, value, display_text) VALUES ('show_courses_descriptions_in_catalog', 'false', 'No'); - -INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_coach_to_edit_course_session', 'true', 'Yes'); -INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_coach_to_edit_course_session', 'false', 'No'); - -INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'true', 'Yes'); -INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'false', 'No'); - -CREATE TABLE user_tag (id int NOT NULL auto_increment, tag varchar(255) NOT NULL, field_id int NOT NULL, count int NOT NULL, PRIMARY KEY (id)); +-- This script updates the databases structure before migrating the data from +-- version 1.8.6.1 to version 1.8.6.2 +-- it is intended as a standalone script, however, because of the multiple +-- databases related difficulties, it should be parsed by a PHP script in +-- order to connect to and update the right databases. +-- There is one line per query, allowing the PHP function file() to read +-- all lines separately into an array. The xxMAINxx-type markers are there +-- to tell the PHP script which database we're talking about. +-- By always using the keyword "TABLE" in the queries, we should be able +-- to retrieve and modify the table name from the PHP script if needed, which +-- will allow us to deal with the unique-database-type installations +-- +-- This first part is for the main database +-- xxMAINxx +ALTER TABLE gradebook_evaluation ADD COLUMN type varchar(40) NOT NULL; +ALTER TABLE session ADD COLUMN visibility int NOT NULL default 1; +ALTER TABLE session ADD COLUMN session_category_id INT NOT NULL; + +ALTER TABLE session_rel_course_rel_user ADD COLUMN visibility int NOT NULL default 1; +ALTER TABLE session_rel_course_rel_user ADD COLUMN status int NOT NULL default 0; +CREATE TABLE session_category (id int(11) NOT NULL auto_increment, name varchar(100) default NULL, date_start date default NULL, date_end date default NULL, PRIMARY KEY (id)); + + +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('allow_coach_to_edit_course_session', NULL, 'radio', 'Course', 'false', 'AllowCoachsToEditInsideTrainingSessions', 'AllowCoachsToEditInsideTrainingSessionsComment', NULL, NULL, 0); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable) VALUES ('show_courses_descriptions_in_catalog', NULL, 'radio', 'Course', 'true', 'ShowCoursesDescriptionsInCatalogTitle', 'ShowCoursesDescriptionsInCatalogComment', NULL, NULL, 1, 1); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable) VALUES ('show_glossary_in_extra_tools', NULL, 'radio', 'Course', 'false', 'ShowGlossaryInExtraToolsTitle', 'ShowGlossaryInExtraToolsComment', NULL, NULL,1,0); + +INSERT INTO settings_options (variable, value, display_text) VALUES ('show_courses_descriptions_in_catalog', 'true', 'Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('show_courses_descriptions_in_catalog', 'false', 'No'); + +INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_coach_to_edit_course_session', 'true', 'Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_coach_to_edit_course_session', 'false', 'No'); + +INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'true', 'Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('show_glossary_in_extra_tools', 'false', 'No'); + +CREATE TABLE tag (id int NOT NULL auto_increment, tag varchar(255) NOT NULL, field_id int NOT NULL, count int NOT NULL, PRIMARY KEY (id)); CREATE TABLE user_rel_tag (id int NOT NULL auto_increment,user_id int NOT NULL,tag_id int NOT NULL, PRIMARY KEY (id)); -CREATE TABLE announcement_attachment ( id int NOT NULL auto_increment, path varchar(255) NOT NULL, comment text, size int NOT NULL default 0, announcement_id int NOT NULL, filename varchar(255) NOT NULL, PRIMARY KEY (id) ); - -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('send_email_to_admin_when_create_course',NULL,'radio','Platform','false','SendEmailToAdminTitle','SendEmailToAdminComment',NULL,NULL, 1); -INSERT INTO settings_options (variable, value, display_text) VALUES ('send_email_to_admin_when_create_course','true','Yes'); -INSERT INTO settings_options (variable, value, display_text) VALUES ('send_email_to_admin_when_create_course','false','No'); - -INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('go_to_course_after_login', NULL, 'radio', 'Course', 'false', 'GoToCourseAfterLoginTitle', 'GoToCourseAfterLoginComment', NULL, NULL, 0); -INSERT INTO settings_options (variable, value, display_text) VALUES ('go_to_course_after_login', 'true', 'Yes'); -INSERT INTO settings_options (variable, value, display_text) VALUES ('go_to_course_after_login', 'false', 'No'); - --- xxSTATSxx -ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00'; -ALTER TABLE track_e_online ADD INDEX (course); - --- xxUSERxx - --- xxCOURSExx - -ALTER TABLE quiz ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE blog ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE course_description ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE glossary ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE link ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE wiki ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE tool ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE link_category ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE item_property ADD id_session INT NOT NULL DEFAULT 0; -ALTER TABLE item_property DROP INDEX idx_item_property_toolref, ADD INDEX idx_item_property_toolref (tool, ref, id_session); +CREATE TABLE announcement_attachment ( id int NOT NULL auto_increment, path varchar(255) NOT NULL, comment text, size int NOT NULL default 0, announcement_id int NOT NULL, filename varchar(255) NOT NULL, PRIMARY KEY (id) ); + +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('send_email_to_admin_when_create_course',NULL,'radio','Platform','false','SendEmailToAdminTitle','SendEmailToAdminComment',NULL,NULL, 1); +INSERT INTO settings_options (variable, value, display_text) VALUES ('send_email_to_admin_when_create_course','true','Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('send_email_to_admin_when_create_course','false','No'); + +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('go_to_course_after_login', NULL, 'radio', 'Course', 'false', 'GoToCourseAfterLoginTitle', 'GoToCourseAfterLoginComment', NULL, NULL, 0); +INSERT INTO settings_options (variable, value, display_text) VALUES ('go_to_course_after_login', 'true', 'Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('go_to_course_after_login', 'false', 'No'); + + +-- xxSTATSxx +ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00'; +ALTER TABLE track_e_online ADD INDEX (course); + +-- xxUSERxx + +-- xxCOURSExx + +ALTER TABLE quiz ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE blog ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE course_description ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE glossary ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE link ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE wiki ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE tool ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE link_category ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id); +ALTER TABLE item_property ADD id_session INT NOT NULL DEFAULT 0; +ALTER TABLE item_property DROP INDEX idx_item_property_toolref, ADD INDEX idx_item_property_toolref (tool, ref, id_session); ALTER TABLE quiz ADD COLUMN expired_time int NOT NULL DEFAULT '0' AFTER feedback_type; ALTER TABLE group_info ADD COLUMN chat_state TINYINT DEFAULT 1, ADD INDEX (chat_state); -ALTER TABLE group_category ADD COLUMN chat_state TINYINT DEFAULT 1, ADD INDEX (chat_state); -ALTER TABLE student_publication ADD COLUMN weight float(6,2) UNSIGNED NOT NULL DEFAULT 0; -ALTER TABLE course_description ADD COLUMN description_type TINYINT NOT NULL DEFAULT 0; -ALTER TABLE dropbox_category ADD COLUMN session_id smallint NOT NULL DEFAULT 0, ADD INDEX (session_id); -ALTER TABLE chat_connected ADD COLUMN session_id smallint NOT NULL DEFAULT 0; -ALTER TABLE chat_connected ADD COLUMN to_group_id INT NOT NULL DEFAULT 0; -ALTER TABLE chat_connected DROP PRIMARY KEY; -ALTER TABLE chat_connected ADD INDEX char_connected_index(user_id,session_id,to_group_id); +ALTER TABLE group_category ADD COLUMN chat_state TINYINT DEFAULT 1, ADD INDEX (chat_state); +ALTER TABLE student_publication ADD COLUMN weight float(6,2) UNSIGNED NOT NULL DEFAULT 0; +ALTER TABLE course_description ADD COLUMN description_type TINYINT NOT NULL DEFAULT 0; +ALTER TABLE dropbox_category ADD COLUMN session_id smallint NOT NULL DEFAULT 0, ADD INDEX (session_id); \ No newline at end of file diff --git a/main/messages/inbox.php b/main/messages/inbox.php index d5f13277ea..be3ea1e736 100755 --- a/main/messages/inbox.php +++ b/main/messages/inbox.php @@ -136,35 +136,45 @@ if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) { } } -if ($request===false) { - $interbreadcrumb[]= array ( - 'url' => '#', - 'name' => get_lang('Messages') - ); - $interbreadcrumb[]= array ( - 'url' => 'outbox.php', - 'name' => get_lang('Outbox') - ); - $interbreadcrumb[]= array ( - 'url' => 'inbox.php', - 'name' => get_lang('Inbox') - ); - Display::display_header(''); - $link_ref="new_message.php"; -} else { - $link_ref="../messages/new_message.php?rs=1"; -} + +$link_ref="new_message.php"; + $table_message = Database::get_main_table(TABLE_MESSAGE); -/*echo '
      '; + + //api_display_tool_title(api_xml_http_response_encode(get_lang('Inbox'))); -echo ''; -echo '
    ';*/ -if (!isset($_GET['del_msg'])) { +if ($_GET['f']=='social') { + $this_section = SECTION_SOCIAL; + $interbreadcrumb[]= array ('url' => '#','name' => get_lang('Profile')); + $interbreadcrumb[]= array ('url' => 'outbox.php','name' => get_lang('Inbox')); +} else { + $this_section = SECTION_MYPROFILE; + $interbreadcrumb[]= array ('url' => '#','name' => get_lang('Profile')); + $interbreadcrumb[]= array ('url' => 'outbox.php','name' => get_lang('Inbox')); +} + +Display::display_header(''); + +if ($_GET['f']=='social') { + require_once api_get_path(LIBRARY_PATH).'social.lib.php'; + SocialManager::show_social_menu(); + echo '
    '; + echo get_lang('Messages'); + echo '
    '; +} else { + //comes from normal profile + echo ''; +} + + +if (!isset($_GET['del_msg'])) { inbox_display(); } else { - $num_msg = $_POST['total']; + $num_msg = intval($_POST['total']); for ($i=0;$i<$num_msg;$i++) { if($_POST[$i]) { //the user_id was necesarry to delete a message?? diff --git a/main/messages/index.php b/main/messages/index.php index 55b4055197..aeefea2d56 100755 --- a/main/messages/index.php +++ b/main/messages/index.php @@ -1,27 +1,5 @@ - Copyright (c) Facultad de Matematicas, UADY (México) - Copyright (c) Evie, Free University of Brussels (Belgium) - - For a full list of contributors, see "credits.txt". - The full license can be read in "license.txt". - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - See the GNU General Public License for more details. - - Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium - Mail: info@dokeos.com -============================================================================== -*/ +/* For licensing terms, see /dokeos_license.txt */ $language_file= 'messages'; require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'message.lib.php'; @@ -34,7 +12,7 @@ if (api_get_setting('allow_message_tool')!='true'){ if(api_get_user_id()!=0) { echo ' '; echo ' '; - $number_of_new_messages = get_new_messages(); + $number_of_new_messages = MessageManager::get_new_messages(); if(is_null($number_of_new_messages)) { $number_of_new_messages = 0; } diff --git a/main/messages/message.class.php b/main/messages/message.class.php index 11b06a9761..0dd7b8b5b9 100755 --- a/main/messages/message.class.php +++ b/main/messages/message.class.php @@ -1,26 +1,5 @@ - - For a full list of contributors, see "credits.txt". - The full license can be read in "license.txt". - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - See the GNU General Public License for more details. - - Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium - Mail: info@dokeos.com - -============================================================================== -*/ +/* For licensing terms, see /dokeos_license.txt */ require_once api_get_path(LIBRARY_PATH).'/main_api.lib.php'; require_once api_get_path(LIBRARY_PATH).'/online.inc.php'; diff --git a/main/messages/new_message.php b/main/messages/new_message.php index bf9120e4c4..64313f2a15 100755 --- a/main/messages/new_message.php +++ b/main/messages/new_message.php @@ -213,14 +213,14 @@ if (isset($_GET['rs'])) { 'name' => get_lang('ComposeMessage') ); -if ($request===false) { Display::display_header(''); -} -//api_display_tool_title($nameTools); + echo ''; + echo ''.Display::return_icon('inbox.png',api_xml_http_response_encode(get_lang('Inbox'))).api_xml_http_response_encode(get_lang('Inbox')).''; + echo ''.Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).api_xml_http_response_encode(get_lang('ComposeMessage')).''; + echo ''.Display::return_icon('outbox.png',api_xml_http_response_encode(get_lang('Outbox'))).api_xml_http_response_encode(get_lang('Outbox')).''; +echo '
    '; if (!isset($_POST['compose'])) { if(isset($_GET['re_id'])) { $message_id = $_GET['re_id']; diff --git a/main/messages/notify.php b/main/messages/notify.php index 45b57f6188..adcc7d9bb2 100755 --- a/main/messages/notify.php +++ b/main/messages/notify.php @@ -1,29 +1,7 @@ - Copyright (c) Facultad de Matematicas, UADY (México) - Copyright (c) Evie, Free University of Brussels (Belgium) - - For a full list of contributors, see "credits.txt". - The full license can be read in "license.txt". - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - See the GNU General Public License for more details. - - Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium - Mail: info@dokeos.com -============================================================================== -*/ +/* For licensing terms, see /dokeos_license.txt */ require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'message.lib.php'; header("Cache-Control: no-cache, must-revalidate"); - echo get_new_messages(); + echo MessageManager::get_new_messages(); ?> \ No newline at end of file diff --git a/main/messages/outbox.php b/main/messages/outbox.php index 98e8a5a911..ca4f84d43b 100755 --- a/main/messages/outbox.php +++ b/main/messages/outbox.php @@ -93,6 +93,13 @@ if ($request===false) { ); Display::display_header(''); } + +echo ''; + /**************************************************************/ $info_delete_outbox=array(); $info_delete_outbox=explode(',',$_GET['form_delete_outbox']); @@ -112,9 +119,7 @@ if( trim($info_delete_outbox[0])=='delete' ) { } /**************************************************************/ $table_message = Database::get_main_table(TABLE_MESSAGE); -echo '
      '; -//api_display_tool_title(api_xml_http_response_encode(get_lang('Outbox'))); -echo '
    '; + $user_sender_id=api_get_user_id(); if ($_REQUEST['action']=='delete') { $delete_list_id=array(); diff --git a/main/messages/send_message.php b/main/messages/send_message.php index d0fbd36bba..669a88edbd 100755 --- a/main/messages/send_message.php +++ b/main/messages/send_message.php @@ -71,8 +71,8 @@ if ($panel_id==4) { if ($subject_message=='clear') { $subject_message=null; } - UserFriend::send_invitation_friend_user($user_id,$subject_message,$content_message); + SocialManager::send_invitation_friend_user($user_id,$subject_message,$content_message); } elseif ($panel_id==5) { - UserFriend::send_invitation_friend_user($user_id,$subject_message,$content_message); + SocialManager::send_invitation_friend_user($user_id,$subject_message,$content_message); } ?> diff --git a/main/social/data_personal.inc.php b/main/social/data_personal.inc.php index 5485f1efa5..4038e1ffd9 100755 --- a/main/social/data_personal.inc.php +++ b/main/social/data_personal.inc.php @@ -129,7 +129,7 @@ $language_variable=api_xml_http_response_encode(get_lang('PersonalData')); $number_of_outbox_message=MessageManager::get_number_of_messages_sent(); $cant_out_box=' ('.$number_of_outbox_message.')'; $cant_msg = ' ('.$number_of_new_messages.')'; - $number_of_new_messages_of_friend=UserFriend::get_message_number_invitation_by_user_id(api_get_user_id()); + $number_of_new_messages_of_friend=SocialManager::get_message_number_invitation_by_user_id(api_get_user_id()); //echo ''; echo '

    '.get_lang('Messages').'

    diff --git a/main/social/friends.php b/main/social/friends.php new file mode 100644 index 0000000000..bd91a8dd94 --- /dev/null +++ b/main/social/friends.php @@ -0,0 +1,150 @@ +'; //jQuery +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; + +$interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social')); + +Display :: display_header($tool_name, 'Groups'); +SocialManager::show_social_menu(); + +echo '
    '; +echo get_lang('MyFriends'); +echo '
    '; + + +//$list_path_friends=array(); +$request=api_is_xml_http_request(); +$language_variable=api_xml_http_response_encode(get_lang('Contacts')); +//api_display_tool_title($language_variable); + +$user_id=api_get_user_id(); +$image_path = UserManager::get_user_picture_path_by_id ($user_id,'web',false,true); +?> +
    + + + + + + + + +
    + \ No newline at end of file diff --git a/main/social/group_add.php b/main/social/group_add.php new file mode 100644 index 0000000000..91441bb3c4 --- /dev/null +++ b/main/social/group_add.php @@ -0,0 +1,78 @@ +addElement('text', 'name', get_lang('Name')); +$form->applyFilter('name', 'html_filter'); +$form->applyFilter('name', 'trim'); +$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required'); + +// Description +$form->addElement('text', 'description', get_lang('Description')); +$form->applyFilter('description', 'html_filter'); +$form->applyFilter('description', 'trim'); + + +// url +$form->addElement('text', 'url', get_lang('URL')); +$form->applyFilter('url', 'html_filter'); +$form->applyFilter('url', 'trim'); + +// Picture +$form->addElement('file', 'picture', get_lang('AddPicture')); + +$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); + +$form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); + + +/* + $form->add_textfield('id_text_name', api_xml_http_response_encode(get_lang('SendMessageTo')),true,array('size' => 40,'id'=>'id_text_name','onkeyup'=>'send_request_and_search()','autocomplete'=>'off','style'=>'padding:0px')); + $form->addRule('id_text_name', api_xml_http_response_encode(get_lang('ThisFieldIsRequired')), 'required'); + $form->addElement('html',''); + $form->addElement('hidden','user_list',0,array('id'=>'user_list')); + +$form->add_textfield('title', api_xml_http_response_encode(get_lang('Title'))); +$form->add_html_editor('content', '', false, false, array('ToolbarSet' => 'Messages', 'Width' => '95%', 'Height' => '250')); +if (isset($_GET['re_id'])) { + $form->addElement('hidden','re_id',Security::remove_XSS($_GET['re_id'])); + $form->addElement('hidden','save_form','save_form'); +} + +*/ + +$form->addElement('style_submit_button','add_group', api_xml_http_response_encode(get_lang('AddGroup')),'class="save"'); + +$form->setRequiredNote(api_xml_http_response_encode('* '.get_lang('ThisFieldIsRequired').'')); +$form->setDefaults($default); +if ($form->validate()) { + $values = $form->exportValues(); + var_dump($values); + $receiver_user_id = $values['user_list']; + $title = $values['title']; + $content = $values['content']; + //all is well, send the message + //MessageManager::send_message($receiver_user_id, $title, $content); + //MessageManager::display_success_message($receiver_user_id); +} else { + $form->display(); +} + + + + +?> \ No newline at end of file diff --git a/main/social/group_contact.inc.php b/main/social/group_contact.inc.php index 1a29aca776..40d23e5603 100755 --- a/main/social/group_contact.inc.php +++ b/main/social/group_contact.inc.php @@ -17,10 +17,12 @@ $request=api_is_xml_http_request(); $language_variable=api_xml_http_response_encode(get_lang('ContactsGroups')); //api_display_tool_title($language_variable); $user_id=api_get_user_id(); -$list_groups=UserFriend::show_list_type_friends(); +$list_groups=SocialManager::show_list_type_friends(); + + for ($p=0;$p @@ -65,7 +67,7 @@ for ($p=0;$p' . '' . '
    '. diff --git a/main/social/group_invitation.php b/main/social/group_invitation.php new file mode 100644 index 0000000000..3b59c641c0 --- /dev/null +++ b/main/social/group_invitation.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/main/social/groups.php b/main/social/groups.php new file mode 100644 index 0000000000..7f123fb520 --- /dev/null +++ b/main/social/groups.php @@ -0,0 +1,120 @@ +'home.php','name' => get_lang('Social')); +Display :: display_header($tool_name, 'Groups'); + +//show the action menu +SocialManager::show_social_menu(); +echo '
    '; +echo get_lang('Groups'); +echo '
    '; + +$group_id = intval($_GET['id']); + +if ($group_id != 0 ) { + $group_info = GroupPortalManager::get_group_data($group_id); + $picture = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'],160,'medium_'); + $tags = GroupPortalManager::get_group_tags($group_id,true); + $users = GroupPortalManager::get_users_by_group($group_id,true); + + + //var_dump($users); + + + //Group's title + echo '

    '.$group_info['name'].'

    '; + + //image + echo '
    '; + echo $img = ''; + echo '
    '; + + //description + echo '
    '; + echo $group_info['description']; + echo '
    '; + + //Privacy + echo '
    '; + echo get_lang('Privacy').' : '; + if ($group_info['visibility']== GROUP_PERMISSION_OPEN) { + echo get_lang('ThisIsAnOpenGroup'); + } elseif ($group_info['visibility']== GROUP_PERMISSION_CLOSED) { + echo get_lang('ThisIsACloseGroup'); + } + echo '
    '; + + //group tags + if (!empty($tags)) { + echo '
    '; + echo get_lang('Tags').' : '.$tags; + echo '
    '; + } + + echo '
    '; + echo get_lang('Members').' : '; + foreach($users as $user) { + echo $user['picture_uri'].$user['firstname'].$user['lastname'].'
    '; + } + echo '
    '; + + + echo '
    '; + if (in_array(api_get_user_id(), $users)) { + //im a member + if (isset($users[api_get_user_id()]) && $users[api_get_user_id()]['relation_info']!='') { + $my_group_role = $users[api_get_get_user_id()]['relation_info']; + // just a reader + if ($my_group_role == GROUP_USER_PERMISSION_READER) { + echo 'Im just a reader'; + echo 'Invite others'; + echo 'Leave group'; + //the main admin + } elseif ($my_group_role == GROUP_USER_PERMISSION_ADMIN) { + echo 'Imm the admin'; + echo 'Edit group'; + echo 'Invite others'; + } + } else { + //im not a member + echo 'I should register'; + } + } else { + //im not a member + echo 'I should register'; + } + echo '
    '; + +} else { + echo '

    '.get_lang('Newest').'

    '; + echo '

    '.get_lang('Popular').'

    '; + echo '

    '.get_lang('MyGroups').'

    '; + + $results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0, true); + $groups = array(); + foreach ($results as $result) { + $id = $result['id']; + $url_open = '
    '; + $url_close = ''; + + $groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close); + } + + Display::display_sortable_grid('search_users', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false)); + +} + + + + +Display :: display_footer(); +?> \ No newline at end of file diff --git a/main/social/home.php b/main/social/home.php new file mode 100644 index 0000000000..f046a7d69f --- /dev/null +++ b/main/social/home.php @@ -0,0 +1,611 @@ + +* @package dokeos.social +*/ + +$language_file = array('registration','messages','userInfo','admin','forum','blog'); +$cidReset = true; +require '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'social.lib.php'; +require_once api_get_path(LIBRARY_PATH).'array.lib.php'; +$user_id = api_get_user_id(); +$show_full_profile = true; +//social tab +$this_section = SECTION_SOCIAL; + +//I'm your friend? I can see your profile? +if (isset($_GET['u'])) { + $user_id = (int) Database::escape_string($_GET['u']); + // It's me! + if (api_get_user_id() != $user_id) { + $user_info = UserManager::get_user_info_by_id($user_id); + $show_full_profile = false; + if ($user_info==false) { + // user does no exist !! + api_not_allowed(); + } else { + //checking the relationship between me and my friend + $my_status= SocialManager::get_relation_between_contacts(api_get_user_id(), $user_id); + if (in_array($my_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { + $show_full_profile = true; + } + //checking the relationship between my friend and me + $my_friend_status = SocialManager::get_relation_between_contacts($user_id, api_get_user_id()); + if (in_array($my_friend_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { + $show_full_profile = true; + } else { + // im probably not a good friend + $show_full_profile = false; + } + } + } else { + $user_info = UserManager::get_user_info_by_id($user_id); + } +} else { + $user_info = UserManager::get_user_info_by_id($user_id); +} + +$libpath = api_get_path(LIBRARY_PATH); +require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'; +require_once api_get_path(SYS_CODE_PATH).'announcements/announcements.inc.php'; +require_once $libpath.'course.lib.php'; +require_once $libpath.'formvalidator/FormValidator.class.php'; +require_once $libpath.'magpierss/rss_fetch.inc'; + +api_block_anonymous_users(); + +$htmlHeadXtra[] = ''; //jQuery +$htmlHeadXtra[] = ''; //jQuery corner +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ' +'; +$htmlHeadXtra[] = ''; +if (isset($_GET['shared'])) { + $my_link='../social/index.php'; + $link_shared='shared='.Security::remove_XSS($_GET['shared']); +} else { + $my_link='../auth/profile.php'; + $link_shared=''; +} +$interbreadcrumb[]= array ('url' =>$my_link,'name' => get_lang('ModifyProfile') ); +$interbreadcrumb[]= array ( + 'url' => '../social/profile.php?'.$link_shared.'#remote-tab-1', + 'name' => get_lang('ViewMySharedProfile') +); + +if (isset($_GET['u']) && is_numeric($_GET['u'])) { + $info_user=api_get_user_info($_GET['u']); + $interbreadcrumb[]= array ( + 'url' => 'javascript: void(0);', + 'name' => api_get_person_name($info_user['firstName'], $info_user['lastName']) + ); +} +if (isset($_GET['u'])) { + $param_user='u='.Security::remove_XSS($_GET['u']); +}else { + $info_user=api_get_user_info(api_get_user_id()); + $param_user=''; +} +$_SESSION['social_user_id'] = $user_id; + + +/** + * Display + */ +Display :: display_header(null); + +// @todo here we must show the user information as read only +//User picture size is calculated from SYSTEM path + +$img_array= UserManager::get_user_picture_path_by_id($user_id,'web',true,true); + +//print_r($user_info); +// Added by Ivan Tcholakov, 03-APR-2009. +if (USE_JQUERY_CORNERS_SCRIPT) { +echo $s=""; +} + + +//echo ''; + +//Setting some course info +$my_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); +$personal_course_list = UserManager::get_personal_session_course_list($my_user_id); +$course_list_code = array(); +$i=1; +//print_r($personal_course_list); + + + +if (is_array($personal_course_list)) { + foreach ($personal_course_list as $my_course) { + if ($i<=10) { + $list[] = SocialManager::get_logged_user_course_html($my_course,$i); + //$course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db'], 'title'=>$my_course['i']); cause double + $course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db']); + + } else { + break; + } + $i++; + } + //to avoid repeted courses + $course_list_code = array_unique_dimensional($course_list_code); +} + + +echo ''; + + +echo '
    '; +if ($user_id == api_get_user_id()) + echo get_lang('ViewMySharedProfile'); +else + echo get_lang('ViewSharedProfile').' - '.api_get_person_name($user_info['firstname'], $user_info['lastname']); + +echo '
    '; + +echo '
    '; +// RIGHT COLUMN + echo '
    '; + //---- FRIENDS + + if ($show_full_profile) { + $list_path_friends= $list_path_normal_friends = $list_path_parents = array(); + + $list_path_good_friends = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALGOODFRIEND); + $list_path_normal_friends = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALFRIEND); + $list_path_parents = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALPARENT); + + $list_path_friends = array_merge_recursive($list_path_good_friends, $list_path_normal_friends, $list_path_parents); + + $friend_html=''; + $number_of_images=3; + $number_friends=0; + $list_friends_id=array(); + $list_friends_dir=array(); + $list_friends_file=array(); + + if (count($list_path_friends)!=0) { + $friends_count = count($list_path_friends['id_friend']); + + for ($z=0;$z< $friends_count ;$z++) { + $list_friends_id[] = $list_path_friends['id_friend'][$z]['friend_user_id']; + $list_friends_dir[] = $list_path_friends['path_friend'][$z]['dir']; + $list_friends_file[]= $list_path_friends['path_friend'][$z]['file']; + } + $number_friends= count($list_friends_dir); + $number_loop = ($number_friends/$number_of_images); + $loop_friends = ceil($number_loop); + $j=0; + $friend_html .= '
    '.get_lang('SocialFriend').'
    '; + $friend_html.= ''; // end of content section + + +echo '
    '; + // LEFT COLUMN + echo '
    '; + + //--- User image + echo ''; + + // Send message or Add to friend links + /*if (!$show_full_profile) { + echo '  '.Display::return_icon('message_new.png').'  '.get_lang('SendMessage').'
    '; + }*/ + + // Extra information + + if ($show_full_profile) { + //-- Extra Data + $t_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD); + $t_ufo = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS); + $extra_user_data = UserManager::get_extra_user_data($user_id); + $extra_information = ''; + if (is_array($extra_user_data) && count($extra_user_data)>0 ) { + $extra_information = '
    '; + $extra_information .= get_lang('ExtraInformation'); + $extra_information .= '

    '; + $extra_information .=''; + $extra_information .= '

    '; + } + // if there are information to show + if (!empty($extra_information_value)) + echo $extra_information; + + + // ---- My Agenda Items + $my_agenda_items = show_simple_personal_agenda($user_id); + if (!empty($my_agenda_items)) { + echo '
    '; + echo get_lang('MyAgenda'); + echo '
    '; + $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); + echo ''; + } + + //-----Announcements + $announcement_content = ''; + $my_announcement_by_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); + + foreach ($course_list_code as $course) { + $content = get_all_annoucement_by_user_course($course['dbName'],$my_announcement_by_user_id); + $course_info=api_get_course_info($course['code']); + if (!empty($content)) { + $announcement_content.= ''; + $announcement_content.= '
    '; + } + + } + + if(!empty($announcement_content)) { + echo '
    '; + echo get_lang('Announcements'); + echo '

    '; + echo ''; + } + } + echo '
    '; + + + // CENTER COLUMN + + + echo '
    '; + + //--- Basic Information + + echo 'ssss'; + echo '
    '; + echo '
    '; +echo '
    '; //from the main +echo '
     '; +Display :: display_footer(); \ No newline at end of file diff --git a/main/social/index.php b/main/social/index.php index a25c49d5e0..ad2c91a1e7 100755 --- a/main/social/index.php +++ b/main/social/index.php @@ -5,6 +5,8 @@ $cidReset = true; $language_file = array('registration','messages','userInfo','admin'); require '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; + $this_section = SECTION_MYPROFILE; $_SESSION['this_section']=$this_section; api_block_anonymous_users(); @@ -15,391 +17,7 @@ $htmlHeadXtra[] = ''; //$htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; if (api_get_setting('allow_message_tool')=='true') { $htmlHeadXtra[] ='"; -// } -// - -//echo ''; //Setting some course info $my_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); @@ -470,12 +240,10 @@ $course_list_code = array(); $i=1; //print_r($personal_course_list); - - if (is_array($personal_course_list)) { foreach ($personal_course_list as $my_course) { if ($i<=10) { - $list[] = get_logged_user_course_html($my_course,$i); + $list[] = SocialManager::get_logged_user_course_html($my_course,$i); //$course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db'], 'title'=>$my_course['i']); cause double $course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db']); @@ -488,14 +256,18 @@ if (is_array($personal_course_list)) { $course_list_code = array_unique_dimensional($course_list_code); } +//show the action menu +SocialManager::show_social_menu(); + echo '
    '; if ($user_id == api_get_user_id()) echo get_lang('ViewMySharedProfile'); else echo get_lang('ViewSharedProfile').' - '.api_get_person_name($user_info['firstname'], $user_info['lastname']); - echo '
    '; + + echo '
    '; // RIGHT COLUMN echo '
    '; @@ -504,9 +276,9 @@ echo '
    '; if ($show_full_profile) { $list_path_friends= $list_path_normal_friends = $list_path_parents = array(); - $list_path_good_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALGOODFRIEND); - $list_path_normal_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALFRIEND); - $list_path_parents = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALPARENT); + $list_path_good_friends = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALGOODFRIEND); + $list_path_normal_friends = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALFRIEND); + $list_path_parents = SocialManager::get_list_path_web_by_user_id($user_id, SOCIALPARENT); $list_path_friends = array_merge_recursive($list_path_good_friends, $list_path_normal_friends, $list_path_parents); @@ -538,7 +310,7 @@ echo '
    '; else $friend_html.= '
    '.$friends_count.' '.get_lang('Friends').'
    '; if (api_get_user_id() == $user_id) - $friend_html.= ''; + $friend_html.= ''; $friend_html.= '
    '; // close div friend-header for ($k=0;$k<$loop_friends;$k++) { @@ -551,7 +323,7 @@ echo '
    '; $name_user=api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']); $friend_html.='
    '; // the height = 92 must be the sqme in the image_friend_network span style in default.css - $friends_profile = UserFriend::get_picture_user($list_friends_id[$j], $list_friends_file[$j], 92, 'medium_', 'width="85" height="90" '); + $friends_profile = SocialManager::get_picture_user($list_friends_id[$j], $list_friends_file[$j], 92, 'medium_', 'width="85" height="90" '); $friend_html.=''; $friend_html.=''; $friend_html.= '
    '; @@ -573,8 +345,8 @@ echo '
    '; echo $friend_html; //Pending invitations if (!isset($_GET['u']) || (isset($_GET['u']) && $_GET['u']==api_get_user_id())) { - $pending_invitations = UserFriend::get_list_invitation_of_friends_by_user_id(api_get_user_id()); - $list_get_path_web=UserFriend::get_list_web_path_user_invitation_by_user_id(api_get_user_id()); + $pending_invitations = SocialManager::get_list_invitation_of_friends_by_user_id(api_get_user_id()); + $list_get_path_web=SocialManager::get_list_web_path_user_invitation_by_user_id(api_get_user_id()); $count_pending_invitations = count($pending_invitations); //echo '

    '; //javascript:register_friend(this) @@ -694,10 +466,10 @@ echo '
    '; echo '

    '; echo '
    '; echo '
    '; - echo '
    '; - echo '
    '; + + if (api_get_user_id() == $user_id) { - // if i'm me + /* // if i'm me echo '
    '; echo Display::return_icon('email.gif'); echo ' '.get_lang('MyInbox').' '; @@ -705,12 +477,13 @@ echo '
    '; echo '
    '; echo Display::return_icon('edit.gif'); echo ' '.get_lang('EditInformation').' '; - echo '
    '; + echo '
    ';*/ } else { + echo '
    '; + echo ''; + echo '
    '; + } echo '
    '; // Send message or Add to friend links @@ -761,8 +534,9 @@ echo '
    '; $user_tags = UserManager::get_user_tags($user_id, $field_id); $tag_tmp = array(); foreach ($user_tags as $tags) { - $tag_tmp[] = $tags['tag']; - } + //$tag_tmp[] = $tags['tag']; + $tag_tmp[] = ''.$tags['tag'].''; + } if (is_array($user_tags) && count($user_tags)>0) { $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(', ',$tag_tmp).'
    '; } @@ -927,7 +701,7 @@ echo '
    '; */ } echo '
    '; - echo get_user_feeds($user_id); + echo SocialManager::get_user_feeds($user_id); echo '
    '; } echo '
    '; diff --git a/main/social/qualify_contact.inc.php b/main/social/qualify_contact.inc.php index 78fdd734e0..318feb902e 100755 --- a/main/social/qualify_contact.inc.php +++ b/main/social/qualify_contact.inc.php @@ -9,13 +9,13 @@ $user_friend=(int)$_POST['user_friend']; $list_of_options=array(); $img_user=array(); $img_info_user=array(); -$list_of_options=UserFriend::show_list_type_friends(); +$list_of_options=SocialManager::show_list_type_friends(); $path_user=str_replace(array('\\','../','\\0'),array('','',''),$_GET['path_user']); $img_user =explode('"',$path_user); $number_list=count($list_of_options); $user_friend = $user_id = (int)str_replace(array('\\','"'),array('',''),$_GET['id_user']); $user_info=api_get_user_info($user_friend); -$user_friend_relation=UserFriend::get_relation_between_contacts(api_get_user_id(),$user_friend); +$user_friend_relation=SocialManager::get_relation_between_contacts(api_get_user_id(),$user_friend); ?>
    diff --git a/main/social/register_friend.php b/main/social/register_friend.php index 3e7dbbaca7..94accdf016 100755 --- a/main/social/register_friend.php +++ b/main/social/register_friend.php @@ -23,9 +23,9 @@ if (isset($_POST['is_my_friend'])) { } if (isset($_POST['friend_id'])) { - UserFriend::register_friend ((int)$the_current_user_id,(int)$my_current_friend,(int)$relation_type); - UserFriend::register_friend ((int)$my_current_friend,(int)$the_current_user_id,(int)$relation_type); - UserFriend::invitation_accepted ((int)$my_current_friend,(int)$the_current_user_id); + SocialManager::register_friend ((int)$the_current_user_id,(int)$my_current_friend,(int)$relation_type); + SocialManager::register_friend ((int)$my_current_friend,(int)$the_current_user_id,(int)$relation_type); + SocialManager::invitation_accepted ((int)$my_current_friend,(int)$the_current_user_id); if (isset($_POST['is_my_friend'])) { echo api_xml_http_response_encode(get_lang('AddedContactToList')); } else { @@ -34,14 +34,14 @@ if (isset($_POST['friend_id'])) { } if (isset($_POST['denied_friend_id'])) { - UserFriend::invitation_denied((int)$my_denied_current_friend,(int)$the_current_user_id); + SocialManager::invitation_denied((int)$my_denied_current_friend,(int)$the_current_user_id); Display::display_confirmation_message(api_xml_http_response_encode(get_lang('InvitationDenied'))); } if (isset($_POST['delete_friend_id'])) { - UserFriend::removed_friend((int)$my_delete_friend); + SocialManager::removed_friend((int)$my_delete_friend); } if(isset($_POST['user_id_friend_q']) && isset($_POST['type_friend_q'])) { - UserFriend::qualify_friend((int)$friend_id_qualify,(int)$type_friend_qualify); + SocialManager::qualify_friend((int)$friend_id_qualify,(int)$type_friend_qualify); echo api_xml_http_response_encode(get_lang('AttachContactsToGroupSuccesfuly')); } ?> \ No newline at end of file diff --git a/main/social/search.php b/main/social/search.php index ade015737f..32446d417c 100644 --- a/main/social/search.php +++ b/main/social/search.php @@ -2,284 +2,66 @@ /* For licensing terms, see /dokeos_license.txt */ // name of the language file that needs to be included -$language_file = array ('registration','admin'); - +$language_file = array('registration','admin'); require_once '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'social.lib.php'; +require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php'; -require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php'); -require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); -require_once (api_get_path(LIBRARY_PATH).'security.lib.php'); -require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); +$this_section = SECTION_SOCIAL; +$tool_name = get_lang('Search'); +$interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social')); -$tool_name = get_lang('SearchAUser'); Display :: display_header($tool_name); - - -// Build search-form -$form = new FormValidator('search_user', 'get', '', '', null, false); -$renderer = & $form->defaultRenderer(); -$renderer->setElementTemplate('{element} '); -$form->add_textfield('keyword', '', false); -$form->addElement('style_submit_button', 'submit', get_lang('SearchButton'), 'class="search"'); -$form->addElement('static', 'additionalactions', null, $actions); -$form->display(); - - -if (isset ($_GET['keyword'])) { - if (isset ($_GET['keyword'])) { - $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword'])); - } - // Create a sortable table with user-data - $parameters['sec_token'] = Security::get_token(); +//show the action menu +SocialManager::show_social_menu(); +echo '
    '; +echo get_lang('Search'); +echo '
    '; + +$query = $_GET['q']; +echo UserManager::get_search_form($query); - $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2); - $table->set_additional_parameters($parameters); - $table->set_header(0, '', false); - $table->set_header(1, get_lang('OfficialCode')); - if (api_is_western_name_order()) { - $table->set_header(2, get_lang('FirstName')); - $table->set_header(3, get_lang('LastName')); - } else { - $table->set_header(2, get_lang('LastName')); - $table->set_header(3, get_lang('FirstName')); - } - $table->set_header(4, get_lang('LoginName')); - $table->set_header(5, get_lang('Email')); - - //tag - $table_tag = new SortableTable('tags', 'get_number_of_user_tags', 'get_user_tag_data'); - $table_tag->set_additional_parameters($parameters); - $table_tag->set_header(0, '', false); - $table->set_header(1, get_lang('OfficialCode')); - if (api_is_western_name_order()) { - $table_tag->set_header(2, get_lang('FirstName')); - $table_tag->set_header(3, get_lang('LastName')); - } else { - $table_tag->set_header(2, get_lang('LastName')); - $table_tag->set_header(3, get_lang('FirstName')); - } - /* - //groups - $table_tag = new SortableTable('groups', 'get_number_of_user_tags', 'get_user_tag_data'); - $table_tag->set_additional_parameters($parameters); - $table_tag->set_header(0, '', false); - $table->set_header(1, get_lang('OfficialCode')); - if (api_is_western_name_order()) { - $table_tag->set_header(2, get_lang('FirstName')); - $table_tag->set_header(3, get_lang('LastName')); - } else { - $table_tag->set_header(2, get_lang('LastName')); - $table_tag->set_header(3, get_lang('FirstName')); - } -*/ - echo get_lang('Users'); - $table->display_grid(); - - echo get_lang('Tags'); - $table_tag->display_grid(); - /* - echo get_lang('Groups'); - $table_group->display_grid(); - */ -} - -/** - * Get the users to display on the current page (fill the sortable-table) - * @param int offset of first user to recover - * @param int Number of users to get - * @param int Column to sort on - * @param string Order (ASC,DESC) - * @see SortableTable#get_table_data($from) - */ -function get_user_tag_data($from, $number_of_items, $column, $direction) -{ - if (isset ($_GET['keyword'])) { - $keyword = Database::escape_string($_GET['keyword']); - } - $user_tags = UserManager::get_all_user_tags($keyword,'5',$from, $number_of_items); - return $user_tags; -} - - - -/** - * Get the total number of users on the platform - * @see SortableTable#get_total_number_of_items() - */ -function get_number_of_user_tags() -{ - $tag_table = Database :: get_main_table(TABLE_MAIN_USER_TAG); - $sql = "SELECT COUNT(tag) AS total_number_of_items FROM $tag_table u"; - if (isset ($_GET['keyword'])) { - $keyword = Database::escape_string($_GET['keyword']); - $sql .= " WHERE (tag LIKE '%".$keyword."%' )"; - } - $res = Database::query($sql, __FILE__, __LINE__); - $obj = Database::fetch_object($res); - return $obj->total_number_of_items; -} - - -/** - * Get the users to display on the current page (fill the sortable-table) - * @param int offset of first user to recover - * @param int Number of users to get - * @param int Column to sort on - * @param string Order (ASC,DESC) - * @see SortableTable#get_table_data($from) - */ -function get_user_data($from, $number_of_items, $column, $direction) -{ - $user_table = Database :: get_main_table(TABLE_MAIN_USER); - $sql = "SELECT - u.user_id AS col0, - u.official_code AS col1, - ".(api_is_western_name_order() - ? "u.firstname AS col2, - u.lastname AS col3," - : "u.lastname AS col2, - u.firstname AS col3,")." - u.username AS col4, - u.email AS col5 - FROM $user_table u "; - - // adding the filter to see the user's only of the current access_url - global $_configuration; - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { - $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; - } - - if (isset ($_GET['keyword'])) { - $keyword = Database::escape_string($_GET['keyword']); - $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' )"; - } elseif (isset ($_GET['keyword_firstname'])) { - $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); - $keyword_firstname = Database::escape_string($_GET['keyword_firstname']); - $keyword_lastname = Database::escape_string($_GET['keyword_lastname']); - $keyword_email = Database::escape_string($_GET['keyword_email']); - $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']); - $keyword_username = Database::escape_string($_GET['keyword_username']); - $keyword_status = Database::escape_string($_GET['keyword_status']); - $query_admin_table = ''; - $keyword_admin = ''; - - if ($keyword_status == SESSIONADMIN) { - $keyword_status = '%'; - $query_admin_table = " , $admin_table a "; - $keyword_admin = ' AND a.user_id = u.user_id '; +//I'm searching something +if ($query != '') { + if (isset($query) && $query!='') { + //get users from tags + $users = UserManager::get_all_user_tags($query, 0, 0, 5); + + $results = array(); + if (is_array($users)) { + echo '

    '.get_lang('Users').'

    '; + + foreach($users as $user) { + $picture = UserManager::get_picture_user($user['user_id'], $user['picture_uri'],80); + $url_open = ''; + $url_close =''; + $img = $url_open.''.$url_close; + $user['firstname'] = $url_open.$user['firstname'].$url_close; + + $results[] = array($img, $user['firstname'],$user['lastname'],$user['tag']); + } } - $keyword_active = isset($_GET['keyword_active']); - $keyword_inactive = isset($_GET['keyword_inactive']); - $sql .= $query_admin_table." WHERE (u.firstname LIKE '%".$keyword_firstname."%' " . - "AND u.lastname LIKE '%".$keyword_lastname."%' " . - "AND u.username LIKE '%".$keyword_username."%' " . - "AND u.email LIKE '%".$keyword_email."%' " . - "AND u.official_code LIKE '%".$keyword_officialcode."%' " . - "AND u.status LIKE '".$keyword_status."'" . - $keyword_admin; - - if ($keyword_active && !$keyword_inactive) { - $sql .= " AND u.active='1'"; - } elseif($keyword_inactive && !$keyword_active) { - $sql .= " AND u.active='0'"; - } - $sql .= " ) "; - } - - // adding the filter to see the user's only of the current access_url - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { - $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); - } - - if (!in_array($direction, array('ASC','DESC'))) { - $direction = 'ASC'; - } - $column = intval($column); - $from = intval($from); - $number_of_items = intval($number_of_items); - - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - $res = Database::query($sql, __FILE__, __LINE__); - - $users = array (); - $t = time(); - while ($user = Database::fetch_row($res)) { - if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') { - // check expiration date - $expiration_time = convert_mysql_date($user[9]); - // if expiration date is passed, store a special value for active field - if ($expiration_time < $t) { - $user[7] = '-1'; - } - } - // forget about the expiration date field - $users[] = array($user[0],$user[1],$user[2],$user[3],$user[4],$user[5]); - } - return $users; + Display::display_sortable_grid('search_users', array(), $results, array('hide_navigation'=>true, 'per_page' => 5), $query_vars, false ,true); + + //get users from tags + $groups = GroupPortalManager::get_all_group_tags($query); + $results = array(); + if (is_array($groups) && count($groups)>0) { + echo '

    '.get_lang('Groups').'

    '; + foreach($groups as $group) { + $picture = GroupPortalManager::get_picture_group($group['id'], $group['picture_uri'],80); + $img = ''; + $tags = GroupPortalManager::get_group_tags($group['id']); + $group['name'] = ''.$group['name'].''; + $img = ''.$img.''; + $results[] = array($img, $group['name'],$group['description'],$tags); + } + } + Display::display_sortable_grid('search_users', array(), $results, array('hide_navigation'=>true, 'per_page' => 5), $query_vars, false, array(true,true,true,true,true)); + } +} else { + //we should show something } - - - -/** - * Get the total number of users on the platform - * @see SortableTable#get_total_number_of_items() - */ -function get_number_of_users() -{ - $user_table = Database :: get_main_table(TABLE_MAIN_USER); - $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u"; - - // adding the filter to see the user's only of the current access_url - global $_configuration; - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { - $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)"; - } - - if ( isset ($_GET['keyword'])) { - $keyword = Database::escape_string($_GET['keyword']); - $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%') "; - } elseif (isset ($_GET['keyword_firstname'])) { - $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN); - $keyword_firstname = Database::escape_string($_GET['keyword_firstname']); - $keyword_lastname = Database::escape_string($_GET['keyword_lastname']); - $keyword_email = Database::escape_string($_GET['keyword_email']); - $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']); - $keyword_username = Database::escape_string($_GET['keyword_username']); - $keyword_status = Database::escape_string($_GET['keyword_status']); - $query_admin_table = ''; - $keyword_admin = ''; - if ($keyword_status == SESSIONADMIN) { - $keyword_status = '%'; - $query_admin_table = " , $admin_table a "; - $keyword_admin = ' AND a.user_id = u.user_id '; - } - $keyword_active = isset($_GET['keyword_active']); - $keyword_inactive = isset($_GET['keyword_inactive']); - $sql .= $query_admin_table . - " WHERE (u.firstname LIKE '%".$keyword_firstname."%' " . - "AND u.lastname LIKE '%".$keyword_lastname."%' " . - "AND u.username LIKE '%".$keyword_username."%' " . - "AND u.email LIKE '%".$keyword_email."%' " . - "AND u.official_code LIKE '%".$keyword_officialcode."%' " . - "AND u.status LIKE '".$keyword_status."'" . - $keyword_admin; - if($keyword_active && !$keyword_inactive) { - $sql .= " AND u.active='1'"; - } elseif($keyword_inactive && !$keyword_active) { - $sql .= " AND u.active='0'"; - } - $sql .= " ) "; - } - - // adding the filter to see the user's only of the current access_url - if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) { - $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id(); - } - - $res = Database::query($sql, __FILE__, __LINE__); - $obj = Database::fetch_object($res); - return $obj->total_number_of_items; -} \ No newline at end of file +Display :: display_footer(); +?> \ No newline at end of file diff --git a/main/social/select_friend_response.php b/main/social/select_friend_response.php index 88167f9938..110e061eff 100755 --- a/main/social/select_friend_response.php +++ b/main/social/select_friend_response.php @@ -19,8 +19,8 @@ $language_comment=api_xml_http_response_encode(get_lang('SocialInvitesComment')) $list_get_invitation=array(); $list_get_path_web=array(); $user_id=api_get_user_id(); -$list_get_invitation=UserFriend::get_list_invitation_of_friends_by_user_id($user_id); -$list_get_path_web=UserFriend::get_list_web_path_user_invitation_by_user_id($user_id); +$list_get_invitation=SocialManager::get_list_invitation_of_friends_by_user_id($user_id); +$list_get_path_web=SocialManager::get_list_web_path_user_invitation_by_user_id($user_id); $number_loop=count($list_get_invitation); if ($number_loop==0) { Display::display_normal_message(api_xml_http_response_encode(get_lang('YouDontHaveInvites'))); @@ -47,7 +47,7 @@ cellpadding="0" cellspacing="0" bgcolor="#9DACBF"> diff --git a/main/social/show_search_image.inc.php b/main/social/show_search_image.inc.php index cd72bf72ce..02a46e47b6 100755 --- a/main/social/show_search_image.inc.php +++ b/main/social/show_search_image.inc.php @@ -34,9 +34,9 @@ $list_path_friends=array(); $user_id=api_get_user_id(); $name_search=Security::remove_XSS($_POST['search_name_q']); if (isset($name_search) && $name_search!='undefined') { - $list_path_friends=UserFriend::get_list_path_web_by_user_id($user_id,null,$name_search); + $list_path_friends=SocialManager::get_list_path_web_by_user_id($user_id,null,$name_search); } else { - $list_path_friends=UserFriend::get_list_path_web_by_user_id($user_id); + $list_path_friends=SocialManager::get_list_path_web_by_user_id($user_id); } $friend_html=''; $number_of_images=8; @@ -64,7 +64,7 @@ if (count($list_path_friends)!=0) { if ($list_friends_file[$j]<>"") { $user_info=api_get_user_info($list_friends_id[$j]); $user_name=api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); - $friends_profile = UserFriend::get_picture_user($list_friends_id[$j], $list_friends_file[$j], 92); + $friends_profile = SocialManager::get_picture_user($list_friends_id[$j], $list_friends_file[$j], 92); $friend_html.='
    '.$user_name.'
    '; diff --git a/whoisonline.php b/whoisonline.php index af6f6152f1..42ea359693 100644 --- a/whoisonline.php +++ b/whoisonline.php @@ -19,7 +19,8 @@ require_once './main/inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; require_once api_get_path(LIBRARY_PATH).'social.lib.php'; - +//social tab +$this_section = SECTION_SOCIAL; // table definitions $track_user_table = Database::get_main_table(TABLE_MAIN_USER); @@ -130,10 +131,14 @@ function display_user_list($user_list, $_plugins) { $uid = $user[0]; $user_info = api_get_user_info($uid); $table_row = array(); - $url = '?id='.$uid.$course_url; + if (api_get_setting('allow_social_tool')=='true') { + $url = '/main/social/profile.php?u='.$uid.$course_url; + } else { + $url = '?id='.$uid.$course_url; + } $image_array = UserManager::get_user_picture_path_by_id($uid, 'system', false, true); - $friends_profile = UserFriend::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" '); + $friends_profile = SocialManager::get_picture_user($uid, $image_array['file'], 92, 'medium_', ' width="90" height="90" '); // reduce image $name = api_get_person_name($user_info['firstName'], $user_info['lastName']); $table_row[] = ''.$name.''; @@ -247,7 +252,7 @@ function display_individual_user($user_id) { $user_anonymous = api_get_anonymous_id(); if ($safe_user_id != api_get_user_id() && !api_is_anonymous($safe_user_id)) { - $user_relation = UserFriend::get_relation_between_contacts(api_get_user_id(), $safe_user_id); + $user_relation = SocialManager::get_relation_between_contacts(api_get_user_id(), $safe_user_id); if ($user_relation == 0 || $user_relation == 6) { echo ''.Display :: return_icon('add_multiple_users.gif', get_lang('SocialInvitationToFriends')).' '.get_lang('SendInvitation').'
    '.Display :: return_icon('mail_send.png', get_lang('SendAMessage')).' '.get_lang('SendAMessage').''; @@ -366,6 +371,7 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || if ($user_list) { if (!isset($_GET['id'])) { + echo UserManager::get_search_form($_GET['q']); display_user_list($user_list, $_plugins); } else { //individual user information - also displays header info
    - +
    />