редактирование личных данных и пароля


создание страницы редактирование личных данных и пароля (частный случай)

Параметры:

редактирование личных данных

код шаблона

<div class="form-cont">
<form action="" id="personal-inf" method="post" class="form-personal col-md-6" role="form" onsubmit=" var parstr = jQuery('#personal-inf').serialize(); doAjRouteJSON('personal-area/do/do_personal_upd.php','personal_res','&'+parstr,'','','');return false;">
<div class="form-group clearfix">
<label for="LNAME" class="col-md-12 control-label">Прізвище:<d/label>
<div class="input-group clearfix">
<dinput type="text" class="form-control" name="LNAME" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('FAMILIA'));|%}">
</div>
</div>
<div class="form-group clearfix">
<label for="NAME" class="col-md-12 control-label">Iм'я:</label>
<div class="input-group clearfix">
<input type="text" class="form-control" name="NAME" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('IMIA'));|%}">
</div>
</div>
<div class="form-group clearfix">
<label for="SNAME" class="col-md-12 control-label">Побатькові:</label>
<div class="input-group clearfix">
<input type="text" class="form-control" name="SNAME" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('OTCHEST'));|%}">
</div>
</div>
<div class="form-group clearfix">
<label for="EMAIL" class="col-md-12 control-label">Email:</label>
<div class="input-group clearfix">
<input type="email" class="form-control" name="EMAIL" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('EMAIL'));|%}">
</div>
</div>
<div class="form-group clearfix">
<label for="PHONE" class="col-md-12 control-label">Телефон:</label>
<div class="input-group clearfix">
<input type="text" class="form-control" name="PHONE" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('TEL'));|%}">
</div>
</div>
<div class="form-group clearfix">
<label for="ADRES" class="col-md-12 control-label">Адресса:</label>
<div class="input-group clearfix">
<input type="text" class="form-control" name="ADRES" value="{%inj|cmd@eval|php@global $persona_obj; $out = hsc($persona_obj->gf('ADRES'));|%}">
</div>
</div>
<button type="submit" class="btn btn-block btn-lg">Сохранить</button>
</form>
<div class="col-md-12" id="personal_res"></div>
</div>

код файла do

