Receive job ads by e-mail

In this section of the tutorial, you will enhance the application by allowing users to subscribe to receive email messages when an ad that fits some entered criteria is posted. The subscribe_sub table will be used for the purpose of this improvement, as it will store the user's preferences for the ads they will receive by e-mail.

To create this enhancements, you must take two steps:

  1. Create a page where users can subscribe to a certain type of ads, view their existing subscriptions and alter them.

  2. Modify the ad posting page, so that it will send an e-mail to all users that subscribed to ads that have the same characteristics as the one entered.

 

The user's subscription page will be placed inside the user folder, and it will be available through a link on the user's home page. To create this page, follow the next steps:

  1. Create the new files that will be used by users to manage their subscriptions in the user folder: view_subscription.php and subscribe.php.

  2. Open the view_subscription.php page in Dreamweaver.

  3. To allow only registered users to take advantage of the subscription improvement, apply a Restrict Access To Page Server Behavior, which will act based on username, password and level. Configure it as shown in the User Authentication Tutorial.

  4. To build the subscription list together with all links and functionality, you will use the NeXTensio List. Open the  Create NeXTensio List Wizard from the MX Kollection tab of the Insert bar.

  5. In the second step, you will have to determine which table columns will be displayed in the list

  6. In the third step of the wizard, you must set options for the filter elements. This will control what elements and with which default values will be used in the filter. For all of the list fields that use a look-up table, the filter element is automatically set to Menu. The menu contents are dynamic, using automatically generated recordsets on the same tables as selected in step two (2). You only need to setup the filter for the type_sub field. Since there are only three possible job types, set the Display as to menu, and configure its static options by pressing the Menu properties button:


     

  7. In the last step, you must configure some of the list's properties:
    · What table column to order the list by, whether to duplicate navigation and buttons, or the skin. Configure the dialog box as shown in the next image:


     

  8. Click the Finish button to close the dialog box and add all elements into the page.

 

In Dreamweaver, you will notice the HTML elements added by the wizard, as well as the server behaviors, and recordset you've created for the fields. There is one more thing you need to do in order for the list to display subscriptions for the current user only: restricting the list's recordset on the currently logged in user's ID.

To accomplish this, follow the next steps:

  1. Double-click the NeXTensio List recordset (usually called ListRecordSet in the Bindings tab. Add a new variable, called user, having the runtime value equal to $_SESSION['kt_login_id']. To add a parameter, click the Plus (+) button on top of  the Variables grid, and set its properties in the dialog box that opens:



    Note: If using ColdFusion, you must add a Page parameter. Configure it as shown in the image below:



     

  2. Change the SQL query, so that it will take the new variable into account:

    SELECT subscribe_sub.type_sub, iddom_sub AS old_iddom_sub, domain_dom.name_dom AS iddom_sub, location_sub AS old_location_sub, location_loc.name_loc AS location_sub, subscribe_sub.minsal_sub, subscribe_sub.id_sub
    FROM subscribe_sub LEFT JOIN domain_dom ON subscribe_sub.iddom_sub = domain_dom.id_dom LEFT JOIN location_loc ON subscribe_sub.location_sub = location_loc.name_loc
    WHERE filter
    AND idusr_sub=user
    ORDER BY sort

     

  3. Click the OK button to close the recordset dialog box, save and upload the page to the server. You can test it by logging in as a user, and clicking the View subscription link on the home page. It will open the list, showing the subscriptions the respective user has made.

 

Create the page that allows users add and edit subscriptions. This page has been referred to already, when you specified it in the NeXTensio List Wizard last step. It will contain a form, allowing users decide the criteria for their subscription.

  1. Open the subscribe.php page in Dreamweaver.

  2. To create the form, you will use the NeXTensio Form Wizard. Because you've already created a list in this site, the user interface persistence will take effect and you will notice that the wizard's options are already filled in.

  3. In the first step, the connJobs database connection, as well as the subscribe_sub table are already completed. Leave them as they are, because the values are correct, and move on to the second step: the field configuration.

  4. The user interface persistence is working in this step too. You can notice that all the list fields are here, configured as menus, with the right recordsets (where applicable) or values. However, one more piece of information is required when entering data into the tables: the user ID.

  5. To add a field to the form fields grid, simply click the Plus (+) button on top of it, and select the desired field from the list of available ones. Select the idusr_sub field.

  6. Once it appeared in the grid, you have to configure it to be displayed as a hidden field, and to retrieve its value from the session variable storing the current user id. To do so, click on it in the grid, and in the Display as drop-down menu select Text. Also, in the Default Value text-field you have to have the session variable. Click the InterAKT Dynamic Data icon next to the field, and select the kt_login_id variable.


     

  7. With all fields configured, you can safely click the Finish button.

  8. If you have MX Form Validation installed, another step will be available in the wizard, where you can define validation rules for any of the fields in the form. You can skip this step, as most of the form elements are menus, where users have to select from predefined values.

  9. Delete the first row in the form, the one containing the user ID element as text.

  10. Save the page and upload it to the server. To test it out, log in with a regular user account and click the View subscriptions link. In the list, press the Add new button, as this will open the subscribe.php file you've just created. Fill in the form, and hit OK to add the subscription to your list:

 

The second part of this tutorial section, requires some modification to the job opportunity posting page. To be precise, it requires adding a Send e-mail to recipients from recordset server behavior, which will send a message regarding the job offer that is being submitted to all users that match the type, domain, location and minimum salary.

To create this page follow the next steps:

  1. Open the post_job.php page from the company folder in Dreamweaver. On the page there is already an Insert Transaction, that allows posting new job offers.

  2. To send the email to all users that are subscribed to the type, domain and location of the job ad that's being posted, you must add two things: a recordset to retrieve their email addresses, and a Send email trigger.

  3. First the recordset: it must be filtered, since the user's preferred job type, domain, location and minimum salary must match the ones entered in the post ad form. Create a new recordset from the Bindings panel, and when the dialog box opens, switch to the QuB3 view by clicking the QuB3 button on the right.

  4. In the QuB3 view, select the database connection created at the beginning of the tutorial. Then name the query rsMail and click the New Query button on the bottom.

  5. Type rsMail again in the name prompt and click OK. The MX Query Builder interface should then open. If this is your first time using MX Query Builder, you may want to take a quick look at the Workspace orientation page to understand the interface a bit better.

  6. From the Tables panel on the left, select the two tables you will need for this query: subscribe_sub, and user_usr

  7. The two tables will now appear in the Database Diagram. Here you will create a relation between the two tables using the foreign key field. Just drag and drop the idusr_sub field to the id_usr field as shown below:

  8. After adding the relation, a blue line with an arrow will connect the two fields. Using the checkboxes from each table, select various fields as shown below. When done, the Database Diagram should look as follows:

  9. By checking the boxes next to each field in the subscribe_sub table, each selected field is displayed below in the Query Management panel. Here is where the conditions are added so that the data retrieved matches the data requested from the form.

  10. To add conditions, click the button under the Condition column of the Query Management panel:

  11. Starting with the type_sub field, click the Condition button in the same row. An Edit SQL Condition window will appear. Configure it as shown below:

  12. Repeat step 11 for iddom_sub, location_sub, and minsal_sub. For the Run-time Value field, make sure to use the appropriate variable from the previously created form (domain_job, location_job, salary_job).
    Note
    : For the minsal_sub field to work properly, use "<=" for the condition instead of just "=".

  13. Once all the conditions are added, you can save the query by going to the Query menu and clicking Save:

  14. Now close MX Query Builder and go back into Dreamweaver.

  15. The QuB3 Visual Recordset window should still be open. Click the Refresh button:

  16. The rsMail query from MX Query Builder will now be in the dropdown, and its SQL code will be in the SQL field. Click OK.

  17. Now for the actual sending of the mail messages you will use a trigger provided by MX Send E-mail: Send E-mail to recipients from recordset. This trigger will send a mail message to all mail addresses retrieved by a recordset, in our case the rsMail one.

  18. Before applying the server behavior, you should check out the mail server settings in Control Panel, to see if they are correct in your case. To learn more about the mail server settings, click here.

  19. Apply the Send E-mail to recipients from recordset server behavior from the Server Behaviors tab->MX Kollection->Send E-mail. From the dialog box that opens, you only need to configure the options on the first tab. Set them as follows:
    · In the Recordset drop-down menu select rsMail.
    · In the Email to field drop-down menu select the recordset field containing the user's mail address.
    · In the From text box you can enter an email address specific for your site, or leave it at default, to use the control panel defined sender.
    · In the Subject text-box enter the mail's subject: New job offer.
    · For the mail's content, you have two choices: to use a predefined template, or to write the content in the text area below. Select the latter version, as there is no need for a special template.
    · In the Content text area enter the mail text. Usually, a notice that a new job that matches what the user subscribed for has been added is enough.

  20. The completed dialog box should look like the image below:


     

  21. Once all dialog box required options are completed, simply click the OK button to add the server behavior into the page.

Note: If using the ASP VBScript server model you must configure the E-mail server settings in the Control Panel. You must fill in the server address (or name), the port (by default it is 25), user name and password. Optionally, you can also set the default sender field.

Now all modifications required for the subscription mechanism to work are completed, and you can save and upload all pages to the server. When a job offer is added, as a last operation on the page, a recordset will retrieve all users that match the job type, domain and location, have the minimum desired salary lower or equal to what is being offered, and send an e-mail message to the respective mail addresses.

You can further improve your site in this direction, by allowing subscribers view the ads directly in the mail message, or even apply for it. Also, a link in the mail message pointing directly to the job detail and application page is a handy feature.