');
$form->addElement('text', 'api_key_generate', get_lang('MyApiKey'), array('size' => 40, 'id' => 'id_api_key_generate'));
$form->addElement('html', '
');
$form->addElement('button', 'generate_api_key', get_lang('GenerateApiKey'), array('id' => 'id_generate_api_key', 'onclick' => 'generate_open_id_form()')); //generate_open_id_form()
}
// SUBMIT
if (is_profile_editable()) {
$form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
} else {
$form->freeze();
}
$user_data = array_merge($user_data, $extra_data);
$form->setDefaults($user_data);
/*
==============================================================================
FUNCTIONS
==============================================================================
*/
/*
-----------------------------------------------------------
LOGIC FUNCTIONS
-----------------------------------------------------------
*/
/**
* Can a user edit his/her profile?
*
* @return boolean Editability of the profile
*/
function is_profile_editable() {
return $GLOBALS['profileIsEditable'];
}
/*
-----------------------------------------------------------
PRODUCTIONS FUNCTIONS
-----------------------------------------------------------
*/
/**
* Upload a submitted user production.
*
* @param $user_id User id
* @return The filename of the new production or FALSE if the upload has failed
*/
function upload_user_production($user_id) {
$image_path = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
$production_repository = $image_path['dir'].$user_id.'/';
if (!file_exists($production_repository)) {
$perm = api_get_setting('permissions_for_new_directories');
$perm = octdec(!empty($perm) ? $perm : '0770');
@mkdir($production_repository, $perm, true);
}
$filename = replace_dangerous_char($_FILES['production']['name']);
$filename = disable_dangerous_file($filename);
if (filter_extension($filename)) {
if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename)) {
return $filename;
}
}
return false; // this should be returned if anything went wrong with the upload
}
/**
* Check current user's current password
* @param char password
* @return bool true o false
* @uses Gets user ID from global variable
*/
function check_user_password($password){
global $_user;
$user_id = $_user['user_id'];
if ($user_id != strval(intval($user_id)) || empty($password)) { return false; }
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$password = api_get_encrypted_password($password);
$sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND password='".$password."'";
$result = Database::query($sql_password, __FILE__, __LINE__);
return Database::num_rows($result) != 0;
}
/**
* Check current user's current password
* @param char email
* @return bool true o false
* @uses Gets user ID from global variable
*/
function check_user_email($email){
global $_user;
$user_id = $_user['user_id'];
if ($user_id != strval(intval($user_id)) || empty($email)) { return false; }
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND email='".$email."'";
$result = Database::query($sql_password, __FILE__, __LINE__);
return Database::num_rows($result) != 0;
}
/*
==============================================================================
MAIN CODE
==============================================================================
*/
$filtered_extension = false;
$update_success = false;
$upload_picture_success = false;
$upload_production_success = false;
$msg_fail_changue_email = false;
$msg_is_not_password = false;
if (!empty($_SESSION['change_email'])) {
$msg_fail_changue_email= ($_SESSION['change_email'] == 'success');
unset($_SESSION['change_email']);
}
elseif (!empty($_SESSION['is_not_password'])) {
$msg_is_not_password = ($_SESSION['is_not_password'] == 'success');
unset($_SESSION['is_not_password']);
}
elseif (!empty($_SESSION['profile_update'])) {
$update_success = ($_SESSION['profile_update'] == 'success');
unset($_SESSION['profile_update']);
}
elseif (!empty($_SESSION['image_uploaded'])) {
$upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
unset($_SESSION['image_uploaded']);
}
elseif (!empty($_SESSION['production_uploaded'])) {
$upload_production_success = ($_SESSION['production_uploaded'] == 'success');
unset($_SESSION['production_uploaded']);
}
elseif (isset($_POST['remove_production'])) {
foreach (array_keys($_POST['remove_production']) as $production) {
UserManager::remove_user_production($_user['user_id'], urldecode($production));
}
if ($production_list = UserManager::build_production_list($_user['user_id'], true, true)) {
$form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions_list');
}
$form->removeElement('productions_list');
$file_deleted = true;
} elseif ($form->validate()) {
$wrong_current_password = false;
// $user_data = $form->exportValues();
$user_data = $form->getSubmitValues();
// set password if a new one was provided
if (!empty($user_data['password0'])) {
if (check_user_password($user_data['password0'])) {
if (!empty($user_data['password1'])) {
$password = $user_data['password1'];
}
} else {
$wrong_current_password = true;
$_SESSION['is_not_password'] = 'success';
}
}
if (empty($user_data['password0']) && !empty($user_data['password1'])) {
$wrong_current_password = true;
$_SESSION['is_not_password'] = 'success';
}
if (!check_user_email($user_data['email']) && !empty($user_data['password0']) && ($wrong_current_password==false)) {
$changeemail = $user_data['email'];
}
if (!check_user_email($user_data['email']) && empty($user_data['password0'])){
$_SESSION['change_email'] = 'success';
}
// upload picture if a new one is provided
if ($_FILES['picture']['size']) {
if ($new_picture = UserManager::update_user_picture($_user['user_id'], $_FILES['picture']['name'], $_FILES['picture']['tmp_name'])) {
$user_data['picture_uri'] = $new_picture;
$_SESSION['image_uploaded'] = 'success';
}
}
// remove existing picture if asked
elseif (!empty($user_data['remove_picture'])) {
UserManager::delete_user_picture($_user['user_id']);
$user_data['picture_uri'] = '';
}
// upload production if a new one is provided
if ($_FILES['production']['size']) {
$res = upload_user_production($_user['user_id']);
if (!$res) {
//it's a bit excessive to assume the extension is the reason why upload_user_production() returned false, but it's true in most cases
$filtered_extension = true;
} else {
$_SESSION['production_uploaded'] = 'success';
}
}
// remove values that shouldn't go in the database
unset($user_data['password0'],$user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
$user_data['remove_picture'], $user_data['apply_change'],$user_data['email'] );
// Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
// we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
$my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : '';
if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) {
//ensure there is at least a http:// scheme in the URI provided
$user_data['openid'] = 'http://'.$my_user_openid;
}
$extras = array();
// build SQL query
$sql = "UPDATE $table_user SET";
unset($user_data['api_key_generate']);
foreach ($user_data as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field
$new_key = substr($key, 6);
// format array date to 'Y-m-d' or date time to 'Y-m-d H:i:s'
if (is_array($value) && isset($value['Y']) && isset($value['F']) && isset($value['d'])) {
if (isset($value['H']) && isset($value['i'])) {
// extra field date time
$time = mktime($value['H'],$value['i'],0,$value['F'],$value['d'],$value['Y']);
$extras[$new_key] = date('Y-m-d H:i:s',$time);
} else {
// extra field date
$time = mktime(0,0,0,$value['F'],$value['d'],$value['Y']);
$extras[$new_key] = date('Y-m-d',$time);
}
} else {
$extras[$new_key] = $value;
}
} else {
$sql .= " $key = '".Database::escape_string($value)."',";
}
}
//changue email
if (isset($changeemail) && !isset($password) ) {
$sql .= " email = '".Database::escape_string($changeemail)."' ";
} elseif (isset($password) && isset($changeemail)) {
$sql .= " email = '".Database::escape_string($changeemail)."', ";
$password = api_get_encrypted_password($password);
$sql .= " password = '".Database::escape_string($password)."'";
} elseif (isset($password) && !isset($changeemail)) {
$password = api_get_encrypted_password($password);
$sql .= " password = '".Database::escape_string($password)."'";
} else {
// remove trailing , from the query we have so far
$sql = rtrim($sql, ',');
}
$sql .= " WHERE user_id = '".$_user['user_id']."'";
//var_dump($sql); exit();
Database::query($sql, __FILE__, __LINE__);
// User tag process
//1. Deleting all user tags
$list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(USER_FIELD_TYPE_TAG);
if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
foreach ($list_extra_field_type_tag as $id) {
UserManager::delete_user_tags(api_get_user_id(), $id);
}
}
//2. Update the extra fields and user tags if available
if (is_array($extras) && count($extras)> 0) {
foreach ($extras as $key => $value) {
//3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
$myres = UserManager::update_extra_field_value($_user['user_id'], $key, $value);
}
}
// re-init the system to take new settings into account
$uidReset = true;
include api_get_path(INCLUDE_PATH).'local.inc.php';
$_SESSION['profile_update'] = 'success';
header("Location: ".api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos($_SERVER['QUERY_STRING'], '&fe=1') === false ? '&fe=1' : ''));
exit;
}
if (isset($_GET['show'])) {
if ((api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') || (api_get_setting('allow_social_tool') == 'true')) {
//$interbreadcrumb[] = array ('url' => 'javascript: void(0);', 'name' => get_lang('SocialNetwork'));
} elseif ((api_get_setting('allow_social_tool') == 'false' && api_get_setting('allow_message_tool') == 'true')) {
//$interbreadcrumb[] = array('url' => 'javascript: void(0);', 'name' => get_lang('MessageTool'));
}
}
/*
==============================================================================
MAIN DISPLAY SECTION
==============================================================================
*/
Display :: display_header('');
if (api_get_setting('allow_social_tool') != 'true') {
if (api_get_setting('extended_profile') == 'true') {
echo '';
echo '
';
SocialManager::show_social_menu('home', null, $user_id, $show_full_profile);
echo '
';
echo '
';
echo '
';
if (api_get_setting('extended_profile') == 'true') {
$show = isset($_GET['show']) ? '&show='.Security::remove_XSS($_GET['show']) : '';
if (isset($_GET['type']) && $_GET['type'] == 'extended') {
echo '
';
} else {
echo '
';
}
}
echo '
';
$form->display();
echo '
';
echo '
';
} else {
// Style position:absolute has been removed for Opera-compatibility.
//echo '