So I've been struggling with this for 3 days now... smart people, please help!
I have 4 wordpress membership sites. All branded differently. I just want to make it so when a new user signs up a .wav file plays that just says the plans name.
I use MemberMouse for my membership plugin. It comes with push notifications so I have it set to call a php file when a new member is created. Here's the file php file.
<?php
/* this will open a new window to play the plan name sound when someone signs up */
include_once('/wp-load.php' );
require_once("/plugins/membermouse/includes/mm-constants.php");
require_once("/plugins/membermouse/includes/init.php");
echo '<script type="text/javascript" src="/AdamCallScripts/txwoo.js"></script>';
if(!isset($_GET["event_type"])){
// event type was not found, so exit
exit;
}
else{
// set the event type
$eventType = $_GET["event_type"];
}
// since we know event type exists, make sure the event is a member add type
if ($eventType == "mm_member_add" || $eventType == "mm_member_membership_change") {
echo '<script type="text/javascript">
openWin();
window.setTimeout( closeWin, 2000 );
</script>';
}
?>
Here's the JS it calls:
function openWin() {
myWindow=window.open("bell.html","","width=200,height=100");
myWindow.focus();
}
function closeWin() {
myWindow.close();
}
I can get it to work when I just open the file in a browser but I have no idea how to get it to trigger on it's own. (Oh, I have to comment out the if(event_type) part for it to work in my browser). My thought was the action of a member being created would be the trigger but no windows are opening and nothing is happening when I test it...
I'm thinking maybe I need to create custom plugin that uses ajax to post data or something...
Do I need to add a new WP action or filter or something?
Buddy you do not need to add these much of files in your request file you just want to trigger a .wav file that you can simply do in the any of the theme files like functions.php itself. As you are using Membemouse. Membermouse provides a hook named mm_member_add and run your JS on this action make a separate function that will execute your this code as soons as new member gets in this hook also provide you with many of the information like users membership etc so you do not need to fetch info with post or get variables read its documentation here http://support.membermouse.com/support/solutions/articles/9000020294-membermouse-wordpress-hooks. Hook your function on this action mm_member_add.
Related
I am trying to make a form on a modal. I have a form with 2 buttons: accept and reject.
If the user clicks on accept there is an update in that database, if the user clicks on reject there is another update.
I need to retain a certain value from database before, so I am making a select.
The problem is that I don't know how to make an insert in database using javascript (I know it is possible with jquery/ajax but how to call
it in the button?).
Here is my code:
Here is the Javascript function to insert in database that doesn't work
<script type="text/javascript">
function clicked1() {
//update candidate_jobs SET is_hired='1' WHERE candidate_id=$userId and applied_to=$row["job_id"];
var connection = new ActiveXObject("ADODB.Connection"),
recordSet = new ActiveXObject("ADODB.Recordset"),
connectionString = '';
connection.Open(connectionString);
recordSet.Open(
"update candidate_jobs SET is_hired='1' WHERE candidate_id=".$userId." and applied_to=".$row["job_id"]."";,
connection);
recordSet.close;
connection.close;
alert('You accepted the offer');
}
function clicked2() {
//idem clicked1 but change the is_hired value to be inserted in the database
alert('You rejected the offer');
}
</script>
Can it be done using Jquery and Ajax? How?
What it wrong with the code?
Thank you very much!
The concatenated sql string is prone to sql injection attacks (although obviously anyone viewing the page source can do whatever they like to the database anyway) - parameterization is the solution here and we need to use an IDENTITY or GUID.
Here is a list of possible issues:
1) The code will only ever run in IE browsers
2) You may need to download and install the COM components - ADO
3) You may need to run IE as an Administrator
4) You may need to open all sorts of security loopholes in IE (ActiveX controls, safe for scripting etc)
If you enable script debugging on the browser you'll get more info on the actual issue.
hope it helps you.
I have a site where I want a user to be able to download some data as a text file, without permanently saving the file on my server. The approach I'm trying is to use JavaScript to send a POST, using PHP to generate and save a text file. On success, JavaScript will open that file in a separate window. After a few seconds delay, it will then send a POST with the file to delete.
I have most of it working, but for some reason, when I try to delete the file, I keep getting an error - No such file or directory. I don't know why, especially since using a test file to delete in the same directory works fine. Here's what I'm using on the javascript side:
////CREATE FILE
function exportGroup() {
$.post("../Modules/Export_Mod/export_mod.php",
{ submit:'export',
groupIndex: groupSelect.value,
userRole: 'admin',
serial: <?php echo $serial;?>
},
function(data,status){
//open created file in new window
window.open("../Modules/Export_Mod/"+data);
removeExport(data);
});
};
//////REMOVE FILE
function removeExport(filename) {
///After 1 second, send post to delete file
setTimeout(function() {
$.post("../Modules/Export_Mod/export_mod.php",
{ submit:'removeExport',
file: filename
},
function(data,status){
data;
});
}, 1000);
}
and my PHP:
//I'm creating the file successfully with this
...
$filename = $groupName."_group_export.txt";
$content = $header.$dataStr;
$strlength = strlen($content);
$create = fopen($filename, "w");
$write = fwrite($create, $content, $strlength);
$close = fclose($create);
But when I try to delete a second (or more) later using this:
if (($_POST)&&($_POST['submit']=='removeExport')){
$file = $_POST['file'];
unlink($file); ///works when using an already-existing file in the same directory ... unlink('test.txt');
}
I get the error. The first thing am wondering is if I'm approaching this the right way. If not, is there a better way to do it? And then the second thing I'm wondering is why I'm getting this error and what I need to change to make it work.
I would check the server permissions to see if the php script that is running is able to delete the files that are created. If you are on a unix based script I would run the
ls -l /usr/var/
command on the directory that you are storing the files in, to see what permissions have been assigned to them.
I've done similar sorts of things where a file is created and then deleted some time later, in my case 24hrs. But what I did was to set up a cron job to find the files that are older than a period of time and then delete them. That way I don't have to depend on the browser to post back a delete request.
Another option is to set up a custom session handler that deletes files associated with the session upon close of the session. Though that may leave things lying about if the user doesn't officially log out.
Or you could keep the file data in CLOBs on MySQL and then set up a query that kills them after a period.
Or if you feel like using Cassandra, you can set a TTL on a row and it will magically disappear.
Don't get locked in to operating system files. You control what data is provided by your pages, so if you want to send back data and call it a "file" the user will never know that it is actually a database entry.
I've been working on a music player that's quite simple and to add music to it you would have to upload it to Dropbox and then manually edit the file (in this case index.php) where the playlist is held.The player then plays the links.
But what I've done is made a file which inserts value through mysql into the database.Two columns:
songname, url
Index.php:
`$(document).ready(function(){
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_N",
cssSelectorAncestor: "#jp_container_N"
}, [
{
title:"C O O L",
artist:"Le Youth",
mp3:"this is where the link must sit",
},`
How can I implement PHP query that selects the name and the link from database into that part of javascript code?
I'm sorry if there's some unclear things for you, please ask I will try to make everything clear.
PHP is a server-side language and it dies after it renders the page. So, you have two good options here.
First one is to grab all the links/names from the database, and then echo that into a JS object (using JSON seems the easiest way to handle the conversion), and then just call the link you need from that JS object. You can build the whole title/artist/mp3 object using PHP and be good to go. It should look something like this:
var mySonglist = <?php echo json_encode($databaseData) ?>;
The other option would require making AJAX calls to retrieve the link of the selected mp3. Although this might seem closer to what you're asking, due to its speed (it makes another server call), I'd suggest you do it only if you have a really, really huge number of songs at once.
So, the bottom line is: extend your PHP functionality to grab everything you need from the database, all the data, and then put that data into a JS variable which you will use to configure your player.
I am not sure that you can do db queries inside your script functions, But Do the queries outside the function and pass the php variables as arguments for the function. Below is an example.
<?php
$var="Select query here";
$name=$var[0]; $url = $var[1];
?>
<script>
play('$name','$url');
function play(name,url);
{
//your code goes here..
}
</script>
If the user navigates off the webpage, is it possible to execute a php script?
I know that Javascript can be executed..
$(window).bind('beforeunload', function(){
return 'DataTest';
});
Cookies might work, but I am not sure how a listener could track an expired cookie, and then delete the correct webpage.
A sample file system is like this:
user0814HIFA9032RHBFAP3RU.php
user9IB83BFI19Y298RYBFWOF.php
index.php
listener.py
data.txt
Typically, to create the website, php writes to the data.txt and the Python listener picks up this change, and creates the file (user[numbers]). As you might think, these files stack up overtime and they need to be deleted.
The http protocol is stateless, therefore users simply can not "navigate away".
The browser requires a page, the server returns it, and the communication stops.
The server doesn't have reliable methods to know what the client will do with that page.
Disclaimer: I'm not sure, as Fox pointed out, that this is the right way to go in your case. I actuallly upvoted Fox's answer.
However, if you absolutely need to delete each page right after the user left it, use this:
$(window).bind('beforeunload', function() {
$.ajax('yourscript.php?currentUser=0814HIFA9032RHBFAP3RU');
});
Then in yourscript.php, put something like the following:
<?php
// load your userId (for example, with $_SESSION, but do what you want here)
$actualUser = $_SESSION['userId'];
// checks if the requested id to delete fits your actual current user's id
if (isset($_GET['currentUser'] && $_GET['currentUser'] == $actualUser)
{
$user = $_GET['currentUser'];
$file = 'user'.$user.'.php';
unlink($file);
}
This topis is already present in other posts but none of the solutions mentioned worked for me so here I am, hoping someone can point me in the right direction.
Basically, I have an application with Primefaces 3.5 with 2 commandButtons that execute backing bean methods to generate two different reports as an output stream (no GET available). One of this report is generated as attachment while the other one should be displayed in another tab. Both in the same form.
My problem comes with the report generated in a separate tab: since the reports share the same form, I cannot use target=blank in the form definition and since I have to do validations in my backing bean, I must show possible error messages in the main tab, opening the new one only in case everything goes smoothly.
I tried the following js in the form page:
function test() {
document.getElementById("formRep3_1").target = '_blank';
}
called by the bean with
RequestContext.getCurrentInstance().execute("test()");
after validation successful. But it doesn't work.
I also tried setting an oncomplete="test()" on report button, slightly modifying the js like this:
function test() {
var v = '<h:outputText value="#{repReqStatus.resultCheck}" />';
if (v.value == "success") {
document.getElementById("formRep3_1").target = '_blank';
}
else {
alert('no');
}
}
but it seems the oncomplete doesn't get called at all! Not even if I do another check like
oncomplete="if (!args.validationFailed){test()}"
So yeah, I'm lost. Any help is really appreciated.
Thanks!
You can't change the link's target during invoking the link's action. It's too late.
Your best bet is to keep out the target="_blank" and instead invoke a JavaScript window.open() on the desired URL. You can store the PDF report in session, or prepare request parameters for the URL so that it can generate the desired PDF report based on those request parameters.