Month: February 2014

Make user cannot write certain words in text field jquery

$("#UserContactmeForm").submit(function(e){
					e.preventDefault();
					var mess = $("#message").val();
					var out;
					if(mess.indexOf("@")  >= 0)
					{
						out+= "@";
										
					}
					if(mess.indexOf("skype")  >= 0)
					{
						out+= ",skype";
										
					}
					if(mess.indexOf("e-mail")  >= 0)
					{
						out+= ",e-mail";
										
					}
								
				 if(out)
					{
						alert("You cannot use these words  "+out);
					}
				if(out="" || !out)
					{
										$("form").submit();
					}
		});
							

Embed vimeo,youtube new and youtube old videos


function getParm(url, base) {
        var re = new RegExp("(\\?|&)" + base + "\\=([^&]*)(&|$)");
        var matches = url.match(re);
        if (matches) {
            return(matches[2]);
        } else {
            return("");
        }
    }
	
function parseVideoURL(url) {
    
    
    
    var retVal = {};
    var matches;
    
    if (url.indexOf("youtube.com/watch") != -1) {
        retVal.provider = "youtube";
        retVal.id = getParm(url, "v");
    } else if (matches = url.match(/vimeo.com\/(\d+)/)) {
        retVal.provider = "vimeo";
        retVal.id = matches[1];
    }
	 else if(url.indexOf("/youtu.be/") != -1)
	 {
	   retVal.provider = "youtube";
	   
	   retVal.id = url.split("/")[3];
	   alert(url.split("/")[3]);
	 }
    return(retVal);
}

function createit()
{
var name= $("#nameofalbum").val();
var link1 = $("#location").val();
var details = $("#details").val();
var video = parseVideoURL(link1);
$.ajax({
     url:"createvideo.php",
	 type:"post",
	 data:{'name':name,'link':video.id,'video_from':video.provider,'details':details},
	 success:function(da){
	         $("#uppics").show(0);
			if(video.provider =="youtube")
				{
			  var row = "<tr id='"+da+"'><td>" + name + "</td><td></td><td>"+ details+"</td><td><img src='images/pencil.png' height='40px' width='40px'></td><td><img src='images/denied.png' height='40px' width='40px'></td></tr>";
				}
			if(video.provider =="vimeo")
			{
			var row =  "<tr id='"+da+"'><td>" + name + "</td><td></td><td>"+ details+"</td><td><img src='images/pencil.png' height='40px' width='40px'></td><td><img src='images/denied.png' height='40px' width='40px'></td></tr>";
			}
			$("#albumbody").append(row);
               $("input[type=text]").val(""); 
    }
});
}

Manage email content from database for whole project

<?php
function babyboom_mail($to,$subject, $body_text){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: BabyBoomApps ' . "\r\n";
return mail($to, $subject, $body_text, $headers);
}

function replace_email_template_variables($uid,$mailid,$link = 0) { // This function replaces the variables in the Body text for the email
$user_info_row = mysql_fetch_array(mysql_query("SELECT * FROM `bb_users` WHERE `id` = ".$uid));
$mail_info_row = mysql_fetch_array(mysql_query("SELECT * FROM `bb_emails` WHERE `id` = ".$mailid));


//get user information
$name = $user_info_row['fname']." ".$user_info_row['lname'];
$email = $user_info_row['email'];
$user_name = $user_info_row['username'];
$usertype = $user_info_row['usertype'];
if($usertype = "f")
{
$type = "Facebook";
}
elseif($usertype = "l")
{
$type = "LinkedIn";
}
elseif($usertype = "t")
{
$type = "Twitter";
}
else
{
$type = "";
}
//get email content from database
$body_text = $mail_info_row['mail_content'];
$body_subject = $mail_info_row['subject'];

//replace user information in mail content
$body_text = eregi_replace('%link%', $link, $body_text);
$body_text = eregi_replace('%utype%', $type, $body_text);
$body_text = eregi_replace('%name%', $name, $body_text);
$body_text = eregi_replace('%email%', $email, $body_text);
$body_text = eregi_replace('%user_name%', $user_name, $body_text);
$body_text = "<pre>".$body_text."</pre>";
return babyboom_mail($email,$body_subject,$body_text);

}



save the file as mails.php
Now send the email using above file

include('includes/mails.php'); //include the above file 
replace_email_template_variables($outputuser['id'],3);//pass the user id and email id from database

Mutiple file uploader ajax,jquery

	$("#addbtnajax").click(function(e){
		var len = document.getElementById(‘addmore’).files.length;
		var file = new Array();
		var formdata = new FormData();
		for(i=0;i<len;i++)
		{
			file[i] = document.getElementById('addmore').files[i];
			formdata.append("file"+i, file[i]);
		}
		//formdata.append("file1", file);
		var ajax = new XMLHttpRequest();

		ajax.open("POST", "uploadselect.php");
		ajax.send(formdata);

		});

	   
});

Jquery editable table

function addpublic() 
{ 
	var data1 = $('#group-create-public').serialize(); 
	$(".group1").show(0); 
	$.ajax({ 
			url:"group-create-code.php", 
			type:"post", 
			data:data1, 
			success:function(da){ 
			var row = "" + document.getElementById('namepb').value + "" + document.getElementById('emailpb').value + ""; 
			$("#publicbody").append(row); 
			$("input[type=text]").val(""); 
			} 
	}); 
	setTimeout(function() { $(".group1").fadeOut(1500); }, 2000); 
} 
function addprivate() {
		 var data1 = $('#group-create-private').serialize(); 
		 $(".group1").show(0); 
		 $.ajax({ 
				 url:"group-create-codeprivate.php", 
				 type:"post", 
				 data:data1, 
				 success:function(da){ 
				 var row = "" + document.getElementById('namep').value + "" + document.getElementById('emailp').value + ""; 
				 $("#privatebody").append(row); 
				 $("input[type=text]").val(""); 
				 } 
		 }); 
		 setTimeout(function() { 
		 $(".group1").fadeOut(1500); }, 2000); 
 } 
 function deletegp(id) {
		 $.ajax({ 
				 url:"delete-member.php", 
				 type:"post", 
				 data:{'id':id}, 
				 success:function(da){ 
				 $("#"+id).hide(0); 
				 } 
		 }); 
 } 
 function editgp(id) {
		 var name = $("#"+id).children('td:first').text(); 
		 var email = $("#"+id).children('td:first').next('td').text(); 
		 var row = ' '; 
		 $("#"+id).html(row); 
 } 
 function updatemember(id) {
		 var name = $("#updatename").val();
		 var email = $("#updateemail").val(); 
		 $.ajax({ 
				 url:"update-member.php", 
				 type:"post", 
				 data:{'id':id,'name':name,'email':email}, 
				 success:function(da){
				 var html = "" + name + "" + email + " "; 
				 $("#"+id).html(html); 
				 } 
		 }); 
 }