3
9

Client space

In the table role of the DB, add the role client:

INSERT INTO `izendsms_role` (`role_id`, `name`) VALUES (NULL, 'client');

IMPORTANT: Change the table prefix of the DB if it's not izendsms_.

Code

Rename the file actions/home.php to actions/main.php.

Edit the file actions/main.php. Rename the function main.

Recreate the file actions/home.php with the following content:

  1. require_once 'userhasrole.php';
  2.  
  3. function home($lang) {
  4.     if (user_has_role('client')) {
  5.         return run('client', $lang);
  6.     }
  7.  
  8.     return run('main', $lang);
  9. }

Runs the action client if the user is connected as a client or the action main by default.

Create the file actions/client.php with the following content:

  1. function client($lang) {
  2.     head('title', translate('client:title', $lang));
  3.  
  4.     $banner = build('banner', $lang);
  5.  
  6.     $info = build('clientinfo', $lang);
  7.  
  8.     $content=view('client', $lang, compact('info'));
  9.  
  10.     $output = layout('standard', compact('banner', 'content'));
  11.  
  12.     return $output;
  13. }

Add the translation of the title of the page in the file includes/strings.inc in English and in French:

  1.         'client:title'          => 'Client',
  1.         'client:title'          => 'Client',

The block clientinfo details a client's account. Create the file blocks/clientinfo.php with the following content:

  1. require_once 'userprofile.php';
  2.  
  3. function clientinfo($lang) {
  4.     $name=user_profile('name');
  5.     $mail=user_profile('mail');
  6.  
  7.     $account_page=url('account', $lang);
  8.  
  9.     $output = view('clientinfo', $lang, compact('name', 'mail', 'account_page'));
  10.  
  11.     return $output;
  12. }

Add the file views/en/clientinfo.phtml:

  1. <p><span id="clientname" title="Identification"><?php echo $name; ?></span>
  2. <img src="<?php echo $base_path; ?>/avatars/<?php echo $name; ?>.png" alt="" title="<?php echo $name; ?>" />
  3. <span id="clientmail" title="Email"><?php echo $mail; ?></span></p>
  4. <p class="info noprint">To modify your identifier, your email or change your password, <a href="<?php echo $account_page; ?>" title="Modify your personal information">click here</a>.</p>

Add the file views/fr/clientinfo.phtml:

  1. <p><span id="clientname" title="Identification"><?php echo $name; ?></span>
  2. <img src="<?php echo $base_path; ?>/avatars/<?php echo $name; ?>.png" alt="" title="<?php echo $name; ?>" />
  3. <span id="clientmail" title="Email"><?php echo $mail; ?></span></p>
  4. <p class="info noprint">Pour modifier votre identifiant, votre email ou changer votre mot de passe, <a href="<?php echo $account_page; ?>" title="Modifiez vos informations personnelles">cliquez ici</a>.</p>

Add the CSS for the identifier and the email address at the end of the file css/theme.css:

Add the file views/en/client.phtml:

  1. <h3>Your account</h3>
  2. <?php echo $info; ?>

Add the file views/fr/client.phtml:

  1. <h3>Votre compte</h3>
  2. <?php echo $info; ?>

Add the role client to the configuration parameter $supported_roles in includes/config.inc:

  1. $supported_roles=array('administrator', 'writer', 'reader', 'moderator', 'client');

Add the translation of the role client in the files views/en/useredit.phtml et views/fr/useredit.phtml:

  1. <?php $rolename=array('administrator' => 'administrator', 'writer' => 'writer', 'reader' => 'reader', 'moderator' => 'moderator', 'client' => 'client'); ?>
  1. <?php $rolename=array('administrator' => 'administrateur', 'writer' => 'rédacteur', 'reader' => 'lecteur', 'moderator' => 'modérateur', 'client' => 'client'); ?>

Authorize a user to modify his password in the file blocks/useredit.php:

  1.     $with_newpassword=($user_id != 1 and $is_owner);

Systematically create a user account for a client in the file blocks/register.php:

  1.             $user_id = $r;
  2.  
  3.             user_set_role($user_id, 'client');
Test

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

Create an account for the user barfoo with the password barf00.

Go back to the administrative part. Search for the user barfoo and edit his profile. Verify that the role client is checked.

 administrator  writer  reader  moderator  client

Connect as a client with the identifier barfoo. The home page of the site displays the client space.

Your account

barfoo barfoo@izendsms.com

To modify your identifier, your email or change your password, click here.

Git
  1. /izendsms.com
    1. avatars
      1. barfoo.png
    2. actions
      1. client.php
      2. home.php
      3. main.php
    3. blocks
      1. clientinfo.php
      2. register.php
      3. useredit.php
    4. css
      1. theme.css
    5. includes
      1. config.inc
      2. strings.inc
    6. views
      1. en
        1. client.phtml
        2. clientinfo.phtml
        3. useredit.phtml
      2. fr
        1. client.phtml
        2. clientinfo.phtml
        3. useredit.phtml

Commit this version:

$ git status
$ git add --update
$ git commit -m'Creates client space'

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

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].