Custom creation users and assign role and custom form altering
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
<?php
require './includes/password.inc';
function custom_module_menu(){
$items['country/autocomplete'] = array(
'page callback' => '_country_autocomplete',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['admin/config/backdraw'] = array(
'title' => 'draw',
'description' => 'Section for handling draw in backend.',
'position' => 'left',
'weight' => -19,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('access administration pages'),
'file' => 'system.admin.inc',
);
$items['admin/config/backdraw/simple_draw'] = array(
'title' => 'draw Management',
'description' => 'This menu is for simple type draw.',
'page callback' => 'simple_draw_management',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => '1',
);
$items['admin/config/backdraw/special_draw'] = array(
'title' => 'Special draw Management',
'description' => 'This menu is for special type draw.',
'page callback' => 'special_draw_management',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => '3',
);
$items['admin/config/backdraw/simple_enteries'] = array(
'title' => 'draw Enteries',
'description' => 'This menu is for simple enteries management.',
'page callback' => 'simple_enteries_management',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => '2',
);
$items['admin/config/backdraw/special_enteries'] = array(
'title' => 'Special draw Enteries',
'description' => 'This menu is for special enteries management.',
'page callback' => 'special_enteries_management',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
'weight' => '4',
);
$items['popup_form_check'] = array(
'title' => 'Popup Form Validate',
'page callback' => 'popup_form_check',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['user_winning_draw'] = array(
'title' => 'User Winning draw',
'page callback' => 'user_winning_draw',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['user_participate_draw'] = array(
'title' => 'User Participate draw',
'page callback' => 'user_participate_draw',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['business_participate_draw'] = array(
'title' => 'Business Participate draw',
'page callback' => 'business_participate_draw',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['custom_module_security_form_ajax_submit'] = array(
'title' => 'Question Form',
'page callback' => 'custom_module_security_form_ajax_submit',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
$items['custom_module_city_tracking_ajax'] = array(
'title' => 'City Form',
'page callback' => 'custom_module_city_tracking_ajax',
'access callback' => TRUE,
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function simple_draw_management(){
global $base_path, $base_url,$user;
drupal_goto($base_url.'/admin/simple-draw');
}
function special_draw_management(){
global $base_path, $base_url,$user;
drupal_goto($base_url.'/admin/special-draw');
}
function simple_enteries_management(){
global $base_path, $base_url,$user;
$theme_path = base_path().''.path_to_theme();
$rows = array();
$header = array(
array('data' => 'No.'),
array('data' => 'User name', 'field' => 'dse.uid'),
array('data' => 'Winners'),
array('data' => 'Entered By'),
array('data' => 'draw name', 'field' => 'dse.draw_id'),
array('data' => 'Participated', 'field' => 'dse.created'),
array('data' => 'Security Queston'),
array('data' => 'Answer'),
);
if(isset($_GET['sort']) && isset($_GET['order'])) {
// Sort it Ascending or Descending?
if($_GET['sort'] == 'asc')
$sort = 'ASC';
else
$sort = 'DESC';
// Which column will be sorted
switch($_GET['order']) {
case 'draw name':
$order = 'draw_id';
break;
case 'User name':
$order = 'uid';
break;
case 'Participated':
$order = 'created';
break;
default:
$order = 'draw_id';
}
}
else {
$sort = 'DESC';
$order = 'created';
}
if(isset($_SESSION['keyword']) && !empty($_SESSION['keyword'])){
$keyword = $_SESSION['keyword'];
$query = db_select('node', 'n'); //Select the node table and give it the alias of n
$query->join('draw_social_enteries', 'dse', 'n.nid = dse.draw_id'); //join users, give it alias u, where u.uid = n.uid
$query->fields('n', array('title')); //get these fields from the node table
$query->fields('dse', array('uid','draw_id','entry_type','created')); //get these fields from the users table
$query->condition('n.title', '%'.$keyword.'%', 'LIKE'); //only published nodes, the n in n.status is needed
$query->orderBy($order, $sort);
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(10);
$draw_Data1 = $query->execute();
}
$query = db_select("draw_social_enteries", "dse");
$query->fields("dse", array("uid","draw_id","entry_type","created"));
$query->orderBy($order, $sort);
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(10);
$draw_Data = $query->execute();
if(isset($_SESSION['keyword']) && !empty($_SESSION['keyword'])){
$draw_Data = $draw_Data1;
}else{
$draw_Data = $draw_Data;
}
if(isset($draw_Data) && !empty($draw_Data)){
if(isset($_REQUEST['page'])){
$i = 10*$_REQUEST['page']+1;
}else{
$i = '1';
}
foreach($draw_Data as $draw_Data){
$user_Data = db_query(" SELECT * FROM users WHERE uid= ".$draw_Data->uid)->fetchObject();
$simple_draw = db_query(" SELECT * FROM node WHERE nid= ".$draw_Data->draw_id)->fetchObject();
$winner_draw = db_query(" SELECT * FROM draw_temp_winners WHERE draw_id= ".$draw_Data->draw_id)->fetchAll();
$user_question_data = db_query(" SELECT * FROM security_questions WHERE draw_id= ".$draw_Data->draw_id." AND uid=".$draw_Data->uid)->fetchObject();
if(isset($user_question_data->uid)){
$userquestion = $user_question_data->question;
$useranswer = $user_question_data->answer;
}else{
$userquestion = '';
$useranswer = '';
}
if(isset($simple_draw->nid) && !empty($simple_draw->nid)){
$draw_link = url($base_url.'/node/'.$simple_draw->nid);
}else{
$draw_link = '';
}
if(isset($user_Data->uid) && !empty($user_Data->uid)){
$user_link = url($base_url.'/user/'.$user_Data->uid);
}else{
$user_link = '';
}
$winner = '';
foreach($winner_draw as $winner_draw){
if(isset($winner_draw->winner_name) && !empty($winner_draw->winner_name)&& isset($user_Data->name) && !empty($user_Data->name) && $winner_draw->winner_name== $user_Data->name){
$winner = "
";
}else{
$winner = '';
}
}
if(isset($user_Data->name) && !empty($user_Data->name)){
$name = $user_Data->name;
}else{
$name = '';
}
if(isset($simple_draw->title) && !empty($simple_draw->title)){
$title = $simple_draw->title;
}else{
$title = '';
}
$myString = "".$draw_Data->entry_type."";
$entry_type = preg_replace('/_/', ' ', $myString);
$rows[] = array(
$i,
l(ucfirst ($name), $user_link),
$winner,
ucfirst($entry_type),
l($title, $draw_link),
date('l F d o h:i',$draw_Data->created),
$userquestion,
$useranswer
);
$i++;
}
}
$search_from = drupal_get_form('custom_module_simple_search_form');
function tcontrol_start_theme($form) {
$variables['element'] = $form;
$output = drupal_render($form);
$variables['element']['#children'] = $output;
return theme_form($variables);
}
$output = '';
$output .= tcontrol_start_theme($search_from);
if(isset($_SESSION['keyword']) && !empty($_SESSION['keyword'])){
$caption = "
";
}else{
$caption = t('');
}
$output .= theme_table(
array(
"header" => $header,
"rows" => $rows,
"attributes" => array("width"=>"100%"),
"sticky" => true, // Table header will be sticky
"caption" => $caption,
"colgroups" => array(),
"empty" => t("No record found.") // The message to be displayed if table is empty
)
).theme("pager");
return $output;
}
function custom_module_theme($existing, $type, $theme, $path)
{
if($type == 'module')
{
return array(
'simple_enteries_management' => array(
'variables' => array('result'=>NULL),
'template' => 'simple-draw-enteries'
),
'special_enteries_management' => array(
'variables' => array('result'=>NULL),
'template' => 'special-draw-enteries'
),
'user_winning_draw' => array(
'variables' => array('result'=>NULL),
'template' => 'user-winning-draw'
),
'user_participate_draw' => array(
'variables' => array('result'=>NULL),
'template' => 'user-participate-draw'
),
'business_participate_draw' => array(
'variables' => array('result'=>NULL),
'template' => 'business-participate-draw'
),
);
}
//return array(); //will raise fatal error if void
}
function user_winning_draw(){
global $base_path, $base_url,$user;
$uid = $user->uid;
if(isset($_SESSION['winning_keyword']) && !empty($_SESSION['winning_keyword'])){
$sql = 'select * from {draw_temp_winners} WHERE uid='.$uid.' AND draw_name LIKE :term';
$result = db_query($sql, array(':term' => '%' . db_like($_SESSION['winning_keyword'])))->fetchAll();
}else{
$result = db_query("select * from draw_temp_winners WHERE uid='".$uid."' ORDER BY `id` DESC LIMIT 0,10")->fetchAll();
}
$output = theme('user_winning_draw', array('result'=>$result));
return $output;
}
function user_participate_draw(){
global $base_path, $base_url,$user;
$uid = $user->uid;
if(isset($_SESSION['participate_keyword']) && !empty($_SESSION['participate_keyword'])){
$sql = 'select n.title,dse.* from {node} as n left join {draw_social_enteries} as dse on n.nid = dse.draw_id WHERE dse.uid='.$uid.' AND n.title LIKE :term';
$result = db_query($sql, array(':term' => '%' . db_like($_SESSION['participate_keyword'])))->fetchAll();
}else{
$result = db_query("select * from draw_social_enteries WHERE uid='".$uid."' ORDER BY `id` DESC LIMIT 0,50")->fetchAll();
}
$output = theme('user_participate_draw', array('result'=>$result));
return $output;
}
function special_enteries_management(){
global $base_path, $base_url,$user;
$theme_path = base_path().''.path_to_theme();
$rows = array();
$header = array(
array('data' => 'No.'),
array('data' => 'User name', 'field' => 'dse.uid'),
array('data' => 'Winners'),
array('data' => 'Entered By'),
array('data' => 'draw name', 'field' => 'dse.draw_id'),
array('data' => 'Participated', 'field' => 'dse.created'),
);
if(isset($_GET['sort']) && isset($_GET['order'])) {
// Sort it Ascending or Descending?
if($_GET['sort'] == 'asc')
$sort = 'ASC';
else
$sort = 'DESC';
// Which column will be sorted
switch($_GET['order']) {
case 'draw name':
$order = 'draw_id';
break;
case 'User name':
$order = 'uid';
break;
break;
case 'Participated':
$order = 'created';
break;
default:
$order = 'draw_id';
}
}
else {
$sort = 'ASC';
$order = 'draw_id';
}
if(isset($_SESSION['special_keyword']) && !empty($_SESSION['special_keyword'])){
$keyword = $_SESSION['special_keyword'];
$query = db_select('node', 'n'); //Select the node table and give it the alias of n
$query->join('draw_special_social_enteries', 'dse', 'n.nid = dse.draw_id'); //join users, give it alias u, where u.uid = n.uid
$query->fields('n', array('title')); //get these fields from the node table
$query->fields('dse', array('uid','draw_id','entry_type','created')); //get these fields from the users table
$query->condition('n.title', '%'.$keyword.'%', 'LIKE'); //only published nodes, the n in n.status is needed
$query->orderBy($order, $sort);
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(10);
$draw_Data1 = $query->execute();
}
$query = db_select("draw_special_social_enteries", "dse");
$query->fields("dse", array("uid","draw_id","entry_type","created"));
$query->orderBy($order, $sort);
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(10);
$draw_Data = $query->execute();
if(isset($_SESSION['special_keyword']) && !empty($_SESSION['special_keyword'])){
$draw_Data = $draw_Data1;
}else{
$draw_Data = $draw_Data;
}
if(isset($draw_Data) && !empty($draw_Data)){
if(isset($_REQUEST['page'])){
$i = 10*$_REQUEST['page']+1;
}else{
$i = '1';
}
foreach($draw_Data as $draw_Data){
$user_Data = db_query(" SELECT * FROM users WHERE uid= ".$draw_Data->uid)->fetchObject();
$simple_draw = db_query(" SELECT * FROM node WHERE nid= ".$draw_Data->draw_id)->fetchObject();
$winner_draw = db_query(" SELECT * FROM draw_temp_winners WHERE draw_id= ".$draw_Data->draw_id)->fetchAll();
if(isset($simple_draw->nid) && !empty($simple_draw->nid)){
$draw_link = url($base_url.'/node/'.$simple_draw->nid);
}
if(isset($user_Data->uid) && !empty($user_Data->uid)){
$user_link = url($base_url.'/user/'.$user_Data->uid);
}else{
$user_link = '';
}
$winner = '';
foreach($winner_draw as $winner_draw){
if(isset($winner_draw->winner_name) && !empty($winner_draw->winner_name)&& isset($user_Data->name) && !empty($user_Data->name) && $winner_draw->winner_name== $user_Data->name){
$winner = "
";
}else{
$winner = '';
}
}
if(isset($user_Data->name) && !empty($user_Data->name)){
$name = $user_Data->name;
}else{
$name = '';
}
$myString = "".$draw_Data->entry_type."";
$entry_type = preg_replace('/_/', ' ', $myString);
$rows[] = array(
$i,
l(ucfirst ($name), $user_link),
$winner,
ucfirst ($entry_type),
l($simple_draw->title, $draw_link),
date('l F d o h:i',$draw_Data->created),
);
$i++;
}
}
$search_from = drupal_get_form('custom_module_special_search_form');
function tcontrol_special_start_theme($form) {
$variables['element'] = $form;
$output = drupal_render($form);
$variables['element']['#children'] = $output;
return theme_form($variables);
}
$output = '';
$output .= tcontrol_special_start_theme($search_from);
if(isset($_SESSION['special_keyword']) && !empty($_SESSION['special_keyword'])){
$caption = "
";
}else{
$caption = t('');
}
$output .= theme_table(
array(
"header" => $header,
"rows" => $rows,
"attributes" => array("width"=>"100%"),
"sticky" => true, // Table header will be sticky
"caption" => $caption,
"colgroups" => array(),
"empty" => t("No record found.") // The message to be displayed if table is empty
)
).theme("pager");
return $output;
}
function custom_module_form_alter(&$form, &$form_state, $form_id) {
//echo $form_id;die;
global $base_path, $base_url,$user;
$theme_path = base_path().''.path_to_theme();
if($form_id == "user_pass"){
$form['actions']['submit']['#value'] = 'Submit';
}
if($user->uid == '1'){
if ($form_id == 'system_site_information_settings') {
$form['custom_module_distance_setting'] = array(
'#type' => 'textfield',
'#title' => t('Distance (In miles)'),
'#default_value' => variable_get('custom_module_distance_setting', TRUE),
);
$form['sf_global_latitude'] = array(
'#type' => 'textfield',
'#title' => t('SF Latitude'),
'#default_value' => variable_get('sf_global_latitude', TRUE),
);
$form['sf_global_longitude'] = array(
'#type' => 'textfield',
'#title' => t('SF Longitude'),
'#default_value' => variable_get('sf_global_longitude', TRUE),
);
}
return;
}else{
if($form_id == "user_profile_form"){
$destination = 'user/'.$user->uid.'/cancel';
$form['actions']['submit']['#value'] = 'Save Changes';
$form['actions']['cancel'] = array(
'#markup' => '
',
'#weight' => 20,
);
}
}
if($form_id == "draw_node_form"){
$form['actions']['submit']['#value'] = 'Submit';
if($user->uid != 1){
$userdata = db_query("select * from profile where uid ='".$user->uid."'" )->fetchAll();
$userdataid = $userdata[0]->pid;
$businessdata = db_query("select * from field_data_field_business_name where entity_id ='".$userdataid."'" )->fetchAll();
$businesswebsitedata = db_query("select * from field_data_field_website where entity_id ='".$userdataid."'" )->fetchAll();
$form['field_draw_business_name']['und'][0]['value']['#default_value'] = $businessdata[0]->field_business_name_value;
$form['field_draw_website']['und'][0]['value']['#default_value'] = $businesswebsitedata[0]->field_website_url;
}else{
$form['field_draw_business_name']['und'][0]['value']['#default_value'] = '';
$form['field_draw_website']['und'][0]['value']['#default_value'] = '';
}
}
if($form_id == "search_block_form"){
$form['search_block_form'] = array(
'#type' => 'textfield',
'#title' => 'Search',
'#title_display' => 'visible',
'#size' => '15',
'#default_value' => 'Search',
'#attributes' => array(
'onblur' => "if (this.value == '') {this.value = 'Search'}",
'onfocus' => "if (this.value == 'Search') {this.value = ''}"
),
);
}
if($form_id == "search_form"){
$form['basic']['keys']['#title'] = 'Search Keyword :';
}
/* if($form_id == "user_profile_form"){
global $base_path, $base_url,$user;
$citydata = db_query("select * from field_data_field_city where entity_id ='".$user->uid."'" )->fetchAll();
if(isset($citydata) && !empty($citydata)){
$tid = $citydata[0]->field_city_tid;
$termdata = db_query("select * from taxonomy_term_data where tid ='".$tid."'" )->fetchAll();
$form['field_city']['und'][0]['value']['#default_value'] = $termdata[0]->name;
}else{
$form['field_city']['und'][0]['value']['#default_value'] = '';
}
} */
}
/*Custom code for menu alter*/
function custom_module_menu_alter(&$items) {
$items['user/register']['type'] = MENU_CALLBACK;
$items['/user']['type'] = MENU_CALLBACK;
$items['user/password']['type'] = MENU_CALLBACK;
$items['general/register']['type'] = MENU_CALLBACK;
$items['/general']['type'] = MENU_CALLBACK;
$items['general/password']['type'] = MENU_CALLBACK;
$items['business/register']['type'] = MENU_CALLBACK;
$items['/business']['type'] = MENU_CALLBACK;
$items['business/password']['type'] = MENU_CALLBACK;
$items['user/%user/follow']['type'] = MENU_CALLBACK;
$items['user/%user/shortcuts']['type'] = MENU_CALLBACK;
$items['user/%user/socialloginandsocialshare']['type'] = MENU_CALLBACK;
$items['user/%user/devel']['type'] = MENU_CALLBACK;
//$items['node/%node/webform']['type'] = MENU_CALLBACK;
$items['/user']['type'] = MENU_CALLBACK;
}
function custom_module_cron() {
global $user;
// Do something when cron runs.
/*********Simple winning process start here**********/
$start_time = strtotime('12:00 am');
$end_time = strtotime('11:59 pm');
$flag = 0;
$draw_Data = db_query("select * from field_data_field_end_date where field_end_date_value between '".$start_time."' AND ".$end_time."")->fetchAll();
foreach($draw_Data as $draw_Data){
$node_data = node_load($draw_Data->entity_id);
$total_enteries_data = db_query("select * from draw_social_enteries where draw_id='".$node_data->nid."' and flag = '".$flag."' order by rand()")->fetchAll();
$totl_entrs = count($total_enteries_data);
$dra_stts = $node_data->status;
$total_users = $node_data->field_draw_action_users['und'][0]['value'];
if(($totl_entrs>=$total_users) && ($dra_stts == 1)){
$winning_odds = $node_data->field_winning_odds['und'][0]['value'];
//echo "
";print_r($node_data);die;
if(isset($winning_odds)){
$total_users = $node_data->field_draw_action_users['und'][0]['value'];
$winn_odds = explode(':',$winning_odds);
$winn_odd_first = $winn_odds[0];
$winn_odd_second = $winn_odds[1];
$winners_limit = (int)(($total_users*$winn_odd_first)/$winn_odd_second);
}else{
$winners_limit = 1;
}
$i=0;
$winners = db_query("select * from draw_social_enteries where draw_id='".$node_data->nid."' and flag = '".$flag."' limit 0, ".$winners_limit."")->fetchAll();
$winner_count = count($winners);
foreach($winners as $winners){
$user_data = user_load($winners->uid);
$winnername = ucfirst($user_data->name);
if(isset($user_data->name) && !empty($user_data->name)){
$username = $user_data->name;
}else{
$username = '';
}
$userdata = db_query("select * from profile where uid ='".$winners->uid."'" )->fetchAll();
if(isset($userdata[0]->pid) && !empty($userdata[0]->pid)){
$userdataid = $userdata[0]->pid;
}else{
$userdataid = '';
}
//echo "";print_r($user_data);die;
if(isset($userdata[0]->type) && !empty($userdata[0]->type) && $userdata[0]->type == 'main'){
$generaldata = db_query("select * from field_data_field_general_full_name where entity_id ='".$userdataid."'" )->fetchAll();
if(isset($generaldata[0]->field_general_full_name_value) && !empty($generaldata[0]->field_general_full_name_value)){
$winnername = $generaldata[0]->field_general_full_name_value;
}
}
if(isset($userdata[0]->type) && !empty($userdata[0]->type) && $userdata[0]->type == 'business'){
$businessdata = db_query("select * from field_data_field_contact_name where entity_id ='".$userdataid."'" )->fetchAll();
if(isset($businessdata[0]->field_contact_name_value) && !empty($businessdata[0]->field_contact_name_value)){
$winnername = $businessdata[0]->field_contact_name_value;
}
}
if(isset($node_data->field_draw_location['und'][0]['tid'])){
$tid = $node_data->field_draw_location['und'][0]['tid'];
}
$termdata = db_query("select * from taxonomy_term_data where tid ='".$tid."'" )->fetchAll();
if(isset($termdata[0]->name)){
$countryname = $termdata[0]->name;
}else{
$countryname = '';
}
if(isset($node_data->field_prize_type['und']) && $node_data->field_prize_type['und'][0]['tid']=='14' && isset($node_data->field_coupons['und'])){
$coupon = array();
foreach($node_data->field_coupons['und'] as $coupons){
$coupon_data = db_query("select field_coupon_code_value from field_data_field_coupon_code where entity_id ='".$coupons['value']."'" )->fetchAll();
$coupon[] = $coupon_data[0]->field_coupon_code_value;
}
}else{
$coupon = '';
}
$coupon_count = count($coupon);
if($coupon_count == $i){
$i=0;
}else{
$i=$i;
}
if(isset($node_data->field_prize_type['und']) && $node_data->field_prize_type['und'][0]['tid']=='15' && isset($node_data->field_prize_name['und'])){
$prize = $node_data->field_prize_name['und'][0]['value'];
}else{
$prize = '';
}
$insert_query = "INSERT INTO {draw_temp_winners} (uid,draw_id,entry_type,created,draw_created_date,draw_prize,draw_name,winner_name,draw_country,coupon_code) values ('".$winners->uid."','".$winners->draw_id."','".$winners->entry_type."','".$winners->created."','".$node_data->field_start_date['und'][0]['value']."','".$prize."','".$node_data->title."','".$winnername."','".$countryname."','".$coupon[$i]."')";
db_query($insert_query);
// entry in recuring table
$recurring_status_avail = $node_data->field_recurring_draw['und'][0]['value'];
if($recurring_status_avail == 1){
$recur_type = $node_data->field_recurring_time['und'][0]['value'];
if($recur_type == 1){
$type = 'Daily';
}
if($recur_type == 2){
$type = 'Weekly';
}
if($recur_type == 3){
$type = 'Biweekly';
}
if($recur_type == 4){
$type = 'Monthly';
}
$recnid = $node_data->nid;
$recstart_date = $node_data->field_start_date['und'][0]['value'];
$recend_date = $node_data->field_end_date['und'][0]['value'];
$past_data = db_query("select * from recurring_draw_winners where draw_id ='".$recnid."'" )->fetchAll();
$entries = db_query("select * from draw_special_social_enteries where draw_id ='".$recnid."'" )->fetchAll();
$entrycount = count($entries);
if(isset($past_data) && !empty($past_data)){
$index_data = db_query("SELECT MAX(id) as max_id FROM recurring_draw_winners where draw_id ='".$recnid."'" )->fetchCol();
if(isset($index_data[0]) && !empty($index_data[0])){
$maxid = $index_data[0];
$maxid_data = db_query("select * from recurring_draw_winners where id ='".$maxid."'" )->fetchAll();
$start_index = ($maxid_data[0]->end_index+1);
$recstart_date = $maxid_data[0]->end_date;
$recend_date = time();
}
}else{
$start_index = 1;
$recstart_date = $node_data->field_start_date['und'][0]['value'];
$recend_date = $node_data->field_end_date['und'][0]['value'];
}
$recurr_data= db_insert('recurring_draw_winners')
->fields(array(
'draw_id' => $recnid,
'start_index' => $start_index,
'end_index' => $entrycount,
'start_date' => $recstart_date,
'end_date' => $recend_date,
'recurr_type' => $type,
))->execute();
}
$i++;
}
foreach($total_enteries_data as $total_enteries_data){
$entry_updated = db_update('draw_social_enteries') // Table name no longer needs {}
->fields(array(
'flag' => 1,
))
->condition('id', $total_enteries_data->id, '=')
->execute();
}
$winners_temp = db_query("select * from draw_temp_winners where draw_id=".$node_data->nid)->fetchAll();
foreach($winners_temp as $winners_temp){
$drawdata = node_load($winners_temp->draw_id);
$tempnodestatus = $drawdata->status;
$draw_id = $winners_temp->draw_id;
$drawdata = node_load($draw_id);
$drawdatanode = $drawdata->title;
$winneruserprofiledata = profile2_load_by_user($winners_temp->uid);
$win_user_id = $winners_temp->uid;
$winneruser = user_load($win_user_id);
$umail = $winneruser->mail;
$fullname = ucfirst($winneruser->name);
if (array_key_exists("main",$winneruserprofiledata)){
if(isset($winneruserprofiledata['main']->field_general_full_name['und'][0]['value'])){
$userfullname = $winneruserprofiledata['main']->field_general_full_name['und'][0]['value'];
$fullname = ucfirst($userfullname);
}
}
if (array_key_exists("business",$winneruserprofiledata)){
if(isset($winneruserprofiledata['business']->field_contact_name['und'][0]['value'])){
$userfullname = $winneruserprofiledata['business']->field_contact_name['und'][0]['value'];
$fullname = ucfirst($userfullname);
}
}
$mailto = $umail;
$mailfrom = variable_get('site_mail');
$sitename = variable_get('site_name');
$subject = "Congratulations for Your winning at ".ucfirst($sitename)."";
$body = '| Hello '.$fullname.', |
| Â |
| We are very happy to inform you that you are selected as a winner at '.ucfirst($sitename).' in the draw named '.ucfirst($drawdatanode).'. '; if(isset($node_data->field_prize_type['und']) && $node_data->field_prize_type['und'][0]['tid']=='14' && isset($node_data->field_coupons['und'])){ $body .= 'You have won coupon code : "'.$winners_temp->coupon_code.'". '; } if(isset($node_data->field_prize_type['und']) && $node_data->field_prize_type['und'][0]['tid']=='15' && isset($node_data->field_prize_name['und'])){ $body .= 'You have won '.$winners_temp->draw_prize.'. '; } $body .= 'For more information please contact to site administrator. |
| Â |
| Regards |
| '.ucfirst($sitename).' team. |
'.''.'Please check your e-mail to complete the registration process.'.''; //$dasmsg = 'Please check your e-mail to complete the registration process.'; drupal_set_message($dmsg); drupal_goto($url); }else{ $expire = time() + (86400); $cookie_city = setcookie('city',$form_state['values']['city'],$expire); } } function _country_autocomplete($str = 0) { $matches = array(); //vocabulary id $vid = 9; $result = db_select('taxonomy_term_data', 't') -> fields('t', array('tid', 'name')) -> condition('vid', $vid, '=') -> condition('name', $str.'%%', 'LIKE') -> range(0, 10) -> execute(); foreach ($result as $term) { $matches[$term -> name] = check_plain($term -> name); } drupal_json_output($matches); } /*Custom code for sending custom mail */ function custom_module_mail($key, &$message, $params) { $message['subject'] = $params['subject']; $message['body'] = $params['body']; $headers = array( 'MIME-Version' => '1.0', 'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes', 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Drupal', ); foreach ($headers as $key => $value) { $message['headers'][$key] = $value; } } function custom_module_user_insert(&$edit, $account, $category) { /* if(isset($account) && $account->roles[2]=='authenticated user' && (isset($account->roles[4]) && $account->roles[4]=='1')){ $nids = db_query('select spl_dra.entity_id from {field_data_field_special_draw} as spl_dra left join {field_data_field_special_draw_type} as spl_dra_type on spl_dra.entity_id = spl_dra_type.entity_id where spl_dra.field_special_draw_value=1 and spl_dra_type.field_special_draw_type_value=3 order by spl_dra_type.entity_id desc limit 0,1')->fetchAll(); if(isset($nids[0]->entity_id) && !empty($nids[0]->entity_id)){ $node_id = $nids[0]->entity_id; } $node = node_load($node_id); if(isset($node->status) && !empty($node->status)){ $status = $node->status; } if($status == 1){ $user_participate= db_insert('draw_special_social_enteries') ->fields(array( 'uid' => $account->uid, 'draw_id' => $node->nid, 'entry_type' => 'new_user_joining', 'sharing_type' => 'new_user_joining', 'created' => REQUEST_TIME, ))->execute(); drupal_set_message('You have successfully participated in this special draw.'); } }*/ } function custom_module_simple_search_form($form_state) { $form = array(); $form['keyword'] = array( '#type' => 'textfield', '#title' => t('Search By draw Name'), '#required' => FALSE, /* '#default_value' => isset($_SESSION['keyword']) ? $_SESSION['keyword'] : '' , */ ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); if(isset($_SESSION['keyword']) && !empty($_SESSION['keyword'])){ $form['reset'] = array( '#name' => 'reset', '#value' => t('Reset'), '#button_type' => 'reset', '#executes_submit_callback' => FALSE, '#limit_validation_errors' => TRUE, '#class'=>'form-submit', '#theme_wrappers' => array('button'), ); } return $form; } function custom_module_simple_search_form_submit($form, &$form_state) { $keyword = $form['keyword']['#value']; $_SESSION['keyword']=$keyword; } function custom_module_special_search_form($form_state) { $form = array(); $form['keyword'] = array( '#type' => 'textfield', '#title' => t('Search By draw Name'), '#required' => FALSE, '#default_value' => FALSE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); if(isset($_SESSION['special_keyword']) && !empty($_SESSION['special_keyword'])){ $form['reset'] = array( '#name' => 'reset', '#value' => t('Reset'), '#button_type' => 'reset', '#executes_submit_callback' => FALSE, '#limit_validation_errors' => TRUE, '#class'=>'form-submit', '#theme_wrappers' => array('button'), ); } return $form; } function custom_module_special_search_form_submit($form, &$form_state) { $keyword = $form['keyword']['#value']; $_SESSION['special_keyword']=$keyword; } function popup_form_check(){ $email = $_POST['email']; $email_result = db_query("SELECT mail FROM users WHERE mail LIKE '".$email."'")->fetchAll(); $email_check = count($email_result); if($email=='Email Address'){ echo '1';die; }else{ $Syntax='/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/'; if($email_check != 0){ echo '3';die; }else if(preg_match($Syntax,$email)){ echo '0';die; }else{ echo '2';die; } echo '0';die; } } function custom_module_winning_search_form($form_state) { $form = array(); $form['keyword'] = array( '#type' => 'textfield', '#title' => t('Search By draw Name'), '#required' => FALSE, '#default_value' => FALSE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); if(isset($_SESSION['winning_keyword']) && !empty($_SESSION['winning_keyword'])){ $form['reset'] = array( '#name' => 'reset', '#value' => t('Reset'), '#button_type' => 'reset', '#executes_submit_callback' => FALSE, '#limit_validation_errors' => TRUE, '#class'=>'form-submit', '#theme_wrappers' => array('button'), ); } return $form; } function custom_module_winning_search_form_submit($form, &$form_state) { $keyword = $form['keyword']['#value']; $_SESSION['winning_keyword']=$keyword; } function custom_module_participate_search_form($form_state) { $form = array(); $form['keyword'] = array( '#type' => 'textfield', '#title' => t('Search By draw Name'), '#required' => FALSE, '#default_value' => FALSE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Search'), ); if(isset($_SESSION['participate_keyword']) && !empty($_SESSION['participate_keyword'])){ $form['reset'] = array( '#name' => 'reset', '#value' => t('Reset'), '#button_type' => 'reset', '#executes_submit_callback' => FALSE, '#limit_validation_errors' => TRUE, '#class'=>'form-submit', '#theme_wrappers' => array('button'), ); } return $form; } function custom_module_participate_search_form_submit($form, &$form_state) { $keyword = $form['keyword']['#value']; $_SESSION['participate_keyword']=$keyword; } function custom_module_page_alter() { global $user; $arg = arg(); if(isset($arg[1])){ if (($arg[0] == 'user' && is_numeric($arg[1]))) { drupal_set_title('My Account'); } } if($arg[0]=='business_participate_draw'){ drupal_set_title('Entries to draw'); } } function business_participate_draw(){ global $base_url; $output = ''; if(isset($_REQUEST['node']) && !empty($_REQUEST['node'])){ $node_id = $_REQUEST['node']; $query = db_select("draw_social_enteries", "dse"); $query->fields("dse", array("uid","draw_id","entry_type","created")); $query->condition('draw_id', $node_id, '='); $query = $query->extend('TableSort')->extend('PagerDefault')->limit(15); $exist_entry = $query->execute(); $rows = array(); $header = array( array('data' => 'Username'), array('data' => 'Winner'), array('data' => 'Entered via'), array('data' => 'Date Entered'), ); $node_data = node_load($node_id); foreach($exist_entry as $exist_entry){ $user_data = user_load($exist_entry->uid); $winner = ''; $winner_draw = db_query(" SELECT * FROM draw_temp_winners WHERE draw_id= ".$node_id)->fetchAll(); foreach($winner_draw as $winner_draw){ if(isset($winner_draw->winner_name) && !empty($winner_draw->winner_name) && isset($user_data->name) && !empty($user_data->name) && $winner_draw->winner_name== $user_data->name){ $winner = "
";print_r($_POST);die;
$draw_id = $_POST['draw_id'];
$question = $_POST['question'];
$answer = $_POST['answer'];
$_SESSION['draw_id'] = $draw_id;
$_SESSION['question'] = $question;
$_SESSION['answer'] = $answer;
if(isset($_SESSION['answer']) && !empty($_SESSION['answer'])){
echo '1';die;
}else{
echo '0';die;
}
}
/* function custom_module_user_login(&$edit, $account) {
// Check if user never logged in.
if ($account->access == 0) {
// Execute code
if(isset($account) && $account->roles[2]=='authenticated user' && (isset($account->roles[4]) && $account->roles[4]=='general')){
$nids = db_query('select spl_dra.entity_id from {field_data_field_special_draw} as spl_dra left join {field_data_field_special_draw_type} as spl_dra_type on spl_dra.entity_id = spl_dra_type.entity_id where spl_dra.field_special_draw_value=1 and spl_dra_type.field_special_draw_type_value=3 order by spl_dra_type.entity_id desc limit 0,1')->fetchAll();
if(isset($nids[0]->entity_id) && !empty($nids[0]->entity_id)){
$node_id = $nids[0]->entity_id;
}
$node = node_load($node_id);
if(isset($node->status) && !empty($node->status)){
$status = $node->status;
}
if($status == 1){
$user_participate= db_insert('draw_special_social_enteries')
->fields(array(
'uid' => $account->uid,
'draw_id' => $node->nid,
'entry_type' => 'new_user_joining',
'sharing_type' => 'new_user_joining',
'created' => REQUEST_TIME,
))->execute();
drupal_set_message('You have successfully participated in the special draw.');
}
}
}
} */
function custom_module_city_track_form($form, &$form_state) {
global $user;
$form['city'] = array(
'#title' => t('City'),
'#prefix' => 'Please provide Your city and zipcode.Please fill city and zipcode.',
'#suffix' => '',
'#type' => 'textfield',
'#default_value' => '',
'#required' => TRUE,
);
$form['zipcode'] = array(
'#title' => t('Zipcode'),
'#prefix' => '',
'#suffix' => '',
'#type' => 'textfield',
'#default_value' => '',
'#required' => TRUE,
);
$form['html']['element'] = array(
'#type' => 'textfield',
'#title' => '',
'#prefix' => '',
'#suffix' => '',
);
return $form;
}
function custom_module_city_track_form_validate($form, &$form_state){
$city = $form_state ['values']['city'];
$zipcode = $form_state ['values']['zipcode'];
if($city=='')
{
form_set_error('city','Please fill the city field');
}
if($zipcode=='')
{
form_set_error('zipcode','Please fill the zipcode field');
}
}
function custom_module_city_track_form_submit($form, &$form_state){
global $base_url,$user;
}
function custom_module_city_tracking_ajax(){
global $base_url,$user,$conf;
$city = $_POST['city'];
$zipcode = $_POST['zipcode'];
if($city=='' || $zipcode==''){
echo '2';die;
}
$LatLong = custom_module_getLatLong($city,$zipcode);
$lat1 = $LatLong['lat'];
$long1 = $LatLong['lng'];
$lat2 = 34.284453;
$long2 = 122.4167;
$distance = custom_module_distance($lat1, $long1, $lat2, $long2, "M");
if($distance > $conf['custom_module_distance_setting']){
echo '1';die;
}else{
$_SESSION['distance'] = $distance;
echo $distance;die;
}
}
function custom_module_getLatLong($city,$zipcode){
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($city)."+".urlencode($zipcode)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}
function custom_module_distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if($unit == "K")
{
return ($miles * 1.609344);
}
elseif($unit == "N") {
return ($miles * 0.8684);
}
else
{
return $miles;
}
}
function custom_module_node_load($nodes, $types) {
// Decide whether any of $types are relevant to our purposes.
global $user,$conf;
if (arg(0) == 'node' && is_numeric(arg(1))) {
if ($types[0] == 'draw') {
$nid = arg(1);
if(isset($nodes[$nid]->field_draw_latitude['und']) && !empty($nodes[$nid]->field_draw_latitude['und'])){
$node_latitude = $nodes[$nid]->field_draw_latitude['und']['0']['value'];
}else{
$node_latitude = $conf['sf_global_latitude'];
}
if(isset($nodes[$nid]->field_draw_longitude['und']) && !empty($nodes[$nid]->field_draw_longitude['und'])){
$node_longitude = $nodes[$nid]->field_draw_longitude['und']['0']['value'];
}else{
$node_longitude = $conf['sf_global_longitude'];
}
if(isset($nodes[$nid]->field_draw_radius['und']) && !empty($nodes[$nid]->field_draw_radius['und'])){
$node_radius = $nodes[$nid]->field_draw_radius['und']['0']['value'];
}else{
$node_radius = $conf['custom_module_distance_setting'];
}
if(isset($user) && $user->uid > 0){
$user_latitude = $user->data['custom_location']['latitude'];
$user_longitude = $user->data['custom_location']['longitude'];
$distance = custom_module_distance($node_latitude,$node_longitude, $user_latitude, $user_longitude, "M");
$_SESSION['draw_distance'] = $distance;
$user->data['draw_distance'] = $distance;
}
}
}
}
