123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- <?php
- /**
- * Implements hook_init().
- */
- function materio_user_init() {
- drupal_add_js(drupal_get_path('module', 'materio_user').'/js/materio_user.js');
- }
- /**
- * Implements hook_permission().
- */
- function materio_user_permission() {
- $perms = array(
- 'view own user profile' => array(
- 'title' => t('view own user profile'),
- 'description' => t('view own user profile'),
- ),
- 'access to online payment' => array(
- 'title' => t('access to online payment'),
- 'description' => t('Access to online payment'),
- ),
- 'access to user export' => array(
- 'title' => t('access to user export'),
- 'description' => t('Access to user export'),
- ),
- );
- $simplenews_cats = simplenews_category_list();
- // dsm($simplenews_cats);
- foreach ($simplenews_cats as $tid => $name) {
- $perms["subscribe to simplenews category $tid"] = array(
- 'title' => t("subscribe to simplenews category $name"),
- // 'description' => t('Access to online payment'),
- );
- }
- return $perms;
- }
- function materio_user_menu(){
- $items = array();
- $base = array(
- 'type' => MENU_CALLBACK,
- 'file' => 'materio_user.pages.inc',
- );
- $items['materio_user/registerblock'] = $base+array(
- 'title' => 'Materio base user ajax',
- 'page callback' => 'materio_user_registerblock',
- // 'page arguments' => array(),
- 'access callback' => TRUE,
- );
- $items['materio_user/loginandregisterblock'] = $base+array(
- 'title' => 'Materio base user ajax',
- 'page callback' => 'materio_user_loginandregisterblock',
- // 'page arguments' => array(),
- 'access callback' => TRUE,
- );
- $items['materio_user/register/submit'] = $base+array(
- 'title' => 'Materio base user ajax',
- 'page callback' => 'materio_user_register_submit',
- // 'page arguments' => array(),
- 'access callback' => TRUE,
- );
- $items['materio_user/login/submit'] = $base+array(
- 'title' => 'Materio base user ajax',
- 'page callback' => 'materio_user_login_submit',
- // 'page arguments' => array(),
- 'access callback' => TRUE,
- );
- $items['admin/materio_user/export'] = $base+array(
- 'title' => 'Materio base user export',
- 'page callback' => 'materio_user_export',
- // 'page arguments' => array(),
- 'access arguments' => array('access to user export'),
- );
- return $items;
- }
- /**
- * Implements hook_menu_alter().
- */
- function materio_user_menu_alter(&$items) {
- $items['user/%user']['access callback'] = 'user_access';
- $items['user/%user']['access arguments'] = array('view own user profile');
- }
- /**
- * Implements hook_block_info().
- */
- function materio_user_block_info() {
- $blocks['user_createaccount'] = array(
- 'info' => t('Create an account block'),
- 'cache' => DRUPAL_NO_CACHE
- );
- $blocks['user_register'] = array(
- 'info' => t('Register block'),
- 'cache' => DRUPAL_NO_CACHE
- );
- $blocks['old_database_link'] = array(
- 'info' => t('Old data base link'),
- 'cache' => DRUPAL_NO_CACHE
- );
- $blocks['front_link'] = array(
- 'info' => t('Front page link'),
- 'cache' => DRUPAL_NO_CACHE
- );
- return $blocks;
- }
- /**
- * Implements hook_block_view().
- */
- function materio_user_block_view($delta = '') {
- global $user, $language;
- $block = array();
- switch ($delta) {
- case 'user_createaccount':
- if(isset($user->roles[1])){
- $block['subject'] = '';
- if (drupal_is_front_page()) {
- $block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
- $block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
- }else{
- $block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
- $block['content'] .= drupal_render(drupal_get_form('user_register_form'));
- }
- }
- break;
- case 'user_register':
- if(isset($user->roles[1])){
- $block['subject'] = '';//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
- $block['content'] = '<h3>'. t('Login') . '</h3>';
- $ulog_form = drupal_get_form('user_login');
- $block['content'] .= drupal_render($ulog_form);
- if (drupal_is_front_page()) {
- $block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
- $block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
- }else{
- $block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
- $block['content'] .= drupal_render(drupal_get_form('user_register_form'));
- }
- // $block['content'] .= l(t('Pricing'), 'node/11187', array('attributes' => array('class' => 'pricing'),));
- }
- break;
- case 'old_database_link':
- if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
- // dsm($user, 'user');
- $block['subject'] = '';
- $path = 'http://base.materio.com';
- if($language->language == 'fr')
- $path .= '/index_fr.html';
- $block['content'] = l(t('Old database'), $path);
- }
- break;
- case 'front_link':
- $block['subject'] = '';
- $block['content'] = l('<i class="fi-home"></i><span class="text">'.t('home').'</span>', '<front>', array('html'=>true));
- break;
- }
- return $block;
- }
- /**
- * Implements hook_module_implements_alter().
- */
- function materio_user_module_implements_alter(&$implementations, $hook){
- if ($hook == 'form_alter') {
- // It is to ensure that hook_form_alter of this module is called
- // after all other hooks
- $group = $implementations['materio_user'];
- if (isset($group)) {
- unset($implementations['materio_user']);
- // Then add it back, so it will be at the end of hook array
- $implementations['materio_user'] = $group;
- }
- }
- }
- /**
- * Implements hook_form_alter().
- */
- function materio_user_form_alter(&$form, &$form_state, $form_id) {
- // dsm($form_id);
- if( $form_id == "user_register_form" && !user_access('administer users') ){
- // dsm($form);
- $form['account']['pass']['#type'] = 'password';
- $form['account']['pass']['#title'] = t('Password');
- $form['actions']['#type'] = "container";
- $form['actions']['submit']['#value'] = t('Join');
- }
- if($form_id == "user_login" ){
- // dsm($form);
- $form['actions']['#type'] = "container";
- }
- # https://drupal.org/comment/6293810#comment-6293810
- if( $form_id == "webform_client_form_11186" ){
- // dsm($form, '$form');
- materio_user_webform_client_11186_form_alter($form, $form_state, $form_id);
- }
- if( $form_id == "uc_cart_checkout_form" ){
- materio_user_uc_cart_checkout_form_alter($form, $form_state, $form_id);
- }
- // remove newsletters category if user doesn't have access to them
- if( $form_id == "user_profile_form" ){
- // dsm($form, '$form');
- $options = array();
- foreach ($form['subscriptions']['newsletters']['#options'] as $tid => $name) {
- if(user_access("subscribe to simplenews category $tid")){
- $options[$tid] = $name;
- }
- }
- $form['subscriptions']['newsletters']['#options'] = $options;
- }
- // remove newsletters category if user doesn't have access to them
- if ( $form_id == "simplenews_subscriptions_multi_block_form"){
- // dsm($form);
- $options = array();
- foreach ($form['newsletters']['#options'] as $tid => $name) {
- if(user_access("subscribe to simplenews category $tid")){
- $options[$tid] = $name;
- }
- }
- $form['newsletters']['#options'] = $options;
- }
- // if ( $form_id == "user_profile_form"){
- // dsm($form);
- // }
- }
- // function materio_user_user_register_form_submit($form, &$form_state){
- // dsm($form, 'form');
- // dsm($form_state, 'form_state');
- // dsm($_REQUEST, '$_REQUEST');
- // dsm($_GET, '$_GET');
- // unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
- // $form_state['redirect'] = array(
- // 'node/11187',
- // array(
- // 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
- // )
- // );
- // $frontlink = l('continue with basic', '<front>');
- // // drupal_get_messages('status');
- // drupal_set_message(t('Welcome, you just join materiO\'! now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink)));
- // }
- // function materio_user_user_login_form_submit($form, &$form_state){
- // unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
- // $form_state['redirect'] = array(
- // 'node/11187',
- // array(
- // 'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
- // )
- // );
- // }
- /*
- _ _ _ _
- ___ _ _| |_ ___ ___ ___|_|___| |_|_|___ ___
- |_ -| | | . |_ -| _| _| | . | _| | . | |
- |___|___|___|___|___|_| |_| _|_| |_|___|_|_|
- |_|
- //(nid : 11186)
- */
- # prefill the webform form with user profil values
- # add validate and submit functions
- function materio_user_webform_client_11186_form_alter(&$form, &$form_state, $form_id){
- // dsm($form_id, 'form_id');
- // dsm($form, "form");
- // dsm($form_state, "form_state");
- $form['#validate'][] = "materio_user_webform_client_11186_validate";
- $form['#submit'][] = "materio_user_webform_client_11186_submit";
- # dont fill default values if form is been rebuilded (by address module)
- if($form_state["rebuild"])
- return;
- global $user;
- // dsm($user, 'user');
- $member_profile = profile2_load_by_user($user, 'adherent');
- // dsm($member_profile, "member_profile");
- $columnright = &$form['submitted']['column_right'];
- $columnright['me']['firstname']['#default_value'] = $member_profile->field_first_name['und'][0]['value'];
- $columnright['me']['name']['#default_value'] = $member_profile->field_name['und'][0]['value'];
- $columnright['company']['administrative_e_mail']['#default_value'] = $member_profile->field_administrative_email['und'][0]['value'];
- $columnright['company']['s']['company']['#default_value'] = $member_profile->field_organization['und'][0]['value'];
- $columnright['company']['s']['activity_sector']['#default_value'] = $member_profile->field_activity_sector['und'][0]['value'];
- $columnright['company']['d']['vat_number_intra_ce']['#default_value'] = $member_profile->field_vat_number_intra_ce['und'][0]['value'];
- $columnright['company']['d']['website']['#default_value'] = $member_profile->field_user_website['und'][0]['url'];
- if( isset($member_profile->field_adresse['und'][0]) ){
- $address = $member_profile->field_adresse['und'][0];
- $formaddress = &$columnright['company']['location']['#address'];
- $formaddress['country'] = $address['country'];
- $formaddress['thoroughfare'] = $address['thoroughfare'];
- $formaddress['premise'] = $address['premise'];
- $formaddress['postal_code'] = $address['postal_code'];
- $formaddress['locality'] = $address['locality'];
- }
- $columnright['company']['phone_number']['#default_value'] = $member_profile->field_private_phone['und'][0]["number"];
- }
- function materio_user_webform_client_11186_validate($form, &$form_state){
- // dsm($form, 'form');
- // dsm($form_state, 'form_state');
- # test if collaborators are filled in case of membership option is 3
- $values = $form_state['values']['submitted'];
- if ($values['column_left']['membership_options'] == 3) {
- foreach ($values['column_right']['collaborators'] as $collab_key => $coll) {
- foreach ($coll as $field_key => $field_value) {
- $form_field = $form['submitted']['column_right']['collaborators'][$collab_key][$field_key];
- if($field_value == ''){
- $collab_label = $form['submitted']['column_right']['collaborators'][$collab_key]['#title'];
- $field_label = $form_field['#title'];
- $human_field_name = $collab_label. " : " .$field_label;
- form_error($form_field, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
- }
- # validate the emails
- # see https://api.drupal.org/api/drupal/modules!user!user.module/function/user_account_form_validate/7
- if($form_field['#type'] == 'webform_email'){
- // dsm($form_field, 'form_field');
- $u = db_select('users')
- ->fields('users', array('uid'))
- // ->condition('uid', $account->uid, '<>')
- ->condition('mail', db_like($field_value), 'LIKE')
- ->range(0, 1)
- ->execute()->fetchField();
- if ((bool) $u ) {
- form_error($form_field, t('The e-mail address %email is already taken.', array('%email' => $field_value)));
- }
- }
- }
- }
- }
- }
- #retreive from the web form info, record them into user profil
- function materio_user_webform_client_11186_submit(&$form, &$form_state){
- // dsm($form, 'form');
- // dsm($form_state, 'form_state');
- $node = &$form['#node'];
- // dsm($node, '$node');
- // $values = $form_state['values']['submitted_tree'];
- $values = $form_state['input']['submitted']; // code updated with webform module
- // dsm($values, '$values');
- $flat_values = array();
- materio_user_flatenize_form_values($values, $flat_values);
- // dsm($flat_values, 'flat_values');
- # records values in member profile
- materio_user_record_member_profile($flat_values);
- # redirect membership form to checkout with good option selected
- if(user_access('access to online payment')){
- // forcer le vidage du panier
- uc_cart_empty(uc_cart_get_id());
- // fill the cart and redirect to checkout
- // cf : http://www.ubercart.org/node/1427
- $subscription_level = $flat_values['membership_options'];
- $form_state['redirect'] = array(
- 'cart/add/e-p11849_q1_a1o'.$subscription_level.'-membershipform',
- array(
- 'query' => array(
- 'destination' => 'cart/checkout',
- ),
- // 'fragment' => 'baz',
- ),
- );
- // TODO effacer le message de soumissions du formulaire -> pas moyen de overwriter le message de webform depuis ici, dommage
- // $node->webform['confirmation'] = '';
- # create collaborators users account incase of membership option is 3
- # NO wait for checkout for that
- //materio_user_create_collaborators_users();
- // enregistrer le type d'adonnement chez les user
- }
- }
- function materio_user_record_member_profile($values) {
- // dsm($values, 'values');
- global $user;
- // dsm($user, 'user');
- $member_profile = profile2_load_by_user($user, 'adherent');
- if (empty($member_profile)) {
- $member_profile = profile2_create(array("type" => 'adherent', "uid" => $user->uid));
- }
- // dsm($member_profile, '$member_profile');
- // transform location values into field_address compatible
- $values['location'] = array(
- 'country' => $values['country'],
- 'thoroughfare' => $values['thoroughfare'],
- 'premise' => $values['premise'],
- 'postal_code' => $values['postal_code'],
- 'locality' => $values['locality'],
- 'administrative_area' => $values['administrative_area'],
- );
- $correspondances = array(
- "firstname"=>"field_first_name",
- "name"=>"field_name",
- "company"=>"field_organization",
- "activity_sector"=>"field_activity_sector",
- "website"=>"field_user_website",
- "administrative_e_mail"=>"field_administrative_email",
- "vat_number_intra_ce"=>"field_vat_number_intra_ce",
- "location"=>"field_adresse",
- "phone_number"=>"field_private_phone",
- );
- foreach ($correspondances as $form_field => $field_name) {
- switch($form_field){
- case "website":
- $value = array("url" => $values[$form_field]);
- break;
- case "administrative_e_mail":
- $value = array("email" => $values[$form_field]);
- break;
- case "location":
- // $value = unserialize($values[$form_field]);
- $value = $values[$form_field];
- // dsm($value, 'location value');
- break;
- case "phone_number":
- $pn = $values[$form_field];
- if(module_exists('cck_phone')){
- preg_match('/^(\+[0-9]+)\s([0-9]+)$/', $pn, $matches);
- // dsm($matches, "matches");
- $ccs = cck_phone_countrycodes();
- foreach ($ccs as $c => $vs) {
- if($vs['code'] == $matches[1]){
- $pn = "0".$matches[2];
- $cc = $c;
- break;
- }
- }
- $value = array(
- "number"=>$pn,
- "country_codes"=>$cc,
- "extension"=>"",
- );
- }else{
- $value = array(
- "number"=>$pn,
- "country_codes"=>"",
- "extension"=>"",
- );
- }
- break;
- default:
- $value = array("value" => $values[$form_field]);
- break;
- }
- $member_profile->{$field_name} = array(
- "und"=>array( 0 => $value,)
- );
- }
- // save the profile2 new contents
- profile2_save($member_profile);
- // Indicate success to the user.
- // drupal_set_message(t('Your member profile has been created.'));
- }
- function materio_user_flatenize_form_values($ar_src, &$flat_ar){
- foreach ($ar_src as $key => $value) {
- if(is_array($value)){
- materio_user_flatenize_form_values($value, $flat_ar);
- }else{
- $flat_ar[$key] = $value;
- }
- }
- }
- function materio_user_uc_cart_checkout_start($order) {
- // dsm($order);
- $user = user_load($order->uid);
- // dsm($user, 'user');
- $member_profile = profile2_load_by_user($user, 'adherent');
- // dsm($member_profile, "member_profile");
- $location = (object) $member_profile->field_adresse['und'][0];
- # convert country code to UC country ID (pfff)
- $countries = db_query("SELECT country_id, country_iso_code_2 FROM {uc_countries} WHERE version > :version", array(':version' => 0))->fetchAllKeyed();
- foreach ($countries as $country_id => $country_code) {
- if($location->country == $country_code){
- $location->uc_country_id = $country_id;
- break;
- }
- }
- $correspondances = array(
- "billing_country" => $location->uc_country_id,
- );
- // dsm($correspondances);
- foreach ($correspondances as $order_field => $value) {
- $order->{$order_field} = $value;
- }
- }
- /**
- * Implements hook_form_alter().
- */
- function materio_user_uc_cart_checkout_form_alter(&$form, &$form_state, $form_id) {
- // dsm($form_id, 'form_id');
- // dsm($form, "form");
- // dsm($form_state, "form_state");
- // Load an order from the session, if available.
- if (isset($_SESSION['cart_order'])) {
- $order = uc_order_load($_SESSION['cart_order']);
- if ($order) {
- // dsm($order, 'order');
- global $user;
- // dsm($user, 'user');
- $member_profile = profile2_load_by_user($user, 'adherent');
- // dsm($member_profile, "member_profile");
- $location = (object) $member_profile->field_adresse['und'][0];
- # convert country code to UC country ID (pfff)
- $countries = db_query("SELECT country_id, country_iso_code_2 FROM {uc_countries} WHERE version > :version", array(':version' => 0))->fetchAllKeyed();
- foreach ($countries as $country_id => $country_code) {
- if($location->country == $country_code){
- $location->uc_country_id = $country_id;
- break;
- }
- }
- // dsm($location, "location");
- // $phone_field = field_get_items('profile2', $member_profile, 'field_private_phone');
- // $phone = $phone_field ? field_view_value('profile2', $member_profile, 'field_private_phone', $phone_field[0]) : "";
- // dsm($phone, 'phone');
- $phone_field = $member_profile->field_private_phone['und'][0];
- if(module_exists('cck_phone')){
- $cc = cck_phone_countrycodes($phone_field['country_codes']);
- $phone = $cc['code'] .' '. $phone_field['number'];
- }
- $correspondances = array(
- "billing_first_name" => $member_profile->field_first_name['und'][0]['value'],
- "billing_last_name" => $member_profile->field_name['und'][0]['value'],
- "billing_phone" => $phone,
- "billing_company" => $member_profile->field_organization['und'][0]['value'],
- "billing_street1" => $location->thoroughfare,
- "billing_street2" => $location->premise,
- "billing_city" => $location->locality,
- "billing_zone" => $location->adminstrative_area,
- "billing_postal_code" => $location->postal_code,
- "billing_country" => $location->uc_country_id,
- );
- // dsm($correspondances);
- foreach ($correspondances as $order_field => $value) {
- $order->{$order_field} = $value;
- }
- $form['panes']['billing']['address']['#default_value'] = $order;
- }
- }
- }
- /**
- * Implements hook_uc_order();
- */
- function materio_user_order($op, $order, $arg2) {
- // dsm($op, "matyerio_user_uc_order | op");
- // dsm($order, "order");
- // dsm($arg2, "arg2");
- switch ($op) {
- case 'save':
- // Do something to save payment info!
- break;
- }
- }
- # not used yet
- function materio_user_create_collaborators_users(){
- /*
- if ($values['membership_options'] == 3) {
- $i = 1;
- foreach ($values['collaborators'] as $collab_key => $coll) {
- // foreach ($coll as $field_key => $field_value) {
- // if($field_value == ''){
- // $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
- // $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
- // // dsm($field_name, 'field_name');
- // form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
- // }
- // }
- $userinfo = array(
- 'mail' => $coll['e_mail_collab_'.$i],
- 'name' => user_password(),
- 'pass' => user_password(), // Generate password
- // 'init' => $data['components']['username']['value'],
- 'status' => 0,
- 'access' => REQUEST_TIME,
- 'memo' => 'from webform',
- );
- $account = drupal_anonymous_user();
- $account->is_new = TRUE;
- user_save($account, $userinfo);
- // module_invoke_all('user_insert', $edit, $account);
- $i++;
- }
- }
- */
- }
- /**
- * Implements hook_help().
- */
- function materio_user_help($path, $arg) {
- // dsm($path, 'path');
- // dsm($arg, 'arg');
- switch ($path) {
- case 'node/%':
- if($arg[1] == 11187 ){
- global $user;
- // dsm($user, 'user');
- if(isset($user->roles[1])){ // anonyme
- $message = t('Please create first a free account and join materio or log in with your existing account,<br />then we\'ll provide you our membership form.', array());
- $content = '<p>' . $message . '</p>';
- return $content;
- }else if(isset($user->roles[2])){ // authentificated user (not utilisateur)
- $content = '<h2>' . t('Welcome, you just joined materiO\' !') . '</h2>';
- $frontlink = l(t('continue with basic'), '<front>');
- $message = t('Now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink));
- $content .= '<p>' . $message . '</p>';
- return $content;
- }
- }
- }
- }
- /**
- * Implements hook_block_view_alter().
- */
- function materio_user_block_view_alter(&$data, $block) {
- if( $block->module == "user" && $block->delta == 'login' && isset($data['subject']) ){
- // dsm($block, 'block');
- // dsm($data, 'data');
- $data['subject'] = '<i class="icon-user"></i>' . '<span class="login">' . $data['subject'] . '</span>';
- }
- }
- /**
- * Define constants
- */
- define('MATERIO_USER_CONFIRMED_USER_ROLE', 'Utilisateur'); // add role name here
- /**
- * Implement hook_user
- */
- function _materio_user_user_update(&$edit, $account, $category){
- // dsm($edit, 'edit');
- // dsm($account, 'account');
- // dsm($category, 'category');
- // This is only fired when a user confirms their email address, logintoboggan style
- if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {
- $confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);
- $roles = $account->roles + array($confirmed_rid => MATERIO_USER_CONFIRMED_USER_ROLE);
- // we have to do this to stop an infinite loop, and also to allow lower weighted modules to possibly do something here
- $user = $account;
- unset($user->logintoboggan_email_validated);
- user_save($user, array('roles' => $roles));
- drupal_go_to('user/'.$user->uid.'/edit');
- }
- }
- /**
- * Returns a role ID based on role name
- *
- * @param $name
- * name of role to return
- * @return
- * (int) Role ID
- */
- function materio_user_get_role_by_name($name) {
- return array_search($name, user_roles());
- }
- /**
- * Catch rejected email by mandrill, and remove them from simplenews lists
- *
- * @param array $result
- * Associative array containing the send result, including the status.
- */
- function materio_user_mandrill_mailsend_result($result) {
- $status = $result['status'];
- if ( in_array($status, array('rejected', 'invalid', 'error')) ) {
- $email = $result['email'];
- // remove email from pool
- module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
- simplenews_delete_spool(array('mail'=>$email));
- watchdog("materio_user", "@mail rejected by mandrill, removed from simplenews spool", array("@mail"=>$email));
- if ( in_array($status, array('invalid')) ) {
- // unsubscribe user if mail does not exists
- $subscriber = simplenews_subscriber_load_by_mail($email);
- if ($subscriber) {
- simplenews_subscriber_delete($subscriber);
- }
- // disable user
- $user = user_load_by_mail($email);
- // $user->status = 0;
- user_save($user, array('status'=>0));
- watchdog("materio_user", "@mail rejected as invalid by mandrill, removed from simplenews subscribers liste and user blocked", array("@mail"=>$email), WATCHDOG_WARNING, "/user/".$user->uid."/edit");
- }
- }
- }
|