'; print_r($fvalue);
if (is_array($fvalue)) {
foreach($fvalue as $val) {
$fvalues .= Database::escape_string($val).';';
@@ -910,6 +912,11 @@ class UserManager
// Check if enumerated field, if the option is available
$rowuf = Database::fetch_array($resuf);
switch ($rowuf['field_type']) {
+ case 10 :
+ //Tags are process here
+ UserManager::process_tags(explode(';', $fvalues), $user_id, $rowuf['id']);
+ return true;
+ break;
case 3:
case 4:
case 5:
@@ -932,7 +939,7 @@ class UserManager
}
break;
case 1:
- case 2:
+ case 2:
default:
break;
}
@@ -1433,6 +1440,19 @@ class UserManager
}
return $return;
}
+
+ public static function get_all_extra_field_by_type($field_type) {
+ // database table definition
+ $table_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
+
+ // all the information of the field
+ $sql = "SELECT * FROM $table_field WHERE field_type='".Database::escape_string($field_type)."'";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ while ($row = Database::fetch_array($result)) {
+ $return[] = $row['id'];
+ }
+ return $return;
+ }
/**
* Get all the extra field information of a certain field (also the options)
@@ -1460,7 +1480,7 @@ class UserManager
}
return $return;
}
-
+
/** Get extra user data by value
* @param string the internal variable name of the field
* @param string the internal value of the field
@@ -2223,4 +2243,274 @@ class UserManager
$rs = Database::query($sql_insert_outbox, __FILE__, __LINE__);
}
}
+
+ /*
+ *
+ * USER TAGS
+ *
+ * Intructions to create a new user tag
+ *
+ * 1. Create a new extra field in main/admin/user_fields.php with the "TAG" field type make it available and visible. Called it "books" for example.
+ * 2. Go to profile main/auth/profile.php There you will see a special input (facebook style) that will show suggestions of tags.
+ * 3. Step 2 will not work since this special input needs a file called "main/user/books.php" In this case. In order to have this file copy and paste from this file main/user/tag.php
+ * 4. All the tags are registered in the user_tag table and the relationship between user and tags is in the user_rel_tag table
+ * 5. Test and enjoy.
+ *
+ */
+
+ /**
+ * Gets the tags of a specific field_id
+ *
+ * @param int field_id
+ * @param string how we are going to result value in array or in a string (json)
+ * @return mixed
+ */
+ 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_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
+ $field_id = intval($field_id); //like '%$tag%'
+ $limit = intval($limit);
+ $tag = Database::escape_string($tag);
+ // all the information of the field
+ $sql = "SELECT id, tag from $table_user_tag
+ WHERE field_id = $field_id AND tag LIKE '$tag%' ORDER BY tag LIMIT $limit";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $return = array();
+ if (Database::num_rows($result)>0) {
+ while ($row = Database::fetch_array($result,'ASSOC')) {
+ $return[] = array('caption'=>$row['tag'], 'value'=>$row['tag']);
+ }
+ }
+ if ($return_format=='json') {
+ $return = json_encode($return);
+ }
+ return $return;
+ }
+
+ 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_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
+ $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";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $return = array();
+ if (Database::num_rows($result)>0) {
+ while ($row = Database::fetch_array($result,'ASSOC')) {
+ $return[] = $row;
+ }
+ }
+ return $return;
+ }
+
+ /**
+ * Get user's tags
+ * @param int field_id
+ * @param int user_id
+ * @return array
+ */
+ 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_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
+ $field_id = intval($field_id);
+ $user_id = intval($user_id);
+
+ // all the information of the field
+ $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['id']] = array($row['tag'],$row['count']);
+ }
+ }
+ return $return;
+ }
+
+ /**
+ * Searchs user with a specific tag
+ * @param string the tag
+ * @param int field id of the tag
+ * @return array
+ */
+ public static function get_all_user_tags($tag, $field_id, $from, $number_of_items) {
+ // database table definition
+ $table_user_tag = Database::get_main_table(TABLE_MAIN_USER_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);
+
+ // 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";
+ $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 $return;
+ }
+
+
+ /**
+ * Get the tag id
+ * @param int $tag
+ * @param int $field_id
+ * @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);
+ $tag = Database::escape_string($tag);
+ $field_id = intval($field_id);
+ //with COLLATE latin1_bin to select query in a case sensitive mode
+ $sql = "SELECT id FROM $table_user_tag WHERE tag COLLATE latin1_bin LIKE '$tag' AND field_id = $field_id";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ if (Database::num_rows($result)>0) {
+ $row = Database::fetch_array($result,'ASSOC');
+ return $row['id'];
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Get the tag id
+ * @param int $tag
+ * @param int $field_id
+ * @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);
+ $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";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ if (Database::num_rows($result)>0) {
+ $row = Database::fetch_array($result,'ASSOC');
+ return $row['id'];
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
+ * Adds a user-tag value
+ * @param mixed $tag
+ * @param int $user_id
+ * @param int $field_id
+ * @return bool
+ */
+ 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_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
+ $tag = Database::escape_string($tag);
+ $user_id = intval($user_id);
+ $field_id = intval($field_id);
+
+ //&& (substr($tag,strlen($tag)-1) == '@')
+ /*$sent_by_user = false;
+ if ( substr($tag,0,1) == '@') {
+ //is a value sent by the list
+ $sent_by_user = true;
+ $tag = substr($tag,1,strlen($tag)-2);
+ }
+ */
+ $tag_id = UserManager::get_tag_id($tag,$field_id);
+ //@todo we don't create tags with numbers
+ if (is_numeric($tag)) {
+ //the form is sending an id this means that the user select it from the list so it MUST exists
+ /*$new_tag_id = UserManager::get_tag_id_from_id($tag,$field_id);
+ if ($new_tag_id !== false) {
+ $sql = "UPDATE $table_user_tag SET count = count + 1 WHERE id = $new_tag_id";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $last_insert_id = $new_tag_id;
+ } else {
+ $sql = "INSERT INTO $table_user_tag (tag, field_id,count) VALUES ('$tag','$field_id', count + 1)";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $last_insert_id = Database::get_last_insert_id();
+ }*/
+ } else {
+ //this is a new tag
+ if ($tag_id == 0) {
+ //the tag doesn't exist
+ $sql = "INSERT INTO $table_user_tag (tag, field_id,count) VALUES ('$tag','$field_id', count + 1)";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $last_insert_id = Database::get_last_insert_id();
+ } else {
+ //the tag exists we update it
+ $sql = "UPDATE $table_user_tag SET count = count + 1 WHERE id = $tag_id";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ $last_insert_id = $tag_id;
+ }
+ }
+
+ if (!empty($last_insert_id) && ($last_insert_id!=0)) {
+ //we insert the relationship user-tag
+ $sql_select ="SELECT tag_id FROM $table_user_tag_values WHERE user_id = $user_id AND tag_id = $last_insert_id ";
+ $result = Database::query($sql_select, __FILE__, __LINE__);
+ //if the relationship does not exist we create it
+ if (Database::num_rows($result)==0) {
+ $sql = "INSERT INTO $table_user_tag_values SET user_id = $user_id, tag_id = $last_insert_id";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ }
+ }
+ }
+ /**
+ * Deletes an user tag
+ * @param int user id
+ * @param int field id
+ *
+ */
+ 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_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
+ $tags = UserManager::get_user_tags($user_id, $field_id);
+ //echo '';var_dump($tags);
+ if(is_array($tags) && count($tags)>0) {
+ foreach ($tags as $key=>$tag) {
+ if ($tag[1]>'0') {
+ $sql = "UPDATE $table_user_tag SET count = count - 1 WHERE id = $key ";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ }
+ $sql = "DELETE FROM $table_user_tag_values WHERE user_id = $user_id AND tag_id = $key";
+ $result = Database::query($sql, __FILE__, __LINE__);
+ }
+
+ }
+ }
+
+ /**
+ * Process the tag list comes from the UserManager::update_extra_field_value() function
+ * @param array the tag list that will be added
+ * @param int user id
+ * @param int field id
+ * @return bool
+ */
+ public function process_tags($tags, $user_id, $field_id) {
+ //We loop the tags and add it to the DB
+ if (is_array($tags)) {
+ foreach($tags as $tag) {
+ UserManager::add_tag($tag, $user_id, $field_id);
+ }
+ } else {
+ UserManager::add_tag($tags,$user_id, $field_id);
+ }
+ return true;
+ }
}
diff --git a/main/install/dokeos_main.sql b/main/install/dokeos_main.sql
index 2b58a7e80a..b447737d62 100644
--- a/main/install/dokeos_main.sql
+++ b/main/install/dokeos_main.sql
@@ -2259,3 +2259,26 @@ CREATE TABLE session_category (
date_end date default NULL,
PRIMARY KEY (id)
);
+
+
+--
+-- Table structure for table user tag
+--
+
+
+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)
+);
+
+
+CREATE TABLE user_rel_tag (
+ id int NOT NULL auto_increment,
+ user_id int NOT NULL,
+ tag_id 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 2c9e94d9c3..4ed485912f 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
@@ -20,7 +20,6 @@ ALTER TABLE session_rel_course_rel_user ADD COLUMN visibility int NOT NULL defau
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);
@@ -30,6 +29,11 @@ INSERT INTO settings_options (variable, value, display_text) VALUES ('show_cours
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');
+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));
+CREATE TABLE user_rel_tag (id int NOT NULL auto_increment,user_id int NOT NULL,tag_id int NOT NULL, PRIMARY KEY (id));
+
+
+
-- xxSTATSxx
-- xxUSERxx
diff --git a/main/social/profile.php b/main/social/profile.php
index 6aba32d0ff..2d74d10101 100644
--- a/main/social/profile.php
+++ b/main/social/profile.php
@@ -731,38 +731,46 @@ echo '';
$extra_information .= get_lang('ExtraInformation');
$extra_information .= '
';
$extra_information .='';
- $extra_information_value = '';
+ $extra_information_value = '';
foreach($extra_user_data as $key=>$data) {
- // get display text, visibility and type from user_field table
- $field_variable = str_replace('extra_','',$key);
- $sql = "SELECT field_display_text,field_visible,field_type FROM $t_uf WHERE field_variable ='$field_variable'";
- $res_field = Database::query($sql,__FILE__,__LINE__);
- $row_field = Database::fetch_row($res_field);
- $field_display_text = $row_field[0];
- $field_visible = $row_field[1];
- $field_type = $row_field[2];
-
- if ($field_visible == 1) {
- if (is_array($data)) {
- $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(',',$data).'
';
- } else {
- if ($field_type == 8) {
- $id_options = explode(';',$data);
- $value_options = array();
- // get option display text from user_field_options table
- foreach ($id_options as $id_option) {
- $sql = "SELECT option_display_text FROM $t_ufo WHERE id = '$id_option'";
- $res_options = Database::query($sql,__FILE__,__LINE__);
- $row_options = Database::fetch_row($res_options);
- $value_options[] = $row_options[0];
+ // get display text, visibility and type from user_field table
+ $field_variable = str_replace('extra_','',$key);
+ $sql = "SELECT field_display_text,field_visible,field_type,id FROM $t_uf WHERE field_variable ='$field_variable'";
+ $res_field = Database::query($sql,__FILE__,__LINE__);
+ $row_field = Database::fetch_row($res_field);
+ $field_display_text = $row_field[0];
+ $field_visible = $row_field[1];
+ $field_type = $row_field[2];
+ $field_id = $row_field[3];
+ if ($field_visible == 1) {
+ if (is_array($data)) {
+ $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(',',$data).'
';
+ } else {
+ if ($field_type == 8) {
+ $id_options = explode(';',$data);
+ $value_options = array();
+ // get option display text from user_field_options table
+ foreach ($id_options as $id_option) {
+ $sql = "SELECT option_display_text FROM $t_ufo WHERE id = '$id_option'";
+ $res_options = Database::query($sql,__FILE__,__LINE__);
+ $row_options = Database::fetch_row($res_options);
+ $value_options[] = $row_options[0];
+ }
+ $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(' ',$value_options).'
';
+ } elseif($field_type == 10) {
+ $user_tags = UserManager::get_user_tags($user_id, $field_id);
+ $tag_tmp = array();
+ foreach ($user_tags as $tags) {
+ $tag_tmp[] = $tags[0];
+ }
+ if (is_array($user_tags) && count($user_tags)>0) {
+ $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(', ',$tag_tmp).'
';
+ }
+ } else {
+ $extra_information_value .= ''.ucfirst($field_display_text).': '.$data.'
';
}
- $extra_information_value .= ''.ucfirst($field_display_text).': '.implode(' ',$value_options).'
';
- }
- else {
- $extra_information_value .= ''.ucfirst($field_display_text).': '.$data.'
';
}
}
- }
}
// if there are information to show
if (!empty($extra_information_value)) {
diff --git a/main/social/search.php b/main/social/search.php
new file mode 100644
index 0000000000..ade015737f
--- /dev/null
+++ b/main/social/search.php
@@ -0,0 +1,285 @@
+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();
+
+ $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 ';
+ }
+ $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;
+}
+
+
+
+/**
+ * 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
diff --git a/main/user/tags.php b/main/user/tags.php
new file mode 100644
index 0000000000..7580911bd7
--- /dev/null
+++ b/main/user/tags.php
@@ -0,0 +1,7 @@
+