<?php
$json_array = array('html'=>'','html2'=>'','js'=>''); // то что вернется
global $_SESSION;
$error='';
$mess2='';
$NAME = ''; if (isset($_GET['NAME'])); @$NAME = $_GET['NAME'];
$LNAME = ''; if (isset($_GET['LNAME'])); @$LNAME = $_GET['LNAME'];
$SNAME = ''; if (isset($_GET['SNAME'])); @$SNAME = $_GET['SNAME'];
$EMAIL = ''; if (isset($_GET['EMAIL'])); @$EMAIL = $_GET['EMAIL'];
$PHONE = ''; if (isset($_GET['PHONE'])); @$PHONE = $_GET['PHONE'];
$ADRES = ''; if (isset($_GET['ADRES'])); @$ADRES = $_GET['ADRES'];
$OLD_PASS = ''; if (isset($_GET['OLD_PASS'])); @$OLD_PASS = $_GET['OLD_PASS'];
$NEW_PASS = ''; if (isset($_GET['NEW_PASS'])); @$NEW_PASS = $_GET['NEW_PASS'];
$PASS_CHECK = ''; if (isset($_GET['PASS_CHECK'])); @$PASS_CHECK = $_GET['PASS_CHECK'];
$persona_id = (int)$_SESSION['w_karloid'];
$NEW_PASS = trim($NEW_PASS);
$OLD_PASS = trim($OLD_PASS);
$PASS_CHECK = trim($PASS_CHECK);
if(strlen($NEW_PASS)){
$op = GetFieldFromSQL($this->conn, "SELECT UPAS
FROM PERSONA
WHERE ID=".$persona_id,'');
if(hash('sha512',$OLD_PASS)!=$op) $error .=(($error)?', ':'').'Невiрний старий пароль';
if($NEW_PASS!=$PASS_CHECK) $error .=(($error)?', ':'').'Паролі не співпадають';
}
if(!$error)
{
$pers = NewObject($this->conn,'TPersona',$persona_id);
$pers->check_rights = false;
if(strlen($NEW_PASS)) $pers->sf('NEWPAS',$NEW_PASS);
$pers->sf('IMIA',$NAME);
$pers->sf('TEL',$PHONE);
$pers->sf('EMAIL',$EMAIL);
$pers->sf('FAMILIA',$LNAME);
$pers->sf('OTCHEST',$SNAME);
$pers->sf('ADRES',$ADRES);
$s = $pers->BaseUpdate();
if($s)
{
$error.=$s;
}
}
global $m_conf;
if(!$error) $mess2="Дані успішно змінено";
if ($error)
$json_array['html'] = "<div class="c-red bg-danger">".hsc($error)."</div>"; // Возврат в блок в шаблоне
elseif ($mess2)
$json_array['html'] = "<div class="c-green bg-success">".hsc($mess2)."</div>";
if (!$error)
{
$loc = $m_conf['host'].'pa-personal-profile';
$json_array['js'] = "window.location='$loc';";
}
die(json_encode($json_array));
?>

пароль

код шаблона

<div class="form-cgange-pass">
<form action="" id="personal-pass__change" method="post" class="form-personal col-md-6" role="form" onsubmit="
var parstr = jQuery('#personal-pass__change').serialize();
doAjRouteJSON('personal-area/do/do_change_pass.php','personal_res_pass','&'+parstr,'','','');return false;">
<div class="form-group clearfix">
<label for="OLD_PASS" class="col-md-12 control-label ">Старый пароль:</label>
<div class="input-group clearfix">
<input type="password" class="form-control" name="OLD_PASS">
</div>
</div>
<div class="form-group clearfix">
<label for="NEW_PASS" class="col-md-12 control-label ">Новий пароль:</label>
<div class="input-group clearfix">
<input type="password" class="form-control" name="NEW_PASS">
</div>
</div>
<div class="form-group clearfix">
<label for="PASS_CHECK" class="col-md-12 control-label ">Подтверждение пароля:</label>
<div class="input-group clearfix">
<input type="password" class="form-control" name="PASS_CHECK">
</div>
</div>
<button type="submit" class="btn btn-block btn-lg">Сохранить</button>
</form>
<div class="col-md-12" id="personal_res_pass"></div>
</div>

код файла do

<?php
$json_array = array('html'=>'','html2'=>'','js'=>''); // то что вернется
global $_SESSION;
$error='';
$mess2='';
$OLD_PASS = ''; if (isset($_GET['OLD_PASS'])); @$OLD_PASS = $_GET['OLD_PASS'];
$NEW_PASS = ''; if (isset($_GET['NEW_PASS'])); @$NEW_PASS = $_GET['NEW_PASS'];
$PASS_CHECK = ''; if (isset($_GET['PASS_CHECK'])); @$PASS_CHECK = $_GET['PASS_CHECK'];
$persona_id = (int)$_SESSION['w_karloid'];
$NEW_PASS = trim($NEW_PASS);
$OLD_PASS = trim($OLD_PASS);
$PASS_CHECK = trim($PASS_CHECK);
if(strlen($OLD_PASS)){
$op = GetFieldFromSQL($this->conn, "SELECT UPAS
FROM PERSONA
WHERE ID=".$persona_id,'');
if(md5($OLD_PASS)!=$op) $error .=(($error)?', ':'').'Неверный старый пароль';
}else{
$error .=' Не введен старый пароль ';
}
if(!$NEW_PASS) $error .=(($error)?', ':'').'Не введен новый пароль';
if(!$PASS_CHECK) $error .=(($error)?', ':'').'Не введен новый пароль повторно';
if($NEW_PASS!=$PASS_CHECK) $error .=(($error)?', ':'').'Пароли не совпадают';
if(!$error)
{
$pers = NewObject($this->conn,'TPersona',$persona_id);
$pers->check_rights = false;
if(strlen($NEW_PASS)) $pers->sf('UPAS',md5($NEW_PASS));
$error = $pers->BaseUpdate();
}
global $m_conf;
if(!$error) $mess2="Пароль изменен";
if ($error)
$json_array['html'] = "<div class="c-red bg-danger">".hsc($error)."</div>"; // Возврат в блок в шаблоне
elseif ($mess2)
$json_array['html'] = "<div class="c-green bg-success">".hsc($mess2)."</div>";
if (!$error)
{
$loc = $m_conf['host'].'pa-personal-profile';
$json_array['js'] = "window.location='$loc';";
}
die(json_encode($json_array));
?>