How to: Zodiac works. Part 2

Here we can make tutorials ... how to ...
it will make it more easy to start with our new sites.

How to: Zodiac works. Part 2

Postby admin » September 18th, 2010, 8:06 pm

This tutorials is made of radioact from http://www.vldcrowd.com

Ok, let's automate our star sign selection with the help of jQuery and for the sake of our users.

1. Add this function to your misc.js (it's location is /includes/js/)


Code: Select all

// calculate sun sign
function calc_sunsign()
{
       
        var month = $('#field_age_month').val();
                if ( ! month ) return;
       
        var day = $('#field_age_day').val();
                if ( ! day ) return;
       
if ( month == 1 && day <=19) {sign = "Capricorn"; sign_id = "438";}
else if (month == 1 && day >=20) {sign = "Aquarius"; sign_id = "439";}
else if (month == 2 && day <=18) {sign = "Aquarius"; sign_id = "439";}
else if (month == 2 && day >=19) {sign = "Pisces"; sign_id = "440";}
else if (month == 3 && day <=20) {sign = "Pisces"; sign_id = "440";}
else if (month == 3 && day >=21) {sign = "Aries"; sign_id = "441";}
else if (month == 4 && day <=20) {sign = "Aries"; sign_id = "441";}
else if (month == 4 && day >=21) {sign = "Taurus"; sign_id = "442";}
else if (month == 5 && day <=20) {sign = "Taurus"; sign_id = "442";}
else if (month == 5 && day >=21) {sign = "Gemini"; sign_id = "443";}
else if (month == 6 && day <=20) {sign = "Gemini"; sign_id = "443";}
else if (month == 6 && day >=21) {sign = "Cancer"; sign_id = "444";}
else if (month == 7 && day <=21) {sign = "Cancer"; sign_id = "444";}
else if (month == 7 && day >=22) {sign = "Leo"; sign_id = "445";}
else if (month == 8 && day <=21) {sign = "Leo"; sign_id = "445";}
else if (month == 8 && day >=22) {sign = "Virgo"; sign_id = "446";}
else if (month == 9 && day <=21) {sign = "Virgo"; sign_id = "446";}
else if (month == 9 && day >=22) {sign = "Libra"; sign_id = "447";}
else if (month == 10 && day <=21) {sign = "Libra"; sign_id = "447";}
else if (month == 10 && day >=22) {sign = "Scorpio"; sign_id = "448";}
else if (month == 11 && day <=21) {sign = "Scorpio"; sign_id = "448";}
else if (month == 11 && day >=22) {sign = "Sagittarius"; sign_id = "449";}
else if (month == 12 && day <=20) {sign = "Sagittarius"; sign_id = "449";}
else if (month == 12 && day >=21) {sign = "Capricorn"; sign_id = "438";}

$('#field_zodiac').val(sign_id);

return;
}


Put in place of my sign_ids your zodiac ids you can find them in between square brackets creating/editing custom field "Zodiac".

Image

2. Open for editing your account_register.tpl and account_profile.tpl

Find word "birthday" after it you can see:

<select class="select" name="{field_label}_month">{dropdownlist:top.months,field_value_month}</select>

<select class="select" name="{field_label}_day">{dropdownlist:top.days,field_value_day}</select>

Modify <select ...> tags accordingly by adding:
id="field_{field_label}_month" onchange="calc_sunsign()"
and
id="field_{field_label}_day" onchange="calc_sunsign()"

Well now this code looks like that:

<select class="select" name="{field_label}_month" id="field_{field_label}_month" onchange="calc_sunsign()">{dropdownlist:top.months,field_value_month}</select>
<select class="select" name="{field_label}_day" id="field_{field_label}_day" onchange="calc_sunsign()">{dropdownlist:top.days,field_value_day}</select>

Every change of the month or day causes recalculating zodiac sign.

3. Press F5 button twice - refresh misc.js file in your browser. Visit registration page and profile data editing page, and try changing birthday.

4. Send mass private messages to existing users asking them set their Zodiac signs or fill Zodiac data yourself :)

Oops! You have more than one thousand users and don't want to spend the rest of your life filling zodiacs?

I have some solution I developed half an hour ago.
As dear vldCrowd member take it for free.


Code: Select all

UPDATE `vld_members_data` SET data_zodiac = 'Capri_id' WHERE LEFT (RIGHT (data_age, 4), 2) = '01' AND RIGHT (data_age, 2) <= 19;
UPDATE `vld_members_data` SET data_zodiac = 'Aquarius_id' WHERE LEFT (RIGHT (data_age, 4), 2) = '01' AND RIGHT (data_age, 2) >= 20;
UPDATE `vld_members_data` SET data_zodiac = 'Aquarius_id' WHERE LEFT (RIGHT (data_age, 4), 2) = '02' AND RIGHT (data_age, 2) <= 18;


Capri_id is a place for you to put ID of the Capricorn you have at step 1.

Notice: I didn't complete the query list having short of time. Do you feel analogy with step 1? If you wish to help other vldCrowd members please complete query list and post it in comments then I'll update this post.

5. (optional) Run mentioned above SQL query.


Code: Select all

...
UPDATE `vld_members_data` SET data_zodiac = '438' WHERE LEFT (RIGHT (data_age, 4), 2) = '01' AND RIGHT (data_age, 2) <= 19;
UPDATE `vld_members_data` SET data_zodiac = '439' WHERE LEFT (RIGHT (data_age, 4), 2) = '01' AND RIGHT (data_age, 2) >= 20;
UPDATE `vld_members_data` SET data_zodiac = '439' WHERE LEFT (RIGHT (data_age, 4), 2) = '02' AND RIGHT (data_age, 2) <= 18;


Dan, I hope you wouldn't mind if I use your screen shot about running queries in phpMyadmin.

Image

6. Enjoy!

you can read the originalpost from vldcrowd
//gugu
Admin VldMods Forum
User avatar
admin
Site Admin
 
Posts: 105
Joined: 13 Aug 2010
Location: sweden
Knowledge: 6
Vld Version: 2.7
Vld Site: http://www.love2u.se

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron