1

Displaying campaigns

Code

Create the file campaign.php in the folder actions with the following content:

  1. require_once 'userhasrole.php';
  2. require_once 'userprofile.php';
  3. require_once 'models/sms.inc';
  4.  
  5. function campaign($lang, $arglist=false) {
  6.     $campaign=$page=false;
  7.  
  8.     if (is_array($arglist)) {
  9.         if (isset($arglist[0])) {
  10.             $campaign=$arglist[0];
  11.         }
  12.         if (isset($arglist[1])) {
  13.             $page=$arglist[1];
  14.         }
  15.     }

The action campaign is called without arguments, with the name or the number of a campaign thread and with or without the name or the number of a campaign.

  1.     if (!$campaign) {
  2.         if (user_has_role('administrator')) {
  3.             require_once 'actions/campaignall.php';
  4.  
  5.             return campaignall($lang);
  6.         }
  7.  
  8.         $user_id=user_profile('id');
  9.  
  10.         if (!$user_id) {
  11.             return run('error/unauthorized', $lang);
  12.         }
  13.  
  14.         $campaign=sms_get_user_campaign_id($user_id);
  15.  
  16.         if (!$campaign) {
  17.             return run('error/notfound', $lang);
  18.         }
  19.     }

If the user is an administrator, displays all the threads of all the clients, the advertizers. Otherwise, displays the list of the campaigns of the user. If the user isn't connected or if the function sms_get_user_campaign_id doesn't find a campaign thread belonging to the user, returns an error.

  1.     if (!$page) {
  2.         require_once 'actions/campaignsummary.php';
  3.  
  4.         return campaignsummary($lang, $campaign);
  5.     }
  6.  
  7.     require_once 'actions/campaignpage.php';
  8.  
  9.     return campaignpage($lang, $campaign, $page);
  10. }

Displays a campaign if the name or the number of a campaign is passed in argument. Otherwise, displays the list of all the campaigns of the user.

Create the file sms.inc in the folder models with the following content:

  1. function sms_get_user_campaign_id($user_id) {
  2.     $tabthread=db_prefix_table('thread');
  3.  
  4.     $sql="SELECT thread_id FROM $tabthread WHERE thread_type='campaign' AND user_id=$user_id";
  5.  
  6.     $r = db_query($sql);
  7.  
  8.     return $r ? $r[0]['thread_id'] : false;
  9. }

The function sms_get_user_campaign_id returns the number of the campaign thread of a user.

  1. function sms_list_campaign_users($lang) {
  2.     $sqllang=db_sql_arg($lang, false);
  3.  
  4.     $tabthread=db_prefix_table('thread');
  5.     $tabthreadlocale=db_prefix_table('thread_locale');
  6.  
  7.     $sql="SELECT t.thread_id, tloc.name AS thread_name, tloc.title AS thread_title, tloc.abstract AS thread_abstract, tloc.cloud AS thread_cloud, t.number AS thread_number FROM $tabthread t JOIN $tabthreadlocale tloc ON tloc.thread_id=t.thread_id AND tloc.locale=$sqllang WHERE t.thread_type='campaign' ORDER BY t.number";
  8.  
  9.     $r = db_query($sql);
  10.  
  11.     if (!$r) {
  12.         return false;
  13.     }
  14.  
  15.     $thread_list = array();
  16.     $url = url('campaign', $lang);
  17.     foreach ($r as $thread) {
  18.         extract($thread);   /* thread_id thread_name thread_title thread_abstract thread_cloud thread_number */
  19.         $thread_url = $url . '/' . $thread_id;
  20.         $thread_list[] = compact('thread_number', 'thread_id', 'thread_title', 'thread_abstract', 'thread_cloud', 'thread_url');
  21.     }
  22.  
  23.     return $thread_list;
  24. }

The function sms_list_campaign_users returns the list of the campaign threads.

