[ Index ] [ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

PHP Cross Reference of TXP stable 4.0.6

title

Body

[close]

/textpattern/include/ -> txp_admin.php (source)

   1  <?php
   2  
   3  /*
   4      This is Textpattern
   5  
   6      Copyright 2005 by Dean Allen
   7      www.textpattern.com
   8      All rights reserved
   9  
  10      Use of this software indicates acceptance of the Textpattern license agreement
  11  
  12  $HeadURL: http://svn.textpattern.com/releases/4.0.6/source/textpattern/include/txp_admin.php $
  13  $LastChangedRevision: 2729 $
  14  
  15  */
  16  
  17      if (!defined('txpinterface'))
  18      {
  19          die('txpinterface is undefined.');
  20      }
  21  
  22      $levels = array(
  23          1 => gTxt('publisher'),
  24          2 => gTxt('managing_editor'),
  25          3 => gTxt('copy_editor'),
  26          4 => gTxt('staff_writer'),
  27          5 => gTxt('freelancer'),
  28          6 => gTxt('designer'),
  29          0 => gTxt('none')
  30      );
  31  
  32      if ($event == 'admin')
  33      {
  34          require_privs('admin');
  35  
  36          include_once txpath.'/lib/txplib_admin.php';
  37  
  38          $available_steps = array(
  39              'admin',
  40              'author_change_pass',
  41              'author_delete',
  42              'author_list',
  43              'author_save',
  44              'author_save_new',
  45              'change_email',
  46              'change_pass'
  47          );
  48  
  49          if (!$step or !in_array($step, $available_steps))
  50          {
  51              admin();
  52          }
  53  
  54          else
  55          {
  56              $step();
  57          }
  58      }
  59  
  60  // -------------------------------------------------------------
  61  
  62  	function admin($message = '')
  63      {
  64          global $txp_user;
  65  
  66          pagetop(gTxt('site_administration'), $message);
  67  
  68          if (!is_callable('mail'))
  69          {
  70              echo tag(gTxt('warn_mail_unavailable'), 'p',' id="warning" ');
  71          }
  72  
  73          $email = fetch('email', 'txp_users', 'name', $txp_user);
  74  
  75          echo new_pass_form().
  76              change_email_form($email);
  77  
  78          if (has_privs('admin.list'))
  79          {
  80              echo author_list();
  81          }
  82  
  83          if (has_privs('admin.edit'))
  84          {
  85              echo new_author_form().
  86                  reset_author_pass_form();
  87          }
  88      }
  89  
  90  // -------------------------------------------------------------
  91  
  92  	function change_email()
  93      {
  94          global $txp_user;
  95  
  96          $new_email = gps('new_email');
  97  
  98          if (!is_valid_email($new_email))
  99          {
 100              admin(gTxt('email_required'));
 101              return;
 102          }
 103  
 104          $rs = safe_update('txp_users', "email = '".doSlash($new_email)."'", "name = '".doSlash($txp_user)."'");
 105  
 106          if ($rs)
 107          {
 108              admin(
 109                  gTxt('email_changed', array('{email}' => $new_email))
 110              );
 111          }
 112      }
 113  
 114  // -------------------------------------------------------------
 115  
 116  	function author_save()
 117      {
 118          require_privs('admin.edit');
 119  
 120          extract(doSlash(psa(array('privs', 'user_id', 'RealName', 'email'))));
 121          $privs   = assert_int($privs);
 122          $user_id = assert_int($user_id);
 123  
 124          if (!is_valid_email($email))
 125          {
 126              admin(gTxt('email_required'));
 127              return;
 128          }
 129  
 130          $rs = safe_update('txp_users', "
 131              privs         = $privs,
 132              RealName = '$RealName',
 133              email         = '$email'",
 134              "user_id = $user_id"
 135          );
 136  
 137          if ($rs)
 138          {
 139              admin(
 140                  gTxt('author_updated', array('{name}' => $RealName))
 141              );
 142          }
 143      }
 144  
 145  // -------------------------------------------------------------
 146  
 147  	function change_pass()
 148      {
 149          global $txp_user;
 150  
 151          extract(doSlash(psa(array('new_pass', 'mail_password'))));
 152  
 153          if (empty($new_pass))
 154          {
 155              admin(gTxt('password_required'));
 156              return;
 157          }
 158  
 159          $rs = safe_update('txp_users', "pass = password(lower('$new_pass'))", "name = '".doSlash($txp_user)."'");
 160  
 161          if ($rs)
 162          {
 163              $message = gTxt('password_changed');
 164  
 165              if ($mail_password)
 166              {
 167                  $email = fetch('email', 'txp_users', 'name', $txp_user);
 168  
 169                  send_new_password($new_pass, $email, $txp_user);
 170  
 171                  $message .= sp.gTxt('and_mailed_to').sp.$email;
 172              }
 173  
 174              else
 175              {
 176                  echo comment(mysql_error());
 177              }
 178  
 179              $message .= '.';
 180  
 181              admin($message);
 182          }
 183      }
 184  
 185  // -------------------------------------------------------------
 186  
 187  	function author_save_new()
 188      {
 189          require_privs('admin.edit');
 190  
 191          extract(doSlash(psa(array('privs', 'name', 'email', 'RealName'))));
 192          $privs = assert_int($privs);
 193  
 194          if ($name && is_valid_email($email))
 195          {
 196              $password = doSlash(generate_password(6));
 197              $nonce    = doSlash(md5(uniqid(mt_rand(), TRUE)));
 198  
 199              $rs = safe_insert('txp_users', "
 200                  privs    = $privs,
 201                  name     = '$name',
 202                  email    = '$email',
 203                  RealName = '$RealName',
 204                  nonce    = '$nonce',
 205                  pass     = password(lower('$password'))
 206              ");
 207  
 208              if ($rs)
 209              {
 210                  send_password($RealName, $name, $email, $password);
 211  
 212                  admin(
 213                      gTxt('password_sent_to').sp.$email
 214                  );
 215  
 216                  return;
 217              }
 218          }
 219  
 220          admin(gTxt('error_adding_new_author'));
 221      }
 222  
 223  // -------------------------------------------------------------
 224  
 225  	function privs($priv = '')
 226      {
 227          global $levels;
 228          return selectInput('privs', $levels, $priv);
 229      }
 230  
 231  // -------------------------------------------------------------
 232  
 233  	function get_priv_level($priv)
 234      {
 235          global $levels;
 236          return $levels[$priv];
 237      }
 238  
 239  // -------------------------------------------------------------
 240  
 241  	function new_pass_form()
 242      {
 243          return '<div style="margin: 3em auto auto auto; text-align: center;">'.
 244          form(
 245              tag(gTxt('change_password'), 'h3').
 246  
 247              graf('<label for="new_pass">'.gTxt('new_password').'</label> '.
 248                  fInput('password', 'new_pass', '', 'edit', '', '', '20', '1', 'new_pass').
 249                  checkbox('mail_password', '1', true, '', 'mail_password').'<label for="mail_password">'.gTxt('mail_it').'</label> '.
 250                  fInput('submit', 'change_pass', gTxt('submit'), 'smallerbox').
 251                  eInput('admin').
 252                  sInput('change_pass')
 253              ,' style="text-align: center;"')
 254          ).'</div>';
 255      }
 256  
 257  // -------------------------------------------------------------
 258  
 259  	function reset_author_pass_form()
 260      {
 261          global $txp_user;
 262  
 263          $names = array();
 264  
 265          $them = safe_rows_start('*', 'txp_users', "name != '".doSlash($txp_user)."'");
 266  
 267          while ($a = nextRow($them))
 268          {
 269              extract($a);
 270  
 271              $names[$name] = $RealName.' ('.$name.')';
 272          }
 273  
 274          if ($names)
 275          {
 276              return '<div style="margin: 3em auto auto auto; text-align: center;">'.
 277              form(
 278                  tag(gTxt('reset_author_password'), 'h3').
 279                  graf(gTxt('a_new_password_will_be_mailed')).
 280                      graf(selectInput('name', $names, '', 1).
 281                      fInput('submit', 'author_change_pass', gTxt('submit'), 'smallerbox').
 282                      eInput('admin').
 283                      sInput('author_change_pass')
 284                  ,' style="text-align: center;"')
 285              ).'</div>';
 286          }
 287      }
 288  
 289  // -------------------------------------------------------------
 290  
 291  	function author_change_pass()
 292      {
 293          require_privs('admin.edit');
 294  
 295          admin(reset_author_pass(ps('name')));
 296      }
 297  
 298  // -------------------------------------------------------------
 299  
 300  	function change_email_form($email)
 301      {
 302          return '<div style="margin: 3em auto auto auto; text-align: center;">'.
 303          form(
 304              tag(gTxt('change_email_address'), 'h3').
 305              graf('<label for="new_email">'.gTxt('new_email').'</label> '.
 306                  fInput('text', 'new_email', $email, 'edit', '', '', '20', '2', 'new_email').
 307                  fInput('submit', 'change_email', gTxt('submit'), 'smallerbox').
 308                  eInput('admin').
 309                  sInput('change_email')
 310              ,' style="text-align: center;"')
 311          ).'</div>';
 312      }
 313  
 314  // -------------------------------------------------------------
 315  
 316  	function author_list()
 317      {
 318          global $txp_user;
 319  
 320          echo n.n.hed(gTxt('authors'), 3,' style="text-align: center;"').
 321  
 322              n.n.startTable('list').
 323  
 324              n.tr(
 325                  n.hCell(gTxt('real_name')).
 326                  n.hCell(gTxt('login_name')).
 327                  n.hCell(gTxt('email')).
 328                  n.hCell(gTxt('privileges')).
 329                  n.hCell().
 330                  n.hCell()
 331              );
 332  
 333          $rs = safe_rows_start('*', 'txp_users', '1 = 1 order by name asc');
 334  
 335          if ($rs)
 336          {
 337              if (has_privs('admin.edit'))
 338              {
 339                  while ($a = nextRow($rs))
 340                  {
 341                      extract($a);
 342  
 343                      echo n.n.'<tr>'.
 344  
 345                          n.'<form method="post" action="index.php">'.
 346  
 347                          n.td(
 348                              fInput('text', 'RealName', $RealName, 'edit')
 349                          ).
 350  
 351                          td(htmlspecialchars($name)).
 352                          td(
 353                              fInput('text', 'email', $email, 'edit')
 354                          );
 355  
 356                      if ($name != $txp_user)
 357                      {
 358                          echo td(
 359                              privs($privs).sp.popHelp('about_privileges')
 360                          );
 361                      }
 362  
 363                      else
 364                      {
 365                          echo td(
 366                              get_priv_level($privs).sp.popHelp('about_privileges').
 367                              hInput('privs', $privs)
 368                          );
 369                      }
 370  
 371                      echo td(
 372                          fInput('submit', 'save', gTxt('save'), 'smallerbox')
 373                      ).
 374  
 375                      n.hInput('user_id', $user_id).
 376                      n.eInput('admin').
 377                      n.sInput('author_save').
 378                      n.'</form>';
 379  
 380                      if ($name != $txp_user)
 381                      {
 382                          echo td(
 383                              dLink('admin', 'author_delete', 'user_id', $user_id)
 384                          );
 385                      }
 386  
 387                      else
 388                      {
 389                          echo td();
 390                      }
 391  
 392                      echo n.'</tr>';
 393                  }
 394              }
 395  
 396              else
 397              {
 398                  while ($a = nextRow($rs))
 399                  {
 400                      extract(doSpecial($a));
 401  
 402                      echo tr(
 403                          td($RealName).
 404                          td($name).
 405                          td('<a href="mailto:'.$email.'">'.$email.'</a>').
 406                          td(
 407                              get_priv_level($privs).sp.popHelp('about_privileges').
 408                              hInput('privs', $privs)
 409                          ).
 410                          td().
 411                          td()
 412                      );
 413                  }
 414              }
 415  
 416              echo n.endTable();
 417          }
 418      }
 419  
 420  // -------------------------------------------------------------
 421  
 422  	function author_delete()
 423      {
 424          require_privs('admin.edit');
 425  
 426          $user_id = assert_int(ps('user_id'));
 427  
 428          $name = fetch('Realname', 'txp_users', 'user_id', $user_id);
 429  
 430          if ($name)
 431          {
 432              $rs = safe_delete('txp_users', "user_id = $user_id");
 433  
 434              if ($rs)
 435              {
 436                  admin(
 437                      gTxt('author_deleted', array('{name}' => $name))
 438                  );
 439              }
 440          }
 441      }
 442  
 443  // -------------------------------------------------------------
 444  
 445  	function new_author_form()
 446      {
 447          return form(
 448              hed(gTxt('add_new_author'), 3,' style="margin-top: 2em; text-align: center;"').
 449              graf(gTxt('a_message_will_be_sent_with_login'), ' style="text-align: center;"').
 450  
 451              startTable('edit').
 452              tr(
 453                  fLabelCell('real_name').
 454                  fInputCell('RealName')
 455              ).
 456  
 457              tr(
 458                  fLabelCell('login_name').
 459                  fInputCell('name')
 460              ).
 461  
 462              tr(
 463                  fLabelCell('email').
 464                  fInputCell('email')
 465              ).
 466  
 467              tr(
 468                  fLabelCell('privileges').
 469                  td(
 470                      privs().sp.popHelp('about_privileges')
 471                  )
 472              ).
 473  
 474              tr(
 475                  td().
 476                  td(
 477                      fInput('submit', '', gTxt('save'), 'publish').sp.popHelp('add_new_author')
 478                  )
 479              ).
 480  
 481              endTable().
 482  
 483              eInput('admin').
 484              sInput('author_save_new')
 485          );
 486      }
 487  
 488  ?>


Generated: Mon Feb 18 03:42:45 2008 Cross-referenced by PHPXref 0.7