Displaying campaigns
Code
Create the file campaign.php in the folder actions with the following content:
- require_once 'userhasrole.php';
- require_once 'userprofile.php';
- require_once 'models/sms.inc';
- function campaign($lang, $arglist=false) {
- $campaign=$page=false;
- if (is_array($arglist)) {
- if (isset($arglist[0])) {
- $campaign=$arglist[0];
- }
- if (isset($arglist[1])) {
- $page=$arglist[1];
- }
- }
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.
- if (!$campaign) {
- if (user_has_role('administrator')) {
- require_once 'actions/campaignall.php';
- return campaignall($lang);
- }
- $user_id=user_profile('id');
- if (!$user_id) {
- return run('error/unauthorized', $lang);
- }
- $campaign=sms_get_user_campaign_id($user_id);
- if (!$campaign) {
- return run('error/notfound', $lang);
- }
- }
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.
- if (!$page) {
- require_once 'actions/campaignsummary.php';
- return campaignsummary($lang, $campaign);
- }
- require_once 'actions/campaignpage.php';
- return campaignpage($lang, $campaign, $page);
- }
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:
- function sms_get_user_campaign_id($user_id) {
- $tabthread=db_prefix_table('thread');
- $sql="SELECT thread_id FROM $tabthread WHERE thread_type='campaign' AND user_id=$user_id";
- $r = db_query($sql);
- return $r ? $r[0]['thread_id'] : false;
- }
The function sms_get_user_campaign_id
returns the number of the campaign thread of a user.
- function sms_list_campaign_users($lang) {
- $sqllang=db_sql_arg($lang, false);
- $tabthread=db_prefix_table('thread');
- $tabthreadlocale=db_prefix_table('thread_locale');
- $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";
- $r = db_query($sql);
- if (!$r) {
- return false;
- }
- $thread_list = array();
- $url = url('campaign', $lang);
- foreach ($r as $thread) {
- extract($thread); /* thread_id thread_name thread_title thread_abstract thread_cloud thread_number */
- $thread_url = $url . '/' . $thread_id;
- $thread_list[] = compact('thread_number', 'thread_id', 'thread_title', 'thread_abstract', 'thread_cloud', 'thread_url');
- }
- return $thread_list;
- }
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:
- require_once 'userhasrole.php';
- require_once 'models/sms.inc';
- function campaignall($lang) {
- global $with_toolbar;
- if (!user_has_role('administrator')) {
- return run('error/unauthorized', $lang);
- }
- head('title', translate('campaignall:title', $lang));
- head('description', false);
- head('keywords', false);
- head('robots', 'noindex, nofollow');
- $admin=true;
- $banner = build('banner', $lang, $with_toolbar ? false : compact('admin'));
- $toolbar = $with_toolbar ? build('toolbar', $lang, compact('admin')) : false;
- $campaign_list = sms_list_campaign_users($lang);
- $content = view('campaignall', $lang, compact('campaign_list'));
- $output = layout('standard', compact('toolbar', 'banner', 'content'));
- return $output;
- }
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:
- <h3>Advertisers</h3>
- <?php if (!empty($campaign_list)): ?>
- <ol>
- <?php foreach ($campaign_list as $thread):
- extract($thread); /* thread_id thread_name thread_title thread_url */
- ?>
- <li><a href="<?php echo $thread_url; ?>"><span><?php echo htmlspecialchars($thread_title ? $thread_title : $thread_id, ENT_COMPAT, 'UTF-8'); ?></span></a></li>
- <?php endforeach; ?>
- </ol>
- <?php endif; ?>
- <h3>Annonceurs</h3>
- <?php if (!empty($campaign_list)): ?>
- <ol>
- <?php foreach ($campaign_list as $thread):
- extract($thread); /* thread_id thread_name thread_title thread_url */
- ?>
- <li><a href="<?php echo $thread_url; ?>"><span><?php echo htmlspecialchars($thread_title ? $thread_title : $thread_id, ENT_COMPAT, 'UTF-8'); ?></span></a></li>
- <?php endforeach; ?>
- </ol>
- <?php endif; ?>
Create the file campaignsummary.php in the folder actions with the following content:
- require_once 'userhasrole.php';
- require_once 'userprofile.php';
- require_once 'models/thread.inc';
- function campaignsummary($lang, $campaign) {
- global $with_toolbar;
- $user_id=user_profile('id');
- if (!$user_id) {
- return run('error/unauthorized', $lang);
- }
- $campaign_id = thread_id($campaign);
- if (!$campaign_id) {
- return run('error/notfound', $lang);
- }
- $r = thread_get($lang, $campaign_id);
- if (!$r) {
- return run('error/notfound', $lang);
- }
- extract($r); /* thread_user_id thread_type thread_name thread_title thread_abstract thread_cloud thread_nocloud thread_nosearch */
- if ($thread_type != 'campaign') {
- return run('error/notfound', $lang);
- }
- if ($thread_user_id != $user_id and !user_has_role('administrator')) {
- return run('error/notfound', $lang);
- }
- $campaign_name = $thread_name;
- $campaign_title = $thread_title;
- $campaign_abstract = $thread_abstract;
- $campaign_cloud = $thread_cloud;
- $campaign_modified= $thread_modified;
- $campaign_nocloud = $thread_nocloud;
- $campaign_nosearch = $thread_nosearch;
- if ($campaign_title) {
- head('title', $campaign_title);
- }
- else {
- head('title', translate('campaignall:title', $lang));
- }
- head('description', false);
- head('keywords', false);
- head('robots', 'noindex, nofollow');
- $campaign_contents = array();
- $r = thread_get_contents($lang, $campaign_id);
- if ($r) {
- $campaign_url = url('campaign', $lang);
- foreach ($r as $c) {
- extract($c); /* node_id node_name node_title node_number */
- $page_id = $node_id;
- $page_title = $node_title;
- $page_url = $campaign_url . '/' . $campaign_id . '/' . $node_id;
- $campaign_contents[] = compact('page_id', 'page_title', 'page_url');
- }
- }
- $content = view('campaignsummary', false, compact('campaign_id', 'campaign_title', 'campaign_abstract', 'campaign_contents'));
- $search=false;
- if (!$campaign_nosearch) {
- $search_text='';
- $search_url= url('search', $lang, $campaign_id);
- $suggest_url= url('suggest', $lang, $campaign_id);
- $search=view('searchinput', $lang, compact('search_url', 'search_text', 'suggest_url'));
- }
- $cloud=false;
- if (!$campaign_nocloud) {
- $cloud_url= url('search', $lang, $campaign_id);
- $byname=$bycount=$index=true;
- $cloud = build('cloud', $lang, $cloud_url, $campaign_id, false, 30, compact('byname', 'bycount', 'index'));
- }
- $headline_text= translate('campaignsummary:title', $lang);
- $headline_url=user_has_role('administrator') ? url('campaign', $lang) : false;
- $headline = compact('headline_text', 'headline_url');
- $title = view('headline', false, $headline);
- $sidebar = view('sidebar', false, compact('search', 'cloud', 'title'));
- $search=!$thread_nosearch ? compact('search_url', 'search_text', 'suggest_url') : false;
- $edit=false;
- $banner = build('banner', $lang, $with_toolbar ? compact('headline', 'search') : compact('headline', 'edit', 'search'));
- $toolbar = $with_toolbar ? build('toolbar', $lang, compact('edit')) : false;
- $output = layout('standard', compact('sharebar', 'toolbar', 'banner', 'sidebar', 'content'));
- return $output;
- }
Create the view campaignsummary
in the file views/campaignsummary.phtml:
- <div id="campaignsummary">
- <h3><?php echo htmlspecialchars($campaign_title ? $campaign_title : $campaign_id, ENT_COMPAT, 'UTF-8'); ?></h3>
- <?php if ($campaign_abstract): ?>
- <p><?php echo htmlspecialchars($campaign_abstract, ENT_COMPAT, 'UTF-8'); ?></p>
- <?php endif; ?>
- <?php if ($campaign_contents): ?>
- <ol>
- <?php foreach ($campaign_contents as $c): ?>
- <?php extract($c); /* page_title page_url */ ?>
- <li><a href="<?php echo $page_url; ?>"><?php echo htmlspecialchars($page_title ? $page_title : $page_id, ENT_COMPAT, 'UTF-8'); ?></a></li>
- <?php endforeach; ?>
- </ol>
- <?php endif; ?>
- </div>
Create the file campaignpage.php in the folder actions with the following content:
- require_once 'userhasrole.php';
- require_once 'userprofile.php';
- require_once 'models/thread.inc';
- function campaignpage($lang, $thread, $node) {
- global $with_toolbar;
- $user_id=user_profile('id');
- if (!$user_id) {
- return run('error/unauthorized', $lang);
- }
- $thread_id = thread_id($thread);
- if (!$thread_id) {
- return run('error/notfound', $lang);
- }
- $node_id = thread_node_id($thread_id, $node, $lang);
- if (!$node_id) {
- return run('error/notfound', $lang);
- }
- $r = thread_get($lang, $thread_id);
- if (!$r) {
- return run('error/notfound', $lang);
- }
- extract($r); /* thread_user_id thread_type thread_name thread_title thread_abstract thread_cloud thread_nocloud thread_nosearch thread_nocomment thread_nomorecomment */
- if ($thread_type != 'campaign') {
- return run('error/notfound', $lang);
- }
- if ($thread_user_id != $user_id and !user_has_role('administrator')) {
- return run('error/notfound', $lang);
- }
- $r = thread_get_node($lang, $thread_id, $node_id);
- if (!$r) {
- return run('error/notfound', $lang);
- }
- 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 */
- $sms_user_id=$node_user_id;
- $sms_name=$node_name;
- $sms_title=$node_title;
- $sms_subject=$node_abstract;
- $sms_cloud=$node_cloud;
- $sms_image=$node_image;
- $sms_number=$node_number;
- $sms_modified=$node_modified;
- $smscontents = build('nodecontent', $lang, $node_id);
- if ($sms_title) {
- head('title', $sms_title);
- }
- else if ($thread_title) {
- head('title', $thread_title);
- }
- else {
- head('title', translate('campaignpage:title', $lang));
- }
- head('description', false);
- head('keywords', false);
- head('robots', 'noindex, nofollow');
- $prev_node_label=$prev_node_url=false;
- $r=thread_node_prev($lang, $thread_id, $node_id);
- if ($r) {
- extract($r); /* prev_node_id prev_node_name prev_node_title prev_node_number */
- $prev_node_label = $prev_node_title ? $prev_node_title : $prev_node_number;
- $prev_node_url=url('campaign', $lang) . '/' . $thread_id . '/'. $prev_node_id;
- }
- $next_node_label=$next_node_url=false;
- $r=thread_node_next($lang, $thread_id, $node_id);
- if ($r) {
- extract($r); /* next_node_id next_node_name next_node_title next_node_number */
- $next_node_label = $next_node_title ? $next_node_title : $next_node_number;
- $next_node_url=url('campaign', $lang) . '/' . $thread_id . '/'. $next_node_id;
- }
- $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'));
- $search=false;
- if (!$thread_nosearch) {
- $search_text='';
- $search_url= url('search', $lang, $thread_id);
- $suggest_url= url('suggest', $lang, $thread_id);
- $search=view('searchinput', $lang, compact('search_url', 'search_text', 'suggest_url'));
- }
- $cloud=false;
- if (!$thread_nocloud) {
- $cloud_url= url('search', $lang, $thread_id);
- $byname=$bycount=$index=true;
- $cloud = build('cloud', $lang, $cloud_url, $thread_id, false, 15, compact('byname', 'bycount', 'index'));
- }
- $headline_text=translate('campaignsummary:title', $lang);
- $headline_url=url('campaign', $lang) . '/' . $thread_id;
- $headline = compact('headline_text', 'headline_url');
- $title = view('headline', false, $headline);
- $sidebar = view('sidebar', false, compact('search', 'cloud', 'title'));
- $search=!$thread_nosearch ? compact('search_url', 'search_text', 'suggest_url') : false;
- $edit=false;
- $banner = build('banner', $lang, $with_toolbar ? compact('headline', 'search') : compact('headline', 'edit', 'search'));
- $toolbar = $with_toolbar ? build('toolbar', $lang, compact('edit')) : false;
- $output = layout('standard', compact('toolbar', 'banner', 'content', 'sidebar'));
- return $output;
- }
Create the view campaignpage
in English and in French in the files views/en/campaignpage.phtml and views/fr/campaignpage.phtml:
- <?php require_once 'dateen.php'; ?>
- <h3><?php echo htmlspecialchars($sms_title ? $sms_title : $node_id, ENT_COMPAT, 'UTF-8'); ?></h3>
- <p class="navigation menu">
- <?php if ($prev_node_url): ?>
- <a class="previous" href="<?php echo $prev_node_url; ?>"><span><</span></a>
- <a href="<?php echo $prev_node_url; ?>"><?php echo htmlspecialchars($prev_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
- <?php endif; ?>
- <?php if ($next_node_url and $prev_node_url): ?>
- |
- <?php endif; ?>
- <?php if ($next_node_url): ?>
- <a href="<?php echo $next_node_url; ?>"><?php echo htmlspecialchars($next_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
- <a class="next" href="<?php echo $next_node_url; ?>"><span>></span></a>
- <?php endif; ?>
- </p>
- <p class="info"><?php echo longdate_en($sms_modified); ?> at <?php echo date('H:i', $sms_modified); ?></p>
- <?php if ($sms_subject): ?>
- <p><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></p>
- <?php endif; ?>
- <?php if ($sms_cloud): ?>
- <p class="small"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></p>
- <?php endif; ?>
- <h4>Message</h4>
- <?php if ($smscontents): ?>
- <div id="sms">
- <?php echo $smscontents; ?>
- </div>
- <?php else: ?>
- <p class="info"><span class="btn_edit btn_help" title="Aide"></span>
- Use the editor to add some content to your message.</p>
- <?php endif; ?>
- <?php require_once 'datefr.php'; ?>
- <h3><?php echo htmlspecialchars($sms_title ? $sms_title : $node_id, ENT_COMPAT, 'UTF-8'); ?></h3>
- <p class="navigation menu">
- <?php if ($prev_node_url): ?>
- <a class="previous" href="<?php echo $prev_node_url; ?>"><span><</span></a>
- <a href="<?php echo $prev_node_url; ?>"><?php echo htmlspecialchars($prev_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
- <?php endif; ?>
- <?php if ($next_node_url and $prev_node_url): ?>
- |
- <?php endif; ?>
- <?php if ($next_node_url): ?>
- <a href="<?php echo $next_node_url; ?>"><?php echo htmlspecialchars($next_node_label, ENT_COMPAT, 'UTF-8'); ?></a>
- <a class="next" href="<?php echo $next_node_url; ?>"><span>></span></a>
- <?php endif; ?>
- </p>
- <p class="info"><?php echo longdate_fr($sms_modified); ?> à <?php echo date('H:i', $sms_modified); ?></p>
- <?php if ($sms_subject): ?>
- <p><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></p>
- <?php endif; ?>
- <?php if ($sms_cloud): ?>
- <p class="small"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></p>
- <?php endif; ?>
- <h4>Message</h4>
- <?php if ($smscontents): ?>
- <div id="sms">
- <?php echo $smscontents; ?>
- </div>
- <?php else: ?>
- <p class="info"><span class="btn_edit btn_help" title="Aide"></span>
- Utilisez l'éditeur pour ajouter du contenu à votre message.</p>
- <?php endif; ?>
Edit the action client
in the file actions/client.php to pass the URL of the action campaign
to the view client
:
- $campaign_page = url('campaign', $lang);
- $content=view('client', $lang, compact('campaign_page', 'info'));
Add a clickable image in the view client
in English and in French:
- <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>
- <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
:
- $campaign_page=url('campaign', $lang);
- $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:
- <?php if (!empty($campaign_page)): ?>
- <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="" title="Campaigns" /></a></p>
- <?php endif; ?>
- <?php if (!empty($campaign_page)): ?>
- <p class="vignette"><a href="<?php echo $campaign_page; ?>" rel="nofollow"><img src="/images/theme/phonelarge.png" alt="" title="Campagnes" /></a></p>
- <?php endif; ?>
Create the URL for the action campaign
in English and in French in the file aliases.inc:
- 'campaign' => 'campaign',
- '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:
- 'campaignall:title' => 'Advertisers',
- 'campaignsummary:title' => 'Campaigns',
- 'campaignpage:title' => 'SMS',
- 'campaignall:title' => 'Annonceurs',
- 'campaignsummary:title' => 'Campagnes',
- '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
Click on the client named Bar Foo in the list.
Bar Foo
Git
- /izendsms.com
- actions
- admin.php
- campaign.php
- campaignall.php
- campaignpage.php
- campaignsummary.php
- client.php
- images
- theme
- phonelarge.png
- theme
- includes
- aliases.inc
- strings.inc
- models
- sms.inc
- views
- campaignsummary.phtml
- en
- admin.phtml
- campaignall.phtml
- campaignpage.phtml
- client.phtml
- fr
- admin.phtml
- campaignall.phtml
- campaignpage.phtml
- client.phtml
- actions
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