Closed pihome-shc closed 3 years ago
this is just basic work, if backup_email is empty or invalid email it should give model Record User e-mail.zip
why not use the email address from the user table
yes we can use that as well my last example was written while i was half asleep early morning :)
what do you think of following, its not anywhere near finished, still need to write saving part and validation isnt working for me,
header.php
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Missing e-mail address!!!</h4>
</div>
<div class="modal-body">
<p>Thank you for using PiHome Smart Heating. Looks like your email address is missing from the system, please enter valid e-mail address to get the latest PiHome updates straight in to your inbox.</p>
<form>
<div class="form-group">
<input type="text" class="form-control" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email Address">
</div>
<input type="submit" name="submit" value="<?php echo $lang['save']; ?>" class="btn btn-default btn-sm">
</form>
</div>
</div>
</div>
</div>
footer.php
<?php
//Function to check if email address is valid
function checkEmail($email) {
$find1 = strpos($email, '@');
$find2 = strpos($email, '.');
return ($find1 !== false && $find2 !== false && $find2 > $find1);
}
//Set user id from user session variable
$user_id = $_SESSION['user_id'];
$query = "select * from user where id = '{$user_id}' LIMIT 1;";
$result = $conn->query($query);
$user_row = mysqli_fetch_array($result);
$email = $user_row['email'];
//Check if email address exit
if (!checkEmail($email)){
echo "
<script>
$(document).ready(function(){
$(\"#myModal\").modal('show');
});
</script>";
}?>
I'll graft in the code and have a play :)
if we used the user table, then probably no need to prompt for name as we could use 'fullname', also how about a 'No Thanks' button and I guess the header code would go in model.php
Yes I meant full name there, if model code goes into model.php it will slow down home screen and that is why weather model is in header.php, We need users email addres to send email to PiHome users.
used your original idea for validation, which worked okay for me
function checkEmail($email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } else { return true; } }
Instead of prompting for a username input, how about a message something like 'Please enter a valid Email Address for user - ' fullname from the user table
would onclick="update_user_email()" with associated request.js and db.php do the save job
Alert message instead of model? but that can be ignored by user whereas model is get display on every menu click. i tried this function works if email is missing but i save email in database it still shows up.
the validation worked okay for me ie no modal popup if a valid email address is present in user table
also got rid of the X close option in modat header by adding to sb-admin-2.css
.modal-header .close { display:none; }
Please give this a try
@twa127 sorry for late, for some reason my PiHome do not like user user_email_address variable, i have to modify some variables to get this working on my installation, can you test these changes.
js
//update user email address
function update_email(){
var idata="w=user_email&o=update";
idata+="&email_add="+document.getElementById("email_add").value;
idata+="&wid=0";
$.get('db.php',idata)
.done(function(odata){
if(odata.Success)
reload_page();
else
console.log(odata.Message);
})
.fail(function( jqXHR, textStatus, errorThrown ){
if(jqXHR==401 || jqXHR==403) return;
console.log("update_email: Error.\r\n\r\njqXHR: "+jqXHR+"\r\n\r\ntextStatus: "+textStatus+"\r\n\r\nerrorThrown:"+errorThrown);
})
.always(function() {
});
}
db.php
//update user email address
if($what=="user_email"){
if($opp=="update"){
$email_add = $_GET['email_add'];
$user_id = $_SESSION['user_id'];
$query = "UPDATE `user` SET `email`= '{$email_add}' WHERE id = '{$user_id}';";
if($conn->query($query)){
header('Content-type: application/json');
echo json_encode(array('Success'=>'Success','Query'=>$query));
return;
}else{
header('Content-type: application/json');
echo json_encode(array('Message'=>'Database query failed.\r\nQuery=' . $query));
return;
}
}
}
header.php
<input type="email" id="email_add" class="form-control" placeholder="Email Address">
for some reason that does not work for me, not updating the database
Interesting, may be change variables to something meaning less
more change i forget in header.php
<input type="submit" name="submit" value="<?php echo $lang['save']; ?>" class="btn btn-default btn-sm" onclick="update_email()">
that worked okay for me
can you update your pull request to include this change, thank you for working on this.
Okay done, also added the fixes for chart_load.php and scheduling.php
@twa127 great work. new release 1.77 issue is opened just in case if i missed anything #392
Hi,
The upgrade process should not include update_db.php at this point in time as we have not updated pihome_mysql_database.sql and MySQL_View.sql yet to avoid problems after running the data migration. If you execute update_db.php it will remove the changed made by migrate_db.php
Ok, if I remember correctly we updated database as well last time,
yep we did, running update_db.php before migrate_controller.php would be okay
as of today, we do not have any way of communicating with any user, all installation do call home once every day, i think this can be good addition to send updates to users on every new release etc. Solution: on login to PiHome web interface user gets model alert to add email address if it is missing and this way we are sure to have communication channel.