Advertisement:

Author Topic: Only one ad for each user  (Read 2376 times)

Aficionado

  • Guest
Re: Only one ad for each user
« Reply #15 on: December 20, 2017, 02:01:35 pm »
I already posted the plugin's name that COULD help you. Try it.

Moredit is the name again.


marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #16 on: December 20, 2017, 02:16:55 pm »

How would anyone have a more precise instruction how and what to change in emails.php to get the following status:

email_user_validation goes to admin
email_user_registration goes to user after the admin validates the user.

I would be grateful
Hi.
I wasn't sure if the email registration goes to the user if the admin validates the user, I should implement that in my osclass also.
EDIT ( please see the solution below 2 posts down without core mods)

So for your last request

emails.php

Code: [Select]
    function fn_email_user_validation($user, $input) {
        $mPages = new Page();
        $locale = osc_current_user_locale();
        $aPage = $mPages->findByInternalName('email_user_validation');

        if(isset($aPage['locale'][$locale]['s_title'])) {
            $content = $aPage['locale'][$locale];
        } else {
            $content = current($aPage['locale']);
        }

        if (!is_null($content)) {
            $validation_url = osc_user_activate_url($user['pk_i_id'], $input['s_secret']);
            $words   = array();
            $words[] = array(
                '{USER_NAME}',
                '{USER_EMAIL}',
                '{VALIDATION_LINK}',
                '{VALIDATION_URL}'
            );
            $words[] = array(
                $user['s_name'],
                $user['s_email'],
                '<a href="' . $validation_url . '" >' . $validation_url . '</a>',
                $validation_url
            );
            $title = osc_apply_filter('email_user_validation_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_user_validation_title', $content['s_title'], $user, $input)), $words), $user, $input);
            $body = osc_apply_filter('email_user_validation_description_after', osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_user_validation_description', $content['s_text'], $user, $input)), $words), $user, $input);

            $emailParams = array(
                'subject'  => $title,
                'from'     => _osc_from_email_aux(),
                'to'       => $user['s_email'],
                'to_name'  => $user['s_name'],
                'body'     => $body,
                'alt_body' => $body
            );
            osc_sendMail($emailParams);
        }
    }
    osc_add_hook('hook_email_user_validation', 'fn_email_user_validation');

Replace with

Code: [Select]
    function fn_email_user_validation($user, $input) {
        $mPages = new Page();
        $locale = osc_current_user_locale();
        $aPage = $mPages->findByInternalName('email_user_validation');

        if(isset($aPage['locale'][$locale]['s_title'])) {
            $content = $aPage['locale'][$locale];
        } else {
            $content = current($aPage['locale']);
        }

        if (!is_null($content)) {
            $validation_url = osc_user_activate_url($user['pk_i_id'], $input['s_secret']);
            $words   = array();
            $words[] = array(
                '{USER_NAME}',
                '{USER_EMAIL}',
                '{VALIDATION_LINK}',
                '{VALIDATION_URL}'
            );
            $words[] = array(
                $user['s_name'],
                $user['s_email'],
                '<a href="' . $validation_url . '" >' . $validation_url . '</a>',
                $validation_url
            );
            $title = osc_apply_filter('email_user_validation_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_user_validation_title', $content['s_title'], $user, $input)), $words), $user, $input);
            $body = osc_apply_filter('email_user_validation_description_after', osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_user_validation_description', $content['s_text'], $user, $input)), $words), $user, $input);

            $emailParams = array(
                'subject'  => $title,
                'from'     => _osc_from_email_aux(),
                'to'       => osc_contact_email(),
                'to_name'  => 'Admin',
                'body'     => $body,
                'alt_body' => $body
            );
            osc_sendMail($emailParams);
        }
    }
    osc_add_hook('hook_email_user_validation', 'fn_email_user_validation');
« Last Edit: December 20, 2017, 03:30:48 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #17 on: December 20, 2017, 02:19:54 pm »
If anyone knows how to run the hook email_user_registration after the admin manualy validates the user in Admin area, please share the mod. Thank you.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #18 on: December 20, 2017, 02:52:15 pm »
If anyone knows how to run the hook email_user_registration after the admin manualy validates the user in Admin area, please share the mod. Thank you.
EDITED AND TESTED => OK
Teseo , if you are seeing this, this is thanks to you (and please verify it).