Create the file campaignall.php in the folder actions with the following content:

  1. require_once 'userhasrole.php';
  2. require_once 'models/sms.inc';
  3.  
  4. function campaignall($lang) {
  5.     global $with_toolbar;
  6.  
  7.     if (!user_has_role('administrator')) {
  8.         return run('error/unauthorized', $lang);
  9.     }
  10.  
  11.     head('title', translate('campaignall:title', $lang));
  12.     head('description', false);
  13.     head('keywords', false);
  14.     head('robots', 'noindex, nofollow');
  15.  
  16.     $admin=true;
  17.     $banner = build('banner', $lang, $with_toolbar ? false : compact('admin'));
  18.     $toolbar = $with_toolbar ? build('toolbar', $lang, compact('admin')) : false;
  19.  
  20.     $campaign_list = sms_list_campaign_users($lang);
  21.  
  22.     $content = view('campaignall', $lang, compact('campaign_list'));
  23.  
  24.     $output = layout('standard', compact('toolbar', 'banner', 'content'));
  25.  
  26.     return $output;
  27. }

Displays a page with the list of all the campaign owners returned by the function sms_list_campaign_users. Clicking on the name of a client displays the list of all his campaigns.

Create the view campaignall in English and in French in the files views/en/campaignall.phtml and views/fr/campaignall.phtml:

  1. <h3>Advertisers</h3>
  2. <?php if (!empty($campaign_list)): ?>
  3. <ol>
  4. <?php foreach ($campaign_list as $thread):
  5. extract($thread);   /* thread_id thread_name thread_title thread_url */
  6. ?>
  7. <li><a href="<?php echo $thread_url; ?>"><span><?php echo htmlspecialchars($thread_title ? $thread_title : $thread_id, ENT_COMPAT, 'UTF-8'); ?></span></a></li>
  8. <?php endforeach; ?>
  9. </ol>
  10. <?php endif; ?>
  1. <h3>Annonceurs</h3>
  2. <?php if (!empty($campaign_list)): ?>
  3. <ol>
  4. <?php foreach ($campaign_list as $thread):
  5. extract($thread);   /* thread_id thread_name thread_title thread_url */
  6. ?>
  7. <li><a href="<?php echo $thread_url; ?>"><span><?php echo htmlspecialchars($thread_title ? $thread_title : $thread_id, ENT_COMPAT, 'UTF-8'); ?></span></a></li>
  8. <?php endforeach; ?>
  9. </ol>
  10. <?php endif; ?>

