Should fix some bugs when using the user tags

skala
Julio Montoya 13 years ago
parent 2196bebe65
commit 38ef514596
  1. 46
      main/admin/user_add.php
  2. 35
      main/admin/user_edit.php
  3. 31
      main/auth/profile.php
  4. 6
      main/inc/ajax/user_manager.ajax.php
  5. 67
      main/inc/lib/usermanager.lib.php

@ -22,8 +22,10 @@ api_protect_admin_script(true);
$is_platform_admin = api_is_platform_admin() ? 1 : 0; $is_platform_admin = api_is_platform_admin() ? 1 : 0;
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = ' $htmlHeadXtra[] = '
<script type="text/javascript"> <script>
<!-- <!--
function enable_expiration_date() { //v2.0 function enable_expiration_date() { //v2.0
document.user_add.radio_expiration_date[0].checked=false; document.user_add.radio_expiration_date[0].checked=false;
@ -59,7 +61,6 @@ function display_drh_list(){
document.getElementById("id_platform_admin").style.display="none"; document.getElementById("id_platform_admin").style.display="none";
} }
} }
//--> //-->
</script>'; </script>';
@ -145,14 +146,14 @@ if (count($extAuthSource) > 0) {
} }
} }
if ($nb_ext_auth_source_added > 0) { if ($nb_ext_auth_source_added > 0) {
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', null, get_lang('ExternalAuthentication').' ', 2); $group[] = $form->createElement('radio', 'password_auto', null, get_lang('ExternalAuthentication').' ', 2);
$group[] =& HTML_QuickForm::createElement('select', 'auth_source', null, $auth_sources); $group[] = $form->createElement('select', 'auth_source', null, $auth_sources);
$group[] =& HTML_QuickForm::createElement('static', '', '', '<br />'); $group[] = $form->createElement('static', '', '', '<br />');
} }
} }
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'<br />', 1); $group[] = $form->createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'<br />', 1);
$group[] =& HTML_QuickForm::createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0); $group[] = $form->createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0);
$group[] =& HTML_QuickForm::createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();')); $group[] = $form->createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();'));
$form->addGroup($group, 'password', get_lang('Password'), ''); $form->addGroup($group, 'password', get_lang('Password'), '');
// Status // Status
@ -181,8 +182,8 @@ $form->addElement('html', '</div>');
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
// Platform admin // Platform admin
$group = array(); $group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('No'), 0); $group[] = $form->createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('No'), 0);
$display = ($_POST['status'] == STUDENT || !isset($_POST['status'])) ? 'none' : 'block'; $display = ($_POST['status'] == STUDENT || !isset($_POST['status'])) ? 'none' : 'block';
$form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.';">'); $form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.';">');
$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;'); $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;');
@ -191,21 +192,30 @@ if (api_is_platform_admin()) {
// Send email // Send email
$group = array(); $group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('Yes'), 1); $group[] = $form->createElement('radio', 'send_mail', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('No'), 0); $group[] = $form->createElement('radio', 'send_mail', null, get_lang('No'), 0);
$form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;'); $form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;');
// Expiration Date // Expiration Date
$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0); $form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
$group = array (); $group = array ();
$group[] = & $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1); $group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
$group[] = & $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();')); $group[] = $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();'));
$form->addGroup($group, 'max_member_group', null, '', false); $form->addGroup($group, 'max_member_group', null, '', false);
// Active account or inactive account // Active account or inactive account
$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1); $form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
$form->addElement('radio', 'active', '', get_lang('Inactive'), 0); $form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
$extra_data = UserManager::get_extra_user_data(0, true); $extra_data = UserManager::get_extra_user_data(0, true);
UserManager::set_extra_fields_in_form($form, $extra_data, 'user_add');
$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'user_add');
$jquery_ready_content = $return_params['jquery_ready_content'];
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
$htmlHeadXtra[] ='<script>
$(document).ready(function(){
'.$jquery_ready_content.'
});
</script>';
// Set default values // Set default values
$defaults['admin']['platform_admin'] = 0; $defaults['admin']['platform_admin'] = 0;
@ -224,8 +234,8 @@ $defaults = array_merge($defaults, $extra_data);
$form->setDefaults($defaults); $form->setDefaults($defaults);
// Submit button // Submit button
$html_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'submit_plus', get_lang('Add').'+', 'class="add"'); $html_results_enabled[] = $form-> createElement ('style_submit_button', 'submit_plus', get_lang('Add').'+', 'class="add"');
$html_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'submit', get_lang('Add'), 'class="add"'); $html_results_enabled[] = $form-> createElement ('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
$form->addGroup($html_results_enabled); $form->addGroup($html_results_enabled);
// Validate form // Validate form
@ -283,7 +293,7 @@ if( $form->validate()) {
$picture_uri = UserManager::update_user_picture($user_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']); $picture_uri = UserManager::update_user_picture($user_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language); UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
} }
$extras = array();
foreach ($user as $key => $value) { foreach ($user as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field if (substr($key, 0, 6) == 'extra_') { //an extra field
UserManager::update_extra_field_value($user_id, substr($key, 6), $value); UserManager::update_extra_field_value($user_id, substr($key, 6), $value);

@ -18,8 +18,11 @@ api_protect_admin_script(true);
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']); $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']);
api_protect_super_admin($user_id, null, true); api_protect_super_admin($user_id, null, true);
$is_platform_admin = api_is_platform_admin() ? 1 : 0; $is_platform_admin = api_is_platform_admin() ? 1 : 0;
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = ' $htmlHeadXtra[] = '
<script> <script>
@ -183,16 +186,16 @@ if (count($extAuthSource) > 0) {
} }
if ($nb_ext_auth_source_added > 0) { if ($nb_ext_auth_source_added > 0) {
// @todo check the radio button for external authentification and select the external authentification in the menu // @todo check the radio button for external authentification and select the external authentification in the menu
$group[] =& HTML_QuickForm::createElement('radio', 'reset_password', null, get_lang('ExternalAuthentication').' ', 3); $group[] =$form->createElement('radio', 'reset_password', null, get_lang('ExternalAuthentication').' ', 3);
$group[] =& HTML_QuickForm::createElement('select', 'auth_source', null, $auth_sources); $group[] =$form->createElement('select', 'auth_source', null, $auth_sources);
$group[] =& HTML_QuickForm::createElement('static', '', '', '<br />'); $group[] =$form->createElement('static', '', '', '<br />');
$form->addGroup($group, 'password', null, '', false); $form->addGroup($group, 'password', null, '', false);
} }
} }
$form->addElement('radio', 'reset_password', null, get_lang('AutoGeneratePassword'), 1); $form->addElement('radio', 'reset_password', null, get_lang('AutoGeneratePassword'), 1);
$group = array(); $group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'reset_password', null, null, 2); $group[] =$form->createElement('radio', 'reset_password', null, null, 2);
$group[] =& HTML_QuickForm::createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();')); $group[] =$form->createElement('password', 'password', null, array('onkeydown' => 'javascript: password_switch_radio_button();'));
$form->addGroup($group, 'password', null, '', false); $form->addGroup($group, 'password', null, '', false);
// Status // Status
@ -229,8 +232,8 @@ $form->addElement('html', '</div>');
// Platform admin // Platform admin
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$group = array(); $group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', null, get_lang('Yes'), 1); $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'platform_admin', null, get_lang('No'), 0); $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
$user_data['status'] == 1 ? $display = 'block':$display = 'none'; $user_data['status'] == 1 ? $display = 'block':$display = 'none';
@ -241,8 +244,8 @@ if (api_is_platform_admin()) {
// Send email // Send email
$group = array(); $group = array();
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('Yes'), 1); $group[] =$form->createElement('radio', 'send_mail', null, get_lang('Yes'), 1);
$group[] =& HTML_QuickForm::createElement('radio', 'send_mail', null, get_lang('No'), 0); $group[] =$form->createElement('radio', 'send_mail', null, get_lang('No'), 0);
$form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;', false); $form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;', false);
// Registration Date // Registration Date
@ -263,8 +266,16 @@ if (!$user_data['platform_admin']) {
// EXTRA FIELDS // EXTRA FIELDS
$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'user_edit', true, $user_id);
$jquery_ready_content = $return_params['jquery_ready_content'];
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
$htmlHeadXtra[] ='<script>
$(document).ready(function(){
'.$jquery_ready_content.'
});
</script>';
UserManager::set_extra_fields_in_form($form, $extra_data, 'user_edit', true);
// Submit button // Submit button
$form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"'); $form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
@ -292,7 +303,7 @@ $error_drh = false;
// Validate form // Validate form
if ( $form->validate()) { if ( $form->validate()) {
$user = $form->exportValues(); $user = $form->getSubmitValues();
$is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']); $is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
if ($user['status'] == DRH && $is_user_subscribed_in_course) { if ($user['status'] == DRH && $is_user_subscribed_in_course) {
@ -352,7 +363,7 @@ if ( $form->validate()) {
} }
foreach ($user as $key => $value) { foreach ($user as $key => $value) {
if(substr($key, 0, 6) == 'extra_') { //an extra field if (substr($key, 0, 6) == 'extra_') { //an extra field
UserManager::update_extra_field_value($user_id, substr($key, 6), $value); UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
} }
} }

@ -12,8 +12,6 @@
* Code * Code
*/ */
/* Init section */
// Language files that should be included. // Language files that should be included.
$language_file = array('registration', 'messages', 'userInfo'); $language_file = array('registration', 'messages', 'userInfo');
$cidReset = true; $cidReset = true;
@ -34,7 +32,7 @@ if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user[
$htmlHeadXtra[] = '<script src="../inc/lib/javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="../inc/lib/javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />'; $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = '<script type="text/javascript"> $htmlHeadXtra[] = '<script>
function confirmation(name) { function confirmation(name) {
if (confirm("'.get_lang('AreYouSureToDelete', '').' " + name + " ?")) { if (confirm("'.get_lang('AreYouSureToDelete', '').' " + name + " ?")) {
document.forms["profile"].submit(); document.forms["profile"].submit();
@ -101,7 +99,6 @@ require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile'); $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
$table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_user = Database :: get_main_table(TABLE_MAIN_USER);
@ -283,11 +280,11 @@ if (is_platform_authentication() && is_profile_editable() && api_get_setting('pr
// EXTRA FIELDS // EXTRA FIELDS
$extra_data = UserManager::get_extra_user_data(api_get_user_id(), true); $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'profile'); $return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'profile', api_get_user_id());
$jquery_ready_content = $return_params['jquery_ready_content']; $jquery_ready_content = $return_params['jquery_ready_content'];
// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
$htmlHeadXtra[] ='<script type="text/javascript"> $htmlHeadXtra[] ='<script>
$(document).ready(function(){ $(document).ready(function(){
'.$jquery_ready_content.' '.$jquery_ready_content.'
}); });
@ -615,7 +612,8 @@ if ($form->validate()) {
// User tag process // User tag process
//1. Deleting all user tags //1. Deleting all user tags
$list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(USER_FIELD_TYPE_TAG); $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(UserManager::USER_FIELD_TYPE_TAG);
if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) { if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
foreach ($list_extra_field_type_tag as $id) { foreach ($list_extra_field_type_tag as $id) {
UserManager::delete_user_tags(api_get_user_id(), $id); UserManager::delete_user_tags(api_get_user_id(), $id);
@ -623,20 +621,21 @@ if ($form->validate()) {
} }
//2. Update the extra fields and user tags if available //2. Update the extra fields and user tags if available
if (is_array($extras) && count($extras)> 0) { if (is_array($extras) && count($extras)> 0) {
foreach ($extras as $key => $value) { foreach ($extras as $key => $value) {
//3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function //3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
$myres = UserManager::update_extra_field_value(api_get_user_id(), $key, $value); UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
} }
} }
// re-init the system to take new settings into account // re-init the system to take new settings into account
$_SESSION['_user']['uidReset'] = true; $_SESSION['_user']['uidReset'] = true;
$_SESSION['noredirection'] = true; $_SESSION['noredirection'] = true;
$_SESSION['profile_update'] = 'success'; $_SESSION['profile_update'] = 'success';
$url = api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos($_SERVER['QUERY_STRING'], '&fe=1') === false ? '&fe=1' : ''); $url = api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos($_SERVER['QUERY_STRING'], '&fe=1') === false ? '&fe=1' : '');
header("Location: ".$url); header("Location: ".$url);
exit; exit;
} }
@ -678,7 +677,6 @@ if (!empty($file_deleted)) {
if ($upload_production_success) { if ($upload_production_success) {
$message.='<br />'.get_lang('ProductionUploaded'); $message.='<br />'.get_lang('ProductionUploaded');
} }
Display :: display_confirmation_message($message, false); Display :: display_confirmation_message($message, false);
} }
@ -723,7 +721,6 @@ $url_big_image = $big_image.'?rnd='.time();
$show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false; $show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false;
if (api_get_setting('allow_social_tool') == 'true') { if (api_get_setting('allow_social_tool') == 'true') {
echo '<div class="row-fluid">'; echo '<div class="row-fluid">';
echo '<div class="span3">'; echo '<div class="span3">';
echo SocialManager::show_social_menu('home', null, api_get_user_id(), false, $show_delete_account_button); echo SocialManager::show_social_menu('home', null, api_get_user_id(), false, $show_delete_account_button);

@ -46,9 +46,9 @@ switch ($action) {
if (api_is_anonymous()) { if (api_is_anonymous()) {
echo ''; echo '';
} else { } else {
$field_id = intval($_GET['field_id']); if (isset($_GET['tag']) && isset($_GET['field_id'])) {
$tag = $_GET['tag']; echo UserManager::get_tags($_GET['tag'], $_GET['field_id'],'json','10');
echo UserManager::get_tags($tag, $field_id,'json','10'); }
} }
break; break;
case 'generate_api_key': case 'generate_api_key':

@ -1236,6 +1236,7 @@ class UserManager {
if ($user_id != strval(intval($user_id))) return false; if ($user_id != strval(intval($user_id))) return false;
if ($user_id === false) return false; if ($user_id === false) return false;
$fvalues = ''; $fvalues = '';
//echo '<pre>'; print_r($fvalue); //echo '<pre>'; print_r($fvalue);
if (is_array($fvalue)) { if (is_array($fvalue)) {
foreach($fvalue as $val) { foreach($fvalue as $val) {
@ -1258,7 +1259,7 @@ class UserManager {
//4. Tags are process here comes from main/auth/profile.php //4. Tags are process here comes from main/auth/profile.php
UserManager::process_tags(explode(';', $fvalues), $user_id, $rowuf['id']); UserManager::process_tags(explode(';', $fvalues), $user_id, $rowuf['id']);
return true; return true;
break; break;
case self::USER_FIELD_TYPE_RADIO: case self::USER_FIELD_TYPE_RADIO:
case self::USER_FIELD_TYPE_SELECT: case self::USER_FIELD_TYPE_SELECT:
case self::USER_FIELD_TYPE_SELECT_MULTIPLE: case self::USER_FIELD_TYPE_SELECT_MULTIPLE:
@ -1681,8 +1682,6 @@ class UserManager {
$sql .= " WHERE field_filter = $field_filter "; $sql .= " WHERE field_filter = $field_filter ";
} }
} }
$sql .= " ORDER BY f.field_order"; $sql .= " ORDER BY f.field_order";
$res = Database::query($sql); $res = Database::query($sql);
@ -1690,6 +1689,7 @@ class UserManager {
while ($row = Database::fetch_array($res)) { while ($row = Database::fetch_array($res)) {
if ($row['type'] == self::USER_FIELD_TYPE_TAG) { if ($row['type'] == self::USER_FIELD_TYPE_TAG) {
$tags = self::get_user_tags_to_string($user_id,$row['id'],false); $tags = self::get_user_tags_to_string($user_id,$row['id'],false);
$extra_data['extra_'.$row['fvar']] = $tags; $extra_data['extra_'.$row['fvar']] = $tags;
} else { } else {
$sqlu = "SELECT field_value as fval FROM $t_ufv WHERE field_id=".$row['id']." AND user_id = ".$user_id; $sqlu = "SELECT field_value as fval FROM $t_ufv WHERE field_id=".$row['id']." AND user_id = ".$user_id;
@ -1812,7 +1812,7 @@ class UserManager {
public static function get_all_extra_field_by_type($field_type) { public static function get_all_extra_field_by_type($field_type) {
// database table definition // database table definition
$table_field = Database::get_main_table(TABLE_MAIN_USER_FIELD); $table_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
// all the information of the field // all the information of the field
$sql = "SELECT * FROM $table_field WHERE field_type='".Database::escape_string($field_type)."'"; $sql = "SELECT * FROM $table_field WHERE field_type='".Database::escape_string($field_type)."'";
@ -2561,13 +2561,12 @@ class UserManager {
public static function get_tags($tag, $field_id, $return_format='json',$limit=10) { public static function get_tags($tag, $field_id, $return_format='json',$limit=10) {
// database table definition // database table definition
$table_user_tag = Database::get_main_table(TABLE_MAIN_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); $field_id = intval($field_id);
$limit = intval($limit); $limit = intval($limit);
$tag = trim(Database::escape_string($tag)); $tag = trim(Database::escape_string($tag));
// all the information of the field // all the information of the field
$sql = "SELECT id, tag from $table_user_tag $sql = "SELECT DISTINCT id, tag from $table_user_tag
WHERE field_id = $field_id AND tag LIKE '$tag%' ORDER BY tag LIMIT $limit"; WHERE field_id = $field_id AND tag LIKE '$tag%' ORDER BY tag LIMIT $limit";
$result = Database::query($sql); $result = Database::query($sql);
$return = array(); $return = array();
@ -2645,7 +2644,8 @@ class UserManager {
// all the information of the field // 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) $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"; WHERE field_id = $field_id AND user_id = $user_id ORDER BY tag";
$result = Database::query($sql);
$result = Database::query($sql);
$return = array(); $return = array();
if (Database::num_rows($result)> 0) { if (Database::num_rows($result)> 0) {
while ($row = Database::fetch_array($result,'ASSOC')) { while ($row = Database::fetch_array($result,'ASSOC')) {
@ -2676,12 +2676,12 @@ class UserManager {
* @param int field_id * @param int field_id
* @return int returns 0 if fails otherwise the tag id * @return int returns 0 if fails otherwise the tag id
*/ */
public function get_tag_id($tag, $field_id) { public static function get_tag_id($tag, $field_id) {
$table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG);
$tag = Database::escape_string($tag); $tag = Database::escape_string($tag);
$field_id = intval($field_id); $field_id = intval($field_id);
//with COLLATE latin1_bin to select query in a case sensitive mode //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"; $sql = "SELECT id FROM $table_user_tag WHERE tag LIKE '$tag' AND field_id = $field_id";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result)>0) { if (Database::num_rows($result)>0) {
$row = Database::fetch_array($result,'ASSOC'); $row = Database::fetch_array($result,'ASSOC');
@ -2697,7 +2697,7 @@ class UserManager {
* @param int field_id * @param int field_id
* @return int 0 if fails otherwise the tag id * @return int 0 if fails otherwise the tag id
*/ */
public function get_tag_id_from_id($tag_id, $field_id) { public static function get_tag_id_from_id($tag_id, $field_id) {
$table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG);
$tag_id = intval($tag_id); $tag_id = intval($tag_id);
$field_id = intval($field_id); $field_id = intval($field_id);
@ -2719,7 +2719,7 @@ class UserManager {
* @param int field id of the tag * @param int field id of the tag
* @return bool * @return bool
*/ */
public function add_tag($tag, $user_id, $field_id) { public static function add_tag($tag, $user_id, $field_id) {
// database table definition // database table definition
$table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG);
$table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
@ -2729,6 +2729,7 @@ class UserManager {
$field_id = intval($field_id); $field_id = intval($field_id);
$tag_id = UserManager::get_tag_id($tag,$field_id); $tag_id = UserManager::get_tag_id($tag,$field_id);
/* IMPORTANT /* IMPORTANT
* @todo we don't create tags with numbers * @todo we don't create tags with numbers
* *
@ -2746,20 +2747,22 @@ class UserManager {
$last_insert_id = Database::get_last_insert_id(); $last_insert_id = Database::get_last_insert_id();
}*/ }*/
} else { } 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);
$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);
$last_insert_id = $tag_id;
}
} }
//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);
$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);
$last_insert_id = $tag_id;
}
if (!empty($last_insert_id) && ($last_insert_id!=0)) { if (!empty($last_insert_id) && ($last_insert_id!=0)) {
//we insert the relationship user-tag //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 "; $sql_select ="SELECT tag_id FROM $table_user_tag_values WHERE user_id = $user_id AND tag_id = $last_insert_id ";
@ -2778,7 +2781,7 @@ class UserManager {
* @param int field id * @param int field id
* *
*/ */
public function delete_user_tags($user_id, $field_id) { public static function delete_user_tags($user_id, $field_id) {
// database table definition // database table definition
$table_user_tag = Database::get_main_table(TABLE_MAIN_TAG); $table_user_tag = Database::get_main_table(TABLE_MAIN_TAG);
$table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG); $table_user_tag_values = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
@ -2804,7 +2807,7 @@ class UserManager {
* @param int field id * @param int field id
* @return bool * @return bool
*/ */
public function process_tags($tags, $user_id, $field_id) { public static function process_tags($tags, $user_id, $field_id) {
//We loop the tags and add it to the DB //We loop the tags and add it to the DB
if (is_array($tags)) { if (is_array($tags)) {
foreach($tags as $tag) { foreach($tags as $tag) {
@ -3321,7 +3324,7 @@ class UserManager {
* @param int The user id * @param int The user id
* @return array containing path_certificate and cat_id * @return array containing path_certificate and cat_id
*/ */
public function get_user_path_certificate($user_id) { public static function get_user_path_certificate($user_id) {
$my_certificate = array(); $my_certificate = array();
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$table_gradebook_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table_gradebook_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
@ -3354,7 +3357,7 @@ class UserManager {
* @return bool True if the user is a coach * @return bool True if the user is a coach
* *
*/ */
public function is_session_course_coach($user_id, $course_code, $session_id) { public static function is_session_course_coach($user_id, $course_code, $session_id) {
$tbl_session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
// Protect data // Protect data
$user_id = intval($user_id); $user_id = intval($user_id);
@ -3377,7 +3380,7 @@ class UserManager {
* @param string Optional second URL of website where to look for favicon.ico * @param string Optional second URL of website where to look for favicon.ico
* @return string Path of icon to load * @return string Path of icon to load
*/ */
public function get_favicon_from_url($url1, $url2 = null) { public static function get_favicon_from_url($url1, $url2 = null) {
$icon_link = ''; $icon_link = '';
$url = $url1; $url = $url1;
if (empty($url1)) { if (empty($url1)) {
@ -3439,7 +3442,7 @@ class UserManager {
return false; return false;
} }
static function set_extra_fields_in_form($form, $extra_data, $form_name, $admin_permissions = false) { static function set_extra_fields_in_form($form, $extra_data, $form_name, $admin_permissions = false, $user_id = null) {
$user_id = intval($user_id); $user_id = intval($user_id);
// EXTRA FIELDS // EXTRA FIELDS
@ -3576,7 +3579,7 @@ class UserManager {
break; break;
case self::USER_FIELD_TYPE_TAG: case self::USER_FIELD_TYPE_TAG:
//the magic should be here //the magic should be here
$user_tags = UserManager::get_user_tags(api_get_user_id(),$field_details[0]); $user_tags = UserManager::get_user_tags($user_id, $field_details[0]);
$tag_list = ''; $tag_list = '';
if (is_array($user_tags) && count($user_tags)> 0) { if (is_array($user_tags) && count($user_tags)> 0) {
@ -3647,7 +3650,7 @@ EOF;
return $types; return $types;
} }
function add_user_as_admin($user_id) { static function add_user_as_admin($user_id) {
$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); $table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
$user_id = intval($user_id); $user_id = intval($user_id);
@ -3657,7 +3660,7 @@ EOF;
} }
} }
function remove_user_admin($user_id) { static function remove_user_admin($user_id) {
$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); $table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
$user_id = intval($user_id); $user_id = intval($user_id);
if (self::is_admin($user_id)) { if (self::is_admin($user_id)) {

Loading…
Cancel
Save