Managing the campaign thread

Code

Edit the file models/sms.inc:

  1. require_once 'models/thread.inc';
  1. function sms_create_campaign_thread($user_id, $lang, $thread_name, $thread_title) {
  2.     global $supported_languages;
  3.  
  4.     $thread_type='campaign';
  5.  
  6.     $r = thread_create($lang, $user_id, $thread_name, $thread_title, $thread_type);
  7.  
  8.     if (!$r) {
  9.         return false;
  10.     }
  11.     extract($r);    /* thread_id thread_number */
  12.  
  13.     foreach ($supported_languages as $clang) {
  14.         $r = thread_set($clang, $thread_id, $thread_name, $thread_title, $thread_type, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
  15.  
  16.         if (!$r) {
  17.             $sql="DELETE FROM $tabthread WHERE thread_id=$thread_id";
  18.  
  19.             $r = db_delete($sql);
  20.  
  21.             return false;
  22.         }
  23.     }
  24.  
  25.     return true;
  26. }
  1. function sms_delete_campaign_thread($user_id) {
  2.     $thread_id=sms_get_user_campaign_id($user_id);
  3.  
  4.     if (!$thread_id) {
  5.         return false;
  6.     }
  7.  
  8.     if (!thread_delete($thread_id)) {
  9.         return false;
  10.     }
  11.  
  12.     return true;
  13. }
  1. function sms_rename_campaign_thread($user_id, $thread_name, $thread_title) {
  2.     $sqlname=db_sql_arg($thread_name, true);
  3.     $sqltitle=db_sql_arg($thread_title, true, true);
  4.  
  5.     $tabthread=db_prefix_table('thread');
  6.     $tabthreadlocale=db_prefix_table('thread_locale');
  7.  
  8.     $sql="UPDATE $tabthreadlocale SET title=$sqltitle, name=$sqlname WHERE thread_id=(SELECT thread_id FROM $tabthread WHERE thread_type='campaign' AND user_id=$user_id)";
  9.  
  10.     $r = db_update($sql);
  11.  
  12.     if ($r === false) {
  13.         return false;
  14.     }
  15.  
  16.     return true;
  17. }

Edit the file actions/campaigneditsummary.php:

  1.             if ($action == 'create') {
  2.                 node_create_content($clang, $node_id, 'sms');
  3.             }
  1.     $viewsms=$thread_contents ? url('campaign', $clang) . '/'. $thread_id . '?' . 'slang=' . $lang : false;

Edit the file actions/campaigneditpage.php:

  1.     $viewsms=$node_name ? url('campaign', $clang) . '/'. $thread_id . '/' . $node_id : false;

Edit the file blocks/searchlist.php:

  1.         else {
  2.             $thread_url=url($thread_type, $lang) . '/'. ($thread_type == 'campaign' ? $thread_id : $thread_name);
  3.         }
  1.         $link_url=$thread_url . '/' . ($thread_type == 'campaign' ? $node_id : $node_name);

Edit the file blocks/register.php:

  1. require_once 'models/sms.inc';
  1.     $with_info=true;
  2.  
  3.     $with_client=$is_admin;
  1.     $is_client=true;
  1.             if ($with_client) {
  2.                 $is_client=isset($_POST['register_isclient']) ? (readarg($_POST['register_isclient']) == 'on' ? true : false) : false;
  3.             }
  1.             if ($with_info and !($with_client and !$is_client)) {
  1.             if ($with_info and !($with_client and !$is_client)) {
  1.             if ($is_client) {
  2.                 $r = sms_create_campaign_thread($user_id, $locale, $name, "$firstname $lastname");
  3.  
  4.                 if (!$r) {
  5.                     $internal_error=true;
  6.                     break;
  7.                 }
  8.  
  9.                 user_set_role($user_id, 'client');
  10.  
  11.                 $newsletter=true;
  12.             }
  1.     $output = view('register', $lang, compact('token', 'connectbar', 'with_captcha', 'with_name', 'with_website', 'with_timezone', 'with_password', 'with_newsletter', 'with_confirmation', 'name', 'mail', 'website', 'timezone', 'password', 'with_client', 'is_client', 'with_info', 'lastname', 'firstname', 'newsletter', 'confirmed', 'account_created', 'errors', 'infos'));

Modify the view register in English and in French in the files views/en/register.phtml and views/fr/register.phtml:

  1. <?php if ($with_client): ?>
  2. <p><input type="checkbox" name="register_isclient" id="register_isclient" title=""<?php if ($is_client): ?> checked="checked"<?php endif; ?> />&nbsp;I want to create a client account</p>
  3. <?php endif; ?>
  1. <?php if ($with_client): ?>
  2. <p><input type="checkbox" name="register_isclient" id="register_isclient" title=""<?php if ($is_client): ?> checked="checked"<?php endif; ?> />&nbsp;Je veux créer un compte client</p>
  3. <?php endif; ?>

Edit the file blocks/useredit.php:

  1.     $user_role = user_get_role($user_id);
  2.  
  3.     $is_client=$user_role && in_array('client', $user_role);
  4.  
  5.     $with_info=$is_client;
  1.                 if ($is_owner) {
  2.                     $_SESSION['user']['lastname'] = $user_lastname;
  3.                     $_SESSION['user']['firstname'] = $user_firstname;
  4.                 }
  5.  
  6.                 if ($is_client) {
  7.                     require_once 'models/sms.inc';
  8.  
  9.                     $r = sms_rename_campaign_thread($user_id, $user_name, "$user_firstname $user_lastname");
  10.  
  11.                     if (!$r) {
  12.                         $internal_error=true;
  13.                         break;
  14.                     }
  15.                 }
  1.             $r = user_delete($user_id);
  2.  
  3.             if (!$r) {
  4.                 $internal_error=true;
  5.                 break;
  6.             }
  7.  
  8.             if ($is_client) {
  9.                 require_once 'models/sms.inc';
  10.  
  11.                 $r = sms_delete_campaign_thread($user_id);
  12.  
  13.                 if (!$r) {
  14.                     $internal_error=true;
  15.                     break;
  16.                 }
  17.             }
Test

Disconnect then go the identification page and follow the link To create your personal account, click here.

New account

What is your first name?

And your last name?

Create an account for John Smith with the identifier jsmith.

Connect with the identifier jsmith.

Click on the large phone to list John Smith's campaigns.

John Smith

Click on the keyboard to enter the editor.

John Smith

the campaign #

Add the campaign with the title The web engine.

Press on the flag to display the list of campaigns in French. IMPORTANT: The version of a campaign in another language is created in the editor of a campaign.

Press on the flag to display the list of campaigns in English. Click on the title The web engine.

Type Create your multimedia website in a few minutes with iZend - The web engine: http://www.izend.org. for the content of the message, associate the campaign to the keywords iZend web engine in the cloud and give it the subject Initial campaign for web agencies. Press Configure.

Click on the to switch into display mode.

Click on iZend in the cloud.

Click on the title The web engine to display the campaign.

Go back into the editor and click on the flag to create a version in French. Notice that the title of the campaign is a number.

Try creating a campaign without a title by pressing Configure. The operation is rejected.

Create a campaign in French with the title Le moteur web, the cloud iZend moteur web, the subject Campagne initialed pour les agences web and the message Créez votre site multimédias en quelques minutes avec iZend - Le moteur web : http://www.izend.org. Press Configure.

Click on the web to switch into display mode.

Go back into the editor , click on the the flag , display the campaign in English, click on Campaigns at the top right above the cloud. Enter the editor and press on the flag to switch languages. The campaign has one version in English and one in French.

Click on the logo to return to the home page. Follow the link To modify your identifier, your email or change your password, click here.

Change the firstname, the lastname and the identifier, e.g. Peter Miller pmiller.

Go back to the home page and display the list of campaigns. The title has changed.

Peter Miller

  1. The web engine

Disconnect and reconnect as administrator. Enter into the management part then look for pmiller and edit the account. Modify the firstname, the lastname and the identifier, e.g. John Smith jsmith.

Go back to the management part and list the advertizers. Display John Smith's campaigns.

Export the DB of the site.

Delete the account jsmith. Check that the campaign thread of the account and all the nodes and all the contents of the thread have been deleted from the DB.

Git
  1. /izendsms.com
    1. actions
      1. campaigneditpage.php
      2. campaigneditsummary.php
    2. blocks
      1. register.php
      2. searchlist.php
      3. useredit.php
    3. models
      1. sms.inc
    4. views
      1. en
        1. register.phtml
      2. fr
        1. register.phtml

Commit this version:

$ git status
$ git add actions/campaigneditpage.php actions/campaigneditsummary.php blocks/register.php blocks/useredit.php models/sms.inc views/en/register.phtml views/fr/register.phtml
$ git commit -m'Adds creating and managing campaign threads with client accounts'

IMPORTANT: Edit the DB connector in the file includes/db.inc.

Comments

To add a comment, click here.