Create the file campaignsummary.php in the folder actions with the following content:

  1. require_once 'userhasrole.php';
  2. require_once 'userprofile.php';
  3. require_once 'models/thread.inc';
  4.  
  5. function campaignsummary($lang, $campaign) {
  6.     global $with_toolbar;
  7.  
  8.     $user_id=user_profile('id');
  9.  
  10.     if (!$user_id) {
  11.         return run('error/unauthorized', $lang);
  12.     }
  13.  
  14.     $campaign_id = thread_id($campaign);
  15.     if (!$campaign_id) {
  16.         return run('error/notfound', $lang);
  17.     }
  18.  
  19.     $r = thread_get($lang, $campaign_id);
  20.     if (!$r) {
  21.         return run('error/notfound', $lang);
  22.     }
  23.     extract($r); /* thread_user_id thread_type thread_name thread_title thread_abstract thread_cloud thread_nocloud thread_nosearch */
  24.  
  25.     if ($thread_type != 'campaign') {
  26.         return run('error/notfound', $lang);
  27.     }
  28.  
  29.     if ($thread_user_id != $user_id and !user_has_role('administrator')) {
  30.         return run('error/notfound', $lang);
  31.     }
  32.  
  33.     $campaign_name = $thread_name;
  34.     $campaign_title = $thread_title;
  35.     $campaign_abstract = $thread_abstract;
  36.     $campaign_cloud = $thread_cloud;
  37.     $campaign_modified= $thread_modified;
  38.     $campaign_nocloud = $thread_nocloud;
  39.     $campaign_nosearch = $thread_nosearch;
  40.  
  41.     if ($campaign_title) {
  42.         head('title', $campaign_title);
  43.     }
  44.     else {
  45.         head('title', translate('campaignall:title', $lang));
  46.     }
  47.     head('description', false);
  48.     head('keywords', false);
  49.     head('robots', 'noindex, nofollow');
  50.  
  51.     $campaign_contents = array();
  52.     $r = thread_get_contents($lang, $campaign_id);
  53.     if ($r) {
  54.         $campaign_url = url('campaign', $lang);
  55.         foreach ($r as $c) {
  56.             extract($c);    /* node_id node_name node_title node_number */
  57.             $page_id = $node_id;
  58.             $page_title = $node_title;
  59.             $page_url = $campaign_url . '/' . $campaign_id . '/' . $node_id;
  60.             $campaign_contents[] = compact('page_id', 'page_title', 'page_url');
  61.         }
  62.     }
  63.  
  64.     $content = view('campaignsummary', false, compact('campaign_id', 'campaign_title', 'campaign_abstract', 'campaign_contents'));
  65.  
  66.     $search=false;
  67.     if (!$campaign_nosearch) {
  68.         $search_text='';
  69.         $search_url= url('search', $lang, $campaign_id);
  70.         $suggest_url= url('suggest', $lang, $campaign_id);
  71.         $search=view('searchinput', $lang, compact('search_url', 'search_text', 'suggest_url'));
  72.     }
  73.  
  74.     $cloud=false;
  75.     if (!$campaign_nocloud) {
  76.         $cloud_url= url('search', $lang, $campaign_id);
  77.         $byname=$bycount=$index=true;
  78.         $cloud = build('cloud', $lang, $cloud_url, $campaign_id, false, 30, compact('byname', 'bycount', 'index'));
  79.     }
  80.  
  81.     $headline_text= translate('campaignsummary:title', $lang);
  82.     $headline_url=user_has_role('administrator') ? url('campaign', $lang) : false;
  83.     $headline = compact('headline_text', 'headline_url');
  84.     $title = view('headline', false, $headline);
  85.  
  86.     $sidebar = view('sidebar', false, compact('search', 'cloud', 'title'));
  87.  
  88.     $search=!$thread_nosearch ? compact('search_url', 'search_text', 'suggest_url') : false;
  89.     $edit=false;
  90.  
  91.     $banner = build('banner', $lang, $with_toolbar ? compact('headline', 'search') : compact('headline', 'edit', 'search'));
  92.     $toolbar = $with_toolbar ? build('toolbar', $lang, compact('edit')) : false;
  93.  
  94.     $output = layout('standard', compact('sharebar', 'toolbar', 'banner', 'sidebar', 'content'));
  95.  
  96.     return $output;
  97. }

Create the view campaignsummary in the file views/campaignsummary.phtml:

  1. <div id="campaignsummary">
  2. <h3><?php echo htmlspecialchars($campaign_title ? $campaign_title : $campaign_id, ENT_COMPAT, 'UTF-8'); ?></h3>
  3. <?php if ($campaign_abstract): ?>
  4. <p><?php echo htmlspecialchars($campaign_abstract, ENT_COMPAT, 'UTF-8'); ?></p>
  5. <?php endif; ?>
  6. <?php if ($campaign_contents): ?>
  7. <ol>
  8. <?php foreach ($campaign_contents as $c): ?>
  9. <?php extract($c)/* page_title page_url */ ?>
  10. <li><a href="<?php echo $page_url; ?>"><?php echo htmlspecialchars($page_title ? $page_title : $page_id, ENT_COMPAT, 'UTF-8'); ?></a></li>
  11. <?php endforeach; ?>
  12. </ol>
  13. <?php endif; ?>
  14. </div>

Create the file campaignpage.php in the folder actions with the following content:

  1. require_once 'userhasrole.php';
  2. require_once 'userprofile.php';
  3. require_once 'models/thread.inc';
  4.  
  5. function campaignpage($lang, $thread, $node) {
  6.     global $with_toolbar;
  7.  
  8.     $user_id=user_profile('id');
  9.  
  10.     if (!$user_id) {
  11.         return run('error/unauthorized', $lang);
  12.     }
  13.  
  14.     $thread_id = thread_id($thread);
  15.     if (!$thread_id) {
  16.         return run('error/notfound', $lang);
  17.     }
  18.  
  19.     $node_id = thread_node_id($thread_id, $node, $lang);
  20.     if (!$node_id) {
  21.         return run('error/notfound', $lang);
  22.     }
  23.  
  24.     $r = thread_get($lang, $thread_id);
  25.     if (!$r) {
  26.         return run('error/notfound', $lang);
  27.     }
  28.     extract($r); /* thread_user_id thread_type thread_name thread_title thread_abstract thread_cloud thread_nocloud thread_nosearch thread_nocomment thread_nomorecomment */
  29.  
  30.     if ($thread_type != 'campaign') {
  31.         return run('error/notfound', $lang);
  32.     }
  33.  
  34.     if ($thread_user_id != $user_id and !user_has_role('administrator')) {
  35.         return run('error/notfound', $lang);
  36.     }
  37.  
  38.     $r = thread_get_node($lang, $thread_id, $node_id);
  39.     if (!$r) {
  40.         return run('error/notfound', $lang);
  41.     }
  42.     extract($r); /* node_number node_ignored node_name node_title node_abstract node_cloud node_image node_user_id node_visits node_nocomment node_nomorecomment node_novote node_nomorevote node_ilike node_tweet node_plusone node_linkedin */
  43.  
  44.     $sms_user_id=$node_user_id;
  45.     $sms_name=$node_name;
  46.     $sms_title=$node_title;
  47.     $sms_subject=$node_abstract;
  48.     $sms_cloud=$node_cloud;
  49.     $sms_image=$node_image;
  50.     $sms_number=$node_number;
  51.     $sms_modified=$node_modified;
  52.  
  53.     $smscontents = build('nodecontent', $lang, $node_id);
  54.  
  55.     if ($sms_title) {
  56.         head('title', $sms_title);
  57.     }
  58.     else if ($thread_title) {
  59.         head('title', $thread_title);
  60.     }
  61.     else {
  62.         head('title', translate('campaignpage:title', $lang));
  63.     }
  64.     head('description', false);
  65.     head('keywords', false);
  66.     head('robots', 'noindex, nofollow');
  67.  
  68.     $prev_node_label=$prev_node_url=false;
  69.     $r=thread_node_prev($lang, $thread_id, $node_id);
  70.     if ($r) {
  71.         extract($r);    /* prev_node_id prev_node_name prev_node_title prev_node_number */
  72.         $prev_node_label = $prev_node_title ? $prev_node_title : $prev_node_number;
  73.         $prev_node_url=url('campaign', $lang) .  '/' . $thread_id . '/'. $prev_node_id;
  74.     }
  75.  
  76.     $next_node_label=$next_node_url=false;
  77.     $r=thread_node_next($lang, $thread_id, $node_id);
  78.     if ($r) {
  79.         extract($r);    /* next_node_id next_node_name next_node_title next_node_number */
  80.         $next_node_label = $next_node_title ? $next_node_title : $next_node_number;
  81.         $next_node_url=url('campaign', $lang) . '/' . $thread_id . '/'. $next_node_id;
  82.     }
  83.  
  84.     $content = view('campaignpage', $lang, compact('node_id', 'sms_title', 'sms_cloud', 'sms_modified', 'sms_subject', 'smscontents', 'prev_node_url', 'prev_node_label', 'next_node_url', 'next_node_label'));
  85.  
  86.     $search=false;
  87.     if (!$thread_nosearch) {
  88.         $search_text='';
  89.         $search_url= url('search', $lang, $thread_id);
  90.         $suggest_url= url('suggest', $lang, $thread_id);
  91.         $search=view('searchinput', $lang, compact('search_url', 'search_text', 'suggest_url'));
  92.     }
  93.  
  94.     $cloud=false;
  95.     if (!$thread_nocloud) {
  96.         $cloud_url= url('search', $lang, $thread_id);
  97.         $byname=$bycount=$index=true;
  98.         $cloud = build('cloud', $lang, $cloud_url, $thread_id, false, 15, compact('byname', 'bycount', 'index'));
  99.     }
  100.  
  101.     $headline_text=translate('campaignsummary:title', $lang);
  102.     $headline_url=url('campaign', $lang) . '/' . $thread_id;
  103.     $headline = compact('headline_text', 'headline_url');
  104.     $title = view('headline', false, $headline);
  105.  
  106.     $sidebar = view('sidebar', false, compact('search', 'cloud', 'title'));
  107.  
  108.     $search=!$thread_nosearch ? compact('search_url', 'search_text', 'suggest_url') : false;
  109.     $edit=false;
  110.  
  111.     $banner = build('banner', $lang, $with_toolbar ? compact('headline', 'search') : compact('headline', 'edit', 'search'));
  112.     $toolbar = $with_toolbar ? build('toolbar', $lang, compact('edit')) : false;
  113.  
  114.     $output = layout('standard', compact('toolbar', 'banner', 'content', 'sidebar'));
  115.  
  116.     return $output;
  117. }

Create the view campaignpage in English and in French in the files views/en/campaignpage.phtml and views/fr/campaignpage.phtml:

  1. <?php require_once 'dateen.php'; ?>
  2. <h3><?php echo htmlspecialchars($sms_title ? $sms_title : $node_id, ENT_COMPAT, 'UTF-8'); ?></h3>
  3. <p class="navigation menu">
  4. <?php if ($prev_node_url): ?>
  5. <a class="previous" href="<?php echo $prev_node_url; ?>"><span>&lt;</span></a>
  6. <a href="<?php echo $prev_node_url; ?>"><?php echo htmlspecialchars($prev_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
  7. <?php endif; ?>
  8. <?php if ($next_node_url and $prev_node_url): ?>
  9. &nbsp;|&nbsp;
  10. <?php endif; ?>
  11. <?php if ($next_node_url): ?>
  12. <a href="<?php echo $next_node_url; ?>"><?php echo htmlspecialchars($next_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
  13. <a class="next" href="<?php echo $next_node_url; ?>"><span>&gt;</span></a>
  14. <?php endif; ?>
  15. </p>
  16. <p class="info"><?php echo longdate_en($sms_modified); ?> at <?php echo date('H:i', $sms_modified); ?></p>
  17. <?php if ($sms_subject): ?>
  18. <p><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></p>
  19. <?php endif; ?>
  20. <?php if ($sms_cloud): ?>
  21. <p class="small"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></p>
  22. <?php endif; ?>
  23. <h4>Message</h4>
  24. <?php if ($smscontents): ?>
  25. <div id="sms">
  26. <?php echo $smscontents; ?>
  27. </div>
  28. <?php else: ?>
  29. <p class="info"><span class="btn_edit btn_help" title="Aide"></span>
  30. Use the editor to add some content to your message.</p>
  31. <?php endif; ?>
  1. <?php require_once 'datefr.php'; ?>
  2. <h3><?php echo htmlspecialchars($sms_title ? $sms_title : $node_id, ENT_COMPAT, 'UTF-8'); ?></h3>
  3. <p class="navigation menu">
  4. <?php if ($prev_node_url): ?>
  5. <a class="previous" href="<?php echo $prev_node_url; ?>"><span>&lt;</span></a>
  6. <a href="<?php echo $prev_node_url; ?>"><?php echo htmlspecialchars($prev_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
  7. <?php endif; ?>
  8. <?php if ($next_node_url and $prev_node_url): ?>
  9. &nbsp;|&nbsp;
  10. <?php endif; ?>
  11. <?php if ($next_node_url): ?>
  12. <a href="<?php echo $next_node_url; ?>"><?php echo htmlspecialchars($next_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
  13. <a class="next" href="<?php echo $next_node_url; ?>"><span>&gt;</span></a>
  14. <?php endif; ?>
  15. </p>
  16. <p class="info"><?php echo longdate_fr($sms_modified); ?> à <?php echo date('H:i', $sms_modified); ?></p>
  17. <?php if ($sms_subject): ?>
  18. <p><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></p>
  19. <?php endif; ?>
  20. <?php if ($sms_cloud): ?>
  21. <p class="small"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></p>
  22. <?php endif; ?>
  23. <h4>Message</h4>
  24. <?php if ($smscontents): ?>
  25. <div id="sms">
  26. <?php echo $smscontents; ?>
  27. </div>
  28. <?php else: ?>
  29. <p class="info"><span class="btn_edit btn_help" title="Aide"></span>
  30. Utilisez l'éditeur pour ajouter du contenu à votre message.</p>
  31. <?php endif; ?>

Edit the action client in the file actions/client.php to pass the URL of the action campaign to the view client:

  1.     $campaign_page = url('campaign', $lang);
  1.     $content=view('client', $lang, compact('campaign_page', 'info'));

Add a clickable image in the view client in English and in French:

  1. <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="Campaigns" title="Manage your campaigns" /></a></p>
  1. <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="Campagnes" title="Gérez vos campagnes" /></a></p>

Edit the action admin in the file actions/admin.php to pass the URL of the action campaign to the view admin:

  1.     $campaign_page=url('campaign', $lang);
  1.     $content = view('admin', $lang, compact('campaign_page', 'newuser_page', 'newsletter_page', 'traffic_page', 'balance', 'usersearch', 'upload'));

Add a clickable image in the view admin in English and in French:

  1. <?php if (!empty($campaign_page)): ?>
  2. <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="" title="Campaigns" /></a></p>
  3. <?php endif; ?>
  1. <?php if (!empty($campaign_page)): ?>
  2. <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="" title="Campagnes" /></a></p>
  3. <?php endif; ?>

Create the URL for the action campaign in English and in French in the file aliases.inc:

  1.         'campaign' => 'campaign',
  1.         'campagne' => 'campaign',

Translate the titles for the pages showing all the campaign owners, all the campaigns of a client, the content of a campaign, in English and in French in strings.inc:

  1.         'campaignall:title'     => 'Advertisers',
  2.         'campaignsummary:title' => 'Campaigns',
  3.         'campaignpage:title'    => 'SMS',
  1.         'campaignall:title'     => 'Annonceurs',
  2.         'campaignsummary:title' => 'Campagnes',
  3.         'campaignpage:title'    => 'SMS',

Copy the file phonelarge.png in the folder images/theme.

Test

Connect as an administrator. Enter in the management part of the site.

Management

Content

Click on the large phone.

Advertisers

  1. Bar Foo

Click on the client named Bar Foo in the list.

Bar Foo

  1. The web engine
Git
  1. /izendsms.com
    1. actions
      1. admin.php
      2. campaign.php
      3. campaignall.php
      4. campaignpage.php
      5. campaignsummary.php
      6. client.php
    2. images
      1. theme
        1. phonelarge.png
    3. includes
      1. aliases.inc
      2. strings.inc
    4. models
      1. sms.inc
    5. views
      1. campaignsummary.phtml
      2. en
        1. admin.phtml
        2. campaignall.phtml
        3. campaignpage.phtml
        4. client.phtml
      3. fr
        1. admin.phtml
        2. campaignall.phtml
        3. campaignpage.phtml
        4. client.phtml

Commit this version:

$ git status
$ git add actions/admin.php actions/campaign.php actions/campaignall.php actions/campaignpage.php actions/campaignsummary.php actions/client.php images/theme/phonelarge.png images/theme/phonesmall.png includes/aliases.inc includes/strings.inc models/sms.inc views/campaignsummary.phtml views/en/admin.phtml views/en/campaignall.phtml views/en/campaignpage.phtml views/en/client.phtml views/fr/admin.phtml views/fr/campaignall.phtml views/fr/campaignpage.phtml views/fr/client.phtml
$ git commit -m'Adds displaying campaigns'

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

Comments

To add a comment, click here.