Put this into your functions.php file from bender for example:
Take care not to leave empty lines after this, of before it.
Code: [Select]
<?php function mc_send_email_registration_to_user_after_admin_validation($user) {
    
fn_email_user_registration($user);
}

osc_add_hook('activate_user''mc_send_email_registration_to_user_after_admin_validation');
?>


PS. The code that I'm hooking into is:
oc-includes.osclass/UserActions.php

Code: [Select]
public function activate($user_id)
        {
            $user = $this->manager->findByPrimaryKey($user_id);

            if( !$user ) {
                return false;
            }

            $this->manager->update( array('b_active' => 1), array('pk_i_id' => $user_id) );

            if( !$this->is_admin ) {
                osc_run_hook('hook_email_admin_new_user', $user);
            }

            Log::newInstance()->insertLog('user', 'activate', $user_id, $user['s_email'], $this->is_admin ? 'admin' : 'user', $this->is_admin ? osc_logged_admin_id() : osc_logged_user_id() );

            if( $user['b_enabled'] == 1 ) {
                $mItem = new ItemActions(true);
                $items = Item::newInstance()->findByUserID($user_id);
                foreach($items as $item) {
                    $mItem->enable($item['pk_i_id']);
                }
            }

            // update items with s_contact_email the same as new user email
            $items_updated = Item::newInstance()->update(array('fk_i_user_id' => $user_id, 's_contact_name' => $user['s_name']), array('s_contact_email' => $user['s_email']) );
            if($items_updated!==false && $items_updated>0) {
                User::newInstance()->update('i_items = i_items + '. (int)$items_updated, array('pk_i_id' => $user_id));
            }
            // update alerts user id with the same email
            Alerts::newInstance()->update(array('fk_i_user_id' => $user_id), array('s_email' => $user['s_email']));

            osc_run_hook('activate_user', $user);

            return true;
        }
The user gets activated in oc-admin/users.php

Code: [Select]
                break;
                case('activate'):       //activate
                                        osc_csrf_check();
                                        require_once LIB_PATH . 'osclass/UserActions.php';
                                        $iUpdated = 0;
                                        $userId   = Params::getParam('id');
                                        if( !is_array($userId) ) {
                                            osc_add_flash_error_message( _m("User id isn't in the correct format"), 'admin');
                                            $this->redirectTo(osc_admin_base_url(true) . '?page=users');
                                        }

                                        $userActions = new UserActions(true);
                                        foreach($userId as $id) {
                                            $iUpdated   += $userActions->activate($id);
                                        }


Thank you for the idea.
« Last Edit: December 20, 2017, 03:30:16 pm by marius-ciclistu »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Only one ad for each user
« Reply #19 on: December 20, 2017, 03:44:36 pm »
Hi,

This is a bit complicated, but I have some time now.

@aficionado, More Edit only deals with ads, so it has no use here.

@marius, if validation mail is diverted to Admin, no need to activate User Account through Admin Dashboard, Admin could use the normal link for validation (and then the "Registration succesful" mail to the real user would be automatically sent).

So:

1.- Core modification to function fn_email_user_validation as shown in this post (although this function could be replaced through hooks with no core modification, more on this later after you check that my proposal is working fine).

2.-

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_user_register_admin_approval_message($message) {
    
$message str_replace(__('The user has been created. An activation email has been sent'), _m('The user has been created, but Admin still needs to approve your account, you\'ll receive a mail then.'), $message);

    return 
$message;
}

osc_add_filter('flash_message_text''cust_user_register_admin_approval_message');

function 
cust_user_register_admin_approval_validated($user) {
    
osc_add_flash_ok_message('User account for ' $user['s_email'] . ' succesfully activated');
    
header("Location: " osc_base_url(true).'?page=main&action=logout');
    exit();
}

osc_add_hook('validate_user''cust_user_register_admin_approval_validated');
?>


So, the flow:
1) The new user register his account and see this flash message "The user has been created, but Admin still needs to approve your account, you'll receive a mail then."

2) Admin receives a mail "Please validate your...". Clicking on the activation link, the new account is activated.

3) Real user receives a mail confirming his Account is active.

Please test this on your side.

Regards

Aficionado

  • Guest
Re: Only one ad for each user
« Reply #20 on: December 20, 2017, 03:54:15 pm »


@aficionado, More Edit only deals with ads, so it has no use here.


Yes, i was suggesting that as a workaround. A possible solution. A long shot ...
« Last Edit: December 20, 2017, 03:56:02 pm by Aficionado »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Only one ad for each user
« Reply #21 on: December 20, 2017, 03:58:23 pm »
Hi Aficionado,

I see your point, I just tought he has already resolved that part "Announcements are moderated by admin" with More Edit and asked if the same might be applied to User Accounts.

Regards

Aficionado

  • Guest
Re: Only one ad for each user
« Reply #22 on: December 20, 2017, 04:04:59 pm »
Hi Aficionado,

I see your point, I just tought he has already resolved that part "Announcements are moderated by admin" with More Edit and asked if the same might be applied to User Accounts.

Regards

Both functions should have been in the core of Osclass a long time ago. A very long time ago. Along with a Renew ad option.

 :o

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #23 on: December 20, 2017, 04:05:35 pm »
Teseo, I suggestet 2 options.

Number 1.The preferred one would be editing the email validation so that it doesn't contain the validation link + add in bender/functions.php file:
Code: [Select]
<?php function mc_send_email_registration_to_user_after_admin_validation($user) {
    
fn_email_user_registration($user);
}

osc_add_hook('activate_user''mc_send_email_registration_to_user_after_admin_validation');
?>

In this way no need for core mods and the admin validates the user from Admin area.

Number 2:
https://forums.osclass.org/3-7-x/only-one-ad-for-each-user/msg158915/#msg158915 The email validation goes to Admin and he validates the user via link, and then the user gets his registration email.

@ which you added the flash messages.

EDIT

Quote
@marius, if validation mail is diverted to Admin, no need to activate User Account through Admin Dashboard, Admin could use the normal link for validation (and then the "Registration succesful" mail to the real user would be automatically sent).

What reason would have the admin to validate the user via link, if he doesn't enter in admin to check more info about him?
« Last Edit: December 20, 2017, 04:18:25 pm by marius-ciclistu »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Only one ad for each user
« Reply #24 on: December 20, 2017, 05:29:47 pm »
What reason would have the admin to validate the user via link, if he doesn't enter in admin to check more info about him?

You're right, didn't think of that. Well, if you want to add the messages part to your proposal, there they are.

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #25 on: December 20, 2017, 05:35:04 pm »
C4 should choose the solution that best suits him.
Anyway I'm glad that I added a new functionality to my osclass with this answer and that I'ts my fist solution implemented via "TESEO's" hooks by my own :D

c4

  • Newbie
  • *
  • Posts: 25
Re: Only one ad for each user
« Reply #26 on: December 21, 2017, 04:13:52 pm »
Thank you very much for your help. I will now test solutions. At the moment I am testing the modification of the emails.php file. And it works right now.

What reason would have the admin to validate the user via link, if he doesn't enter in admin to check more info about him?

Only companies in a specific industry will be able to register in the portal I am building. Before clicking the link activating the account we need to check if the e-mail is the company's main email. It can be done by a moderator without access to the osclass panel. Each user can only give one ad, which is also moderated by another person.

c4

  • Newbie
  • *
  • Posts: 25
Re: Only one ad for each user
« Reply #27 on: December 29, 2017, 01:56:44 pm »
Only one ad per user. I tested the option:

1) See here: https://forums.osclass.org/plugins-20/limiting-number-of-postings-per-user/msg144243/#msg144243

The user wants to publish an advert having already their one receives the message "only 1 ad for the user" and here it is great

The user deletes the advertisement - he continues to receive the message - "only one ad per user"

I need that after the removal it will be possible to publish another one as if it were the first one

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #28 on: December 29, 2017, 02:08:15 pm »
Only one ad per user. I tested the option:

1) See here: https://forums.osclass.org/plugins-20/limiting-number-of-postings-per-user/msg144243/#msg144243

The user wants to publish an advert having already their one receives the message "only 1 ad for the user" and here it is great

The user deletes the advertisement - he continues to receive the message - "only one ad per user"

I need that after the removal it will be possible to publish another one as if it were the first one

I managed to repair that user field osc_user_field('i_items')  without a plugin but I'm strugling with the lack of google search in these forums to find the post.

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: Only one ad for each user
« Reply #29 on: December 29, 2017, 02:12:16 pm »
Found it
https://forums.osclass.org/development/updating-dt_mod_date-together-with-dt_expiration/msg155870/#msg155870

But after implementing it you must manually correct the values in the db.
« Last Edit: December 29, 2017, 02:14:37 pm by marius-ciclistu »