site = $site; if (!is_array($conf)) { $conf = array(); } $this->_configuration = $conf; if (!empty($ism)) { // Configuration mode $this->ism = $ism; require_once('modules/'.$this->_parent_module.'/common.inc.php'); eval('$this->_module = new '.$this->_parent_classname.'($this->ism);'); } return true; } // Run function... constrained by a width public function run($width) { if (!empty($this->_configuration['categories'])) { $sm = $this->site->smarty(); $s = 0; $err = array(); if (!empty($_REQUEST['s'])) { $s = $_REQUEST['s']; } if (!empty($_REQUEST['frm'])) { $frm = $_REQUEST['frm']; } if (empty($frm['country'])) { $frm['country'] = 1; } $itvtext = $this->site->frm('itvtext'); $itvimage = $this->site->frm('itvimage'); $itvvalid = 1; // Cell providers $sms = new SMS(); $sm->assign('cellproviders', $sms->cellproviders); // States $states = array(); $state_query = $this->site->sdb_query("SELECT * FROM ISM3.db_states ORDER BY country_id, name"); while ($state = $this->site->sdb_fetch_array($state_query)) { array_push($states, $state); } // Countries $countries = array(); $country_query = $this->site->sdb_query("SELECT * FROM ISM3.db_countries ORDER BY name"); while ($country = $this->site->sdb_fetch_array($country_query)) { array_push($countries, $country); } // Load the newsletter types $newsletters = array(); foreach ($this->_configuration as $key => $conf) { if (preg_match("/^emcats_([0-9]+)$/", $key, $matches) && is_array($conf)) { $newsletters[$matches[1]] = 0; } } if (sizeof($newsletters) > 0) { $newsletter_query = $this->site->sdb_query("SELECT id, name FROM `emailer1_compose_categories` WHERE ". " id IN (".join(', ', array_keys($newsletters)).") "); while ($newsletter = $this->site->sdb_fetch_array($newsletter_query)) { $newsletters[$newsletter['id']] = array('name' => htmlspecialchars($newsletter['name'])); } $sm->assign('newsletters', $newsletters); $sm->assign('enable_multiple', 1); } // Load custom fields $cf = new CustomFields($this->site); $custom = $cf->get('emailer1-members', $s); // Load configuration data $enable = array(); foreach (array('enable_name', 'enable_address', 'enable_dob', 'enable_gender', 'enable_cell', 'enable_cellprovider', 'enable_email', 'enable_password', 'enable_billing', 'enable_shipping', 'enable_emailerstatus', 'enable_homephone', 'enable_workphone', 'enable_retypeemail') as $conf) { $enable[$conf] = (empty($this->_configuration[$conf])) ? '' : $this->_configuration[$conf]; $sm->assign($conf, $enable[$conf]); } switch ($s) { case 2: // Modify existing subscription $group_subscribe = array(); // Place user in these groups $group_total = $this->_configuration['categories']; // Possible groups to be placed in foreach ($this->_configuration as $key => $val) { if (preg_match("/^emcats_([0-9]+)$/", $key, $matches)) { $group_total = array_merge($group_total, $val); } } if (isset($frm['newsletters'])) { foreach ($frm['newsletters'] as $newsletter_id => $null) { if (isset($this->_configuration['emcats_'.$newsletter_id])) { foreach ($this->_configuration['emcats_'.$newsletter_id] as $gid) { if (!in_array($gid, $this->_configuration['categories'])) { array_push($this->_configuration['categories'], $gid); } } } } } // Get user ID $email = addslashes($frm['email']); $user_query = $this->site->sdb_query("SELECT id FROM `std_core_siteusers` WHERE email='$email' "); $user = $this->site->sdb_fetch_array($user_query); if (isset($user['id'])) { // Flush out possible groups $this->site->sdb_query("DELETE FROM `std_core_siteusergroups` WHERE ". " siteuser_id='$user[id]' AND ". " group_id IN ('".join("', '", $group_total)."') "); // Add user to the member groups inside $this->_configuration['categories'] if (!empty($this->_configuration['categories'])) { foreach ($this->_configuration['categories'] as $group_id) { $this->site->sdb_query("INSERT INTO `std_core_siteusergroups` (siteuser_id, group_id) ". " VALUES ('$user[id]', '$group_id')"); } } // Set flags $is_noemail = (!empty($frm['is_noemail'])) ? 1 : 0; $this->site->sdb_query("UPDATE `std_core_siteusers` SET is_noemail='$is_noemail' ". " WHERE id='$user[id]'"); echo '

Email subscription options saved.

'; } else { echo '

Invalid email address.

'; } break; case 1: // Verify & subscribe $fields = array(); // Check validation if (!empty($this->_configuration['itv'])) { $itv = new ImageTextValidation(); $itvimage = str_replace($itv->path_http, '', $itvimage); if (!$itv->validate($itvtext, $itvimage)) { $err['itv'] = 'Invalid image text verification response'; } } // Full name check if ($enable['enable_name'] == 1 && empty($frm['name_first'])) { $err['name_first'] = 'Must not be empty.'; } elseif (!empty($frm['name_first'])) { array_push($fields, "name_first='".addslashes($frm['name_first'])."'"); } if (!empty($frm['name_mi'])) { array_push($fields, "name_mi='".addslashes($frm['name_mi'])."'"); } if ($enable['enable_name'] == 1 && empty($frm['name_last'])) { $err['name_last'] = 'Must not be empty.'; } elseif (!empty($frm['name_last'])) { array_push($fields, "name_last='".addslashes($frm['name_last'])."'"); } // Email check if (empty($frm['email']) || !preg_match("/^[A-z0-9_\-\.]+@[A-z0-9\-]+\.[A-z0-9\-\.]+$/i", $frm['email'])) { $err['email'] = 'Invalid email address.'; } else { array_push($fields, "email='".addslashes($frm['email'])."'"); } // Check for duplicate email addresses /*$email_query = $this->site->sdb_query("SELECT count(*) AS 'count' FROM ". " `std_core_siteusers` WHERE username='0' AND email='$frm[email]'"); $emailc = $this->site->sdb_fetch_array($email_query); if ($emailc['count'] > 0) { $err['email'] = 'This e-mail address is associated with an existing account.'; }*/ // Email retype check if ($enable['enable_retypeemail']) { if (empty($frm['email2']) || $frm['email'] != $frm['email2']) { $err['email2'] = 'Email addresses do not match.'; } } // Home number check if ($enable['enable_homephone']) { if ($enable['enable_homephone'] == 1 && empty($frm['number_home'])) { $err['number_home'] = 'Please include your home phone number.'; } else { array_push($fields, "phone_home='".addslashes($frm['number_home'])."'"); } } // Work number check if ($enable['enable_workphone']) { if ($enable['enable_workphone'] == 1 && empty($frm['number_work'])) { $err['number_work'] = 'Please include your work phone number.'; } else { array_push($fields, "phone_work='".addslashes($frm['number_work'])."'"); } } // Cell check if ($enable['enable_cell']) { if ($enable['enable_cell'] == 1 && empty($frm['number_cell'])) { $err['number_cell'] = 'Please include your cell phone number.'; } else { array_push($fields, "phone_cell='".addslashes($frm['number_cell'])."'"); } } // Cell provider check if ($enable['enable_cellprovider']) { if ($enable['enable_cellprovider'] == 1 && empty($frm['number_cellprovider'])) { $err['number_cellprovider'] = 'Please include your cell phone provider.'; } else { array_push($fields, "phone_cellprovider='".addslashes($frm['number_cellprovider'])."'"); } } // Address check if ($enable['enable_address'] == 1 && empty($frm['address'])) { $err['address'] = 'Must not be empty.'; } elseif (!empty($frm['address'])) { array_push($fields, "address='".addslashes($frm['address'])."'"); } if ($enable['enable_address'] == 1 && empty($frm['city'])) { $err['city'] = 'Must not be empty.'; } elseif (!empty($frm['city'])) { array_push($fields, "city='".addslashes($frm['city'])."'"); } if ($enable['enable_address'] == 1 && empty($frm['state'])) { $err['state'] = 'Please select a state.'; } elseif (!empty($frm['state'])) { array_push($fields, "state='".addslashes($frm['state'])."'"); } if ($enable['enable_address'] == 1 && empty($frm['zip'])) { $err['zip'] = 'Must not be empty.'; } elseif (!empty($frm['zip'])) { array_push($fields, "zip='".addslashes($frm['zip'])."'"); } if ($enable['enable_address'] == 1 && empty($frm['country'])) { $err['country'] = 'Must not be empty.'; } elseif (!empty($frm['country'])) { array_push($fields, "country='".addslashes($frm['country'])."'"); } // Date of birth check if (!empty($frm['dob_Year']) && !empty($frm['dob_Month']) && !empty($frm['dob_Day'])) { $frm['dob'] = $frm['dob_Year'].'-'.$frm['dob_Month'].'-'.$frm['dob_Day']; array_push($fields, "dob='".addslashes($frm['dob'])."'"); } // Gender check if (!empty($frm['gender'])) { array_push($fields, "gender='".addslashes($frm['gender'])."'"); } elseif ($enable['enable_gender'] == 1) { $err['gender'] = 'Please specify your gender.'; } if (sizeof($err) > 0) { $s = 0; echo '

Please correct the highlighted fields below:

'; } else { foreach ($frm as $var => $val) { if (!is_array($val)) { $frm[$var] = addslashes($val); } } // Get user id $this->site->sdb_query("INSERT INTO `std_core_siteusers` (id) VALUES ('')"); $user_id = $this->site->sdb_insert_id(); /** * Add user to the selected newsletter groups */ if (isset($frm['newsletters'])) { foreach ($frm['newsletters'] as $newsletter_id => $null) { if (isset($this->_configuration['emcats_'.$newsletter_id])) { foreach ($this->_configuration['emcats_'.$newsletter_id] as $gid) { if (!in_array($gid, $this->_configuration['categories'])) { array_push($this->_configuration['categories'], $gid); } } } } } // Add user to the member groups inside $this->_configuration['categories'] if (!empty($this->_configuration['categories'])) { foreach ($this->_configuration['categories'] as $group_id) { $this->site->sdb_query("INSERT INTO `std_core_siteusergroups` (siteuser_id, group_id) ". " VALUES ('$user_id', '$group_id')"); } } // Update user record with form data $this->site->sdb_query('UPDATE `std_core_siteusers` SET date_created=NOW(), '.join(', ', $fields)." WHERE id='$user_id'"); // Insert custom fields $cf->set('emailer1-members', $user_id, $custom); // Send confirmation e-mail to registrant $rwtext_query = $this->site->sdb_query(" SELECT * FROM `std_core_config` WHERE id='emailer1-config_nwtext' "); $rwtext = $this->site->sdb_fetch_array($rwtext_query); if (!empty($rwtext['value'])) { $this->site->sendemail( $frm['email'], 'Welcome to '.$this->site->config['site_name'].'!', $rwtext['value'] ); } // Send notification e-mail to client $ntext_query = $this->site->sdb_query("SELECT * FROM `std_core_config` WHERE id='emailer1-config_registernotify' "); $ntext = $this->site->sdb_fetch_array($ntext_query); if (!empty($ntext['value'])) { if ( $this->site->frm('address') ) { $state_q = $this->site->sdb_query("SELECT `name` FROM ISM3.db_states where id=".$this->site->frm('state')." "); $state_name = $this->site->sdb_fetch_array($state_q); $country_q = $this->site->sdb_query("SELECT `name` FROM ISM3.db_countries where id=".$this->site->frm('country')." "); $country_name = $this->site->sdb_fetch_array($country_q); } $emt = '

New site member!

'. '

'.$this->site->frm('username').'
'. ''.$this->site->frm('email').'

'. '

Address »

'. $this->site->frm('name_last').', '.$this->site->frm('name_first').$this->site->frm('name_mi').'
'. ( $this->site->frm('address') ? $this->site->frm('address').'
'. $this->site->frm('city').', '.$state_name[0].' '.$this->site->frm('zip').'
'. $country_name[0].'
' : ''). '

Phone Numbers »

'. 'Home Phone: '.$this->site->frm('number_home').'
'. 'Work Phone: '.$this->site->frm('number_work').'
'. 'Cell Phone: '.$this->site->frm('number_cell').'
'. 'Cell Provider: '.$this->site->frm('number_cellprovider').'
'. '

General »

'. 'DOB: '.$this->site->frm('dob_Month').'/'.$this->site->frm('dob_Day').'/'.$this->site->frm('dob_Year').'
'. 'Gender: '.$this->site->frm('gender').'
'. '

Custom Fields »

'; if (!empty($custom)) { foreach ($custom as $key => $value) { $emt .= $value['name'].': '.$value['html'].'
'; } } $emt = $this->site->buildemail('register', 'New Registration', $emt); $this->site->sendemail($ntext['value'], 'New Registration', $emt); //$this->site->sendemail('kfir@infinityprosports.com', 'New Registration', $emt); } // Redirect if necessary if (!empty($this->_configuration['rdpage'])) { $this->site->redirect($this->site->path_http.$this->site->pages[$this->_configuration['rdpage']]['path']); } else { $sm->assign('noform', 1); echo '

Thanks for registering!

'; } } break; } // Generate image link if the user has not validated himself yet if (!empty($this->_configuration['itv'])) { $itv = new ImageTextValidation(); if (!($itvtext && $itvvalid) || isset($err['itv'])) { $itvimage = $itv->generate(); $itvtext = ''; } else { $itvimage = $itv->path_http.$itvimage; } $sm->assign('itvimage', $itvimage); $sm->assign('itvtext', $itvtext); } $sm->assign('config', $this->_configuration); $sm->assign('custom', $custom); $sm->assign('countries', $countries); $sm->assign('states', $states); $sm->assign('frm', $frm); $sm->assign('err', $err); $sm->display($this->templates[0]); } else { $this->site->error('Please select member categories to place new registrations in.'); } } /** * Get all available configuration options for this module. See the ISMHTMLFormTable class * for information about the datatype returned. */ public function getconfformtablearray() { require_once('./modules/emailer1-compose/common.inc.php'); $emc = new ISMModuleEmailer1Compose($this->ism); $emcats = $emc->getcategorieshash(); $sb = new ISMModuleStdSiteBuilder($this->ism); $rows = array(); array_push($rows, array( array('type' => 'field', 'value' => 'Redirect successful registrations to this page'), array('type' => 'select', 'name' => 'plugin_rdpage', 'size' => 3, 'selected' => ((empty($this->_configuration['rdpage'])) ? 0 : $this->_configuration['rdpage']), 'values' => array('' => '') + $sb->getpageshash()), )); array_push($rows, array( array('type' => 'section', 'value' => 'Newsletters & Group Assignment'), )); array_push($rows, array( array('type' => 'field', 'colspan' => 2, 'value' => 'By default, visitors to this page will not be given the '. 'option to select which newsletters to subscribe to. If this site has multiple newsletters, '. 'select the appropriate groups associated with each subscription below.'), )); array_push($rows, array( array('type' => 'field', 'value' => 'Add all sign-ups to these groups:'), array('type' => 'checkboxarray', 'values' => $this->_module->getmembergroupshash(), 'selected_ar' => ((!empty($this->_configuration['categories'])) ? $this->_configuration['categories'] : ''), 'name' => 'plugin_categories') )); foreach ($emcats as $category_id => $name) { array_push($rows, array( array('type' => 'field', 'value' => ''.$name.''), array('type' => 'checkboxarray', 'values' => $this->_module->getmembergroupshash(), 'selected_ar' => ((!empty($this->_configuration['emcats_'.$category_id])) ? $this->_configuration['emcats_'.$category_id] : ''), 'name' => 'plugin_emcats_'.$category_id) )); } array_push($rows, array( array('type' => 'section', 'value' => 'Field Configuration'), )); array_push($rows, array( array('type' => 'field', 'value' => 'Force user to retype email address?'), array('type' => 'select', 'name' => 'plugin_enable_retypeemail', 'values' => array('' => 'No', '1' => 'Yes'), 'selected' => ((!empty($this->_configuration['enable_retypeemail'])) ? $this->_configuration['enable_retypeemail'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Name'), array('type' => 'select', 'name' => 'plugin_enable_name', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_name'])) ? $this->_configuration['enable_name'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Address'), array('type' => 'select', 'name' => 'plugin_enable_address', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_address'])) ? $this->_configuration['enable_address'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Date of Birth'), array('type' => 'select', 'name' => 'plugin_enable_dob', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_dob'])) ? $this->_configuration['enable_dob'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Gender'), array('type' => 'select', 'name' => 'plugin_enable_gender', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_gender'])) ? $this->_configuration['enable_gender'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Home Phone'), array('type' => 'select', 'name' => 'plugin_enable_homephone', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_homephone'])) ? $this->_configuration['enable_homephone'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Work Phone'), array('type' => 'select', 'name' => 'plugin_enable_workphone', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_workphone'])) ? $this->_configuration['enable_workphone'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Cell Phone'), array('type' => 'select', 'name' => 'plugin_enable_cell', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_cell'])) ? $this->_configuration['enable_cell'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Cell Phone Provider
For SMS routing'), array('type' => 'select', 'name' => 'plugin_enable_cellprovider', 'values' => array('' => 'Hidden', '1' => 'Required', '2' => 'Optional'), 'selected' => ((!empty($this->_configuration['enable_cellprovider'])) ? $this->_configuration['enable_cellprovider'] : '')) )); array_push($rows, array( array('type' => 'field', 'value' => 'Enable image text validation?'), array('type' => 'boolean', 'name' => 'plugin_itv', 'value' => ((!empty($this->_configuration['itv'])) ? $this->_configuration['itv'] : '0')) )); return $rows; } }