[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/registration/inc/ -> class.uireg.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Registration                                                *
   4      * http://www.egroupware.org                                                *
   5      * This application written by Joseph Engo <jengo@phpgroupware.org>         *
   6      * Modified by Jason Wies (Zone) <zone@users.sourceforge.net>               *
   7      * Modified by Loic Dachary <loic@gnu.org>                                  *
   8      * Modified by Pim Snel <pim@egroupware.org>                                *
   9      * --------------------------------------------                             *
  10      * Funding for this program was provided by http://www.checkwithmom.com     *
  11      * --------------------------------------------                             *
  12      *  This program is free software; you can redistribute it and/or modify it *
  13      *  under the terms of the GNU General Public License as published by the   *
  14      *  Free Software Foundation; either version 2 of the License, or (at your  *
  15      *  option) any later version.                                              *
  16      \**************************************************************************/
  17  
  18      /* $Id: class.uireg.inc.php 20049 2005-11-29 12:08:25Z nelius_weiss $ */
  19  
  20      class uireg
  21      {
  22          var $template;
  23          var $bomanagefields;
  24          var $fields;
  25          var $bo;
  26          var $lang_code;
  27          var $public_functions = array(
  28              'welcome_screen' => True,
  29              'step1'   => True,
  30              'step2'   => True,
  31              'lostpw1' => True,
  32              'lostpw3' => True,
  33              'lostpw4' => True,
  34              'lostid1' => True,
  35              'ready_to_activate' => True,
  36              'email_sent_lostpw' => True,
  37              'tos'     => True
  38          );
  39  
  40  		function uireg()
  41          {
  42              $this->template = $GLOBALS['egw']->template;
  43              $this->bo =& CreateObject ('registration.boreg');
  44              $this->bomanagefields =& CreateObject ('registration.bomanagefields');
  45              $this->fields = $this->bomanagefields->get_field_list ();
  46  
  47              $this->set_lang_code();
  48  
  49              $var = Array (
  50                  'website_title' => $GLOBALS['egw_info']['server']['site_title'] .'[Registration]',
  51                  'img_icon' => substr($GLOBALS['egw_info']['server']['login_logo_file'],0,4) == 'http' ? 
  52                      $GLOBALS['egw_info']['server']['login_logo_file'] :
  53                      $GLOBALS['egw']->common->image('phpgwapi',$GLOBALS['egw_info']['server']['login_logo_file'] ? 
  54                          $GLOBALS['egw_info']['server']['login_logo_file'] : 'logo'),
  55                  'logo_url' => $GLOBALS['egw_info']['server']['login_logo_url']?$GLOBALS['egw_info']['server']['login_logo_url']:'http://www.eGroupWare.org',
  56                  'logo_title' => $GLOBALS['egw_info']['server']['login_logo_title']?$GLOBALS['egw_info']['server']['login_logo_title']:'www.eGroupWare.org',
  57              ) ;
  58              $this->template->set_var($var) ;
  59          }
  60  
  61  		function set_lang_code($code='')
  62          {
  63              if($code)
  64              {
  65                  $this->lang_code=$code;
  66              }
  67              elseif(strlen($_GET['lang_code'])==2)
  68              {
  69                  $this->lang_code=$_GET['lang_code'];
  70              }
  71              else//if($_POST]['lang_code']==2)
  72              {
  73                  $this->lang_code=$_POST['lang_code'];
  74              }
  75  
  76              if ($this->lang_code)
  77              {
  78                  $GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $this->lang_code;
  79                  $GLOBALS['egw']->translation->init();    
  80              }
  81              else
  82              {
  83                  $GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $GLOBALS[default_lang];
  84                  $GLOBALS['egw']->translation->init();    
  85              }
  86          }
  87  
  88  		function set_header_footer_blocks()
  89          {
  90              $this->template->set_file(array(
  91                  '_layout' => 'layout.tpl'
  92              ));
  93              $this->template->set_block('_layout','header');
  94              $this->template->set_block('_layout','footer');
  95          }
  96  
  97  		function header($head_subj='')
  98          {
  99              $GLOBALS['egw']->common->egw_header();
 100              $this->set_header_footer_blocks();
 101              if($head_subj)
 102              {
 103                  $this->template->set_var('lang_header',$head_subj);
 104              }
 105              else
 106              {
 107                  $this->template->set_var('lang_header',$GLOBALS['egw_info']['server']['site_title'].' - '.lang('Account registration'));
 108              }
 109  
 110              $this->template->pfp('out','header');
 111          }
 112  
 113  		function footer()
 114          {
 115              $this->template->pfp('out','footer');
 116          }
 117  
 118  		function create_option_string($selected,$values)
 119          {
 120              while (is_array($values) && list($var,$value) = each($values))
 121              {
 122                  $s .= '<option value="' . $var . '"';
 123                  if ("$var" == "$selected")    // the "'s are necessary to force a string-compare
 124                  {
 125                      $s .= ' selected';
 126                  }
 127                  $s .= '>' . $value . '</option>';
 128              }
 129              return $s;
 130          }
 131  		function step1($errors = '',$r_reg = '',$o_reg = '')
 132          {
 133              global $config;
 134  
 135              if($config['enable_registration']!="True")
 136              {
 137                  $this->header();
 138                  echo '<br/><div align="center">';    
 139                  echo lang('On-line registration is not activated. Please contact the site administrator for more information about registration.');
 140                  echo '</div><br/>';
 141                  $this->footer();
 142                  exit;
 143              }
 144  
 145  
 146              if ($errors && $config['username_is'] == 'http')
 147              {
 148                  $vars[message]=    lang('An error occured. Please contact our technical support and let them know.');
 149                  $this->simple_screen ('error_general.tpl', $GLOBALS['egw']->common->error_list ($errors),$vars);
 150              }
 151  
 152              /* Note that check_select_username () may not return */
 153              $select_username = $this->bo->check_select_username ();
 154              if (!$select_username || is_string ($select_username))
 155              {
 156                  $vars[message]=    lang('An error occured. Please contact our technical support and let them know.');
 157                  $this->simple_screen ('error_general.tpl', $GLOBALS['egw']->common->error_list (array ($select_username)),$vars);
 158              }
 159  
 160              $this->header();
 161              $this->template->set_file(array(
 162                  '_loginid_select' => 'loginid_select.tpl'
 163              ));
 164              $this->template->set_block('_loginid_select','form');
 165  
 166              if ($errors)
 167              {
 168                  $this->template->set_var('errors',$GLOBALS['egw']->common->error_list($errors));
 169              }
 170  
 171              // temporary set all available langcodes
 172              $langs = $GLOBALS['egw']->translation->get_installed_langs();
 173              $comeback_code=$this->lang_code;
 174              foreach ($langs as $key => $name)    // if we have a translation use it
 175              {
 176                  unset($choosetrans);
 177                  $this->set_lang_code($key);
 178                  
 179                  $choosetrans=lang('Choose your language');
 180              
 181                  if($choosetrans!='Choose your language*' && $choosetrans!=$prevstring)
 182                  {
 183                      if($lang_choose_string) $lang_choose_string .='<br/> ';
 184                      $lang_choose_string .=$choosetrans;
 185                      $prevstring=$choosetrans;
 186                  }
 187                      
 188                  $trans = lang($name);
 189                  if ($trans != $name . '*')
 190                  {
 191                      $langs[$key] = $trans;
 192                  }
 193              } 
 194              $this->set_lang_code($comeback_code);
 195  
 196              $this->template->set_var('title',lang('Choose Language')); 
 197              $this->template->set_var('illustration',$GLOBALS['egw']->common->image('registration','screen0_language'));
 198                  
 199              $this->template->set_var('lang_choose_language',$lang_choose_string);
 200  
 201              $selected_lang=($this->lang_code?$this->lang_code:$GLOBALS[default_lang]);
 202      
 203              $s .= $this->create_option_string($selected_lang,$langs);
 204              $this->template->set_var('selectbox_languages','<select name="lang_code" onChange="this.form.langchanged.value=\'true\';this.form.submit()">'.$s.'</select>');
 205  
 206  
 207  
 208  
 209  
 210              $this->template->set_var('form_action',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.step1'));
 211              $this->template->set_var('lang_username',lang('Username'));
 212              $this->template->set_var('lang_submit',lang('Submit'));
 213  
 214              $this->template->pfp('out','form');
 215  
 216              $this->footer();
 217          }
 218  
 219  		function step2($errors = '',$r_reg = '',$o_reg = '',$missing_fields='')
 220          {
 221              global $config;
 222  
 223              $show_password_prompt = True;
 224              $select_password = $this->bo->check_select_password ();
 225              if (is_string ($select_password))
 226              {
 227                  $vars[message]=    lang('An error occured. Please contact our technical support and let them know.');
 228                  $this->simple_screen ('error_general.tpl', $select_password,$vars);
 229              }
 230              elseif (!$select_password)
 231              {
 232                  $show_password_prompt = False;
 233              }
 234  
 235              $this->header();
 236              $this->template->set_file(array(
 237                  '_personal_info' => 'personal_info.tpl'
 238              ));
 239              $this->template->set_block('_personal_info','form');
 240              $this->template->set_var('lang_code',$this->lang_code);
 241              $this->template->set_var('lang_username',lang('Username'));
 242              $this->template->set_var('value_username',$GLOBALS['egw']->session->appsession('loginid','registration'));
 243  
 244              if ($errors)
 245              {
 246                  $this->template->set_var('errors',$GLOBALS['egw']->common->error_list($errors));
 247              }
 248  
 249              if ($missing_fields)
 250              {
 251                  while (list(,$field) = each($missing_fields))
 252                  {
 253                      $missing[$field] = True;
 254                      $this->template->set_var('missing_' . $field,'<font color="#CC0000">*</font>');
 255                  }
 256              }
 257  
 258              if (is_array($r_reg))
 259              {
 260                  while (list($name,$value) = each($r_reg))
 261                  {                $post_values[$name] = $value;
 262                      $this->template->set_var('value_' . $name,$value);
 263                  }
 264              }
 265  
 266              if (is_array($o_reg))
 267              {
 268                  while (list($name,$value) = each($o_reg))
 269                  {
 270                      $post_values[$name] = $value;
 271                      $this->template->set_var('value_' . $name,$value);
 272                  }
 273              }
 274  
 275              $this->template->set_var('form_action',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.step2'));
 276              $this->template->set_var('lang_password',lang('Password'));
 277              $this->template->set_var('lang_reenter_password',lang('Re-enter password'));
 278              $this->template->set_var('lang_submit',lang('Submit'));
 279  
 280              if (!$show_password_prompt)
 281              {
 282                  $this->template->set_block ('form', 'password', 'empty');
 283              }
 284  
 285              $this->template->set_block ('form', 'other_fields_proto', 'other_fields_list');
 286  
 287              reset ($this->fields);
 288              while (list ($num, $field_info) = each ($this->fields))
 289              {
 290                  $input_field = $this->get_input_field ($field_info, $post_values);
 291                  $var = array (
 292                      'missing_indicator' => $missing[$field_info['field_name']] ? '<font color="#CC0000">*</font>' : '',
 293                      'bold_start'  => $field_info['field_required'] == 'Y' ? '<b>' : '',
 294                      'bold_end'    => $field_info['field_required'] == 'Y' ? '</b>' : '',
 295                      'lang_displayed_text' => lang ($field_info['field_text']),
 296                      'input_field' => $input_field
 297                  );
 298  
 299                  $this->template->set_var ($var);
 300  
 301                  $this->template->parse ('other_fields_list', 'other_fields_proto', True);
 302              }
 303  
 304              if ($config['display_tos'])
 305              {
 306                  $this->template->set_var('tos_link',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.uireg.tos'));
 307                  $this->template->set_var('lang_tos_agree',lang('I have read the terms and conditions and agree by them.'));
 308                  if ($r_reg['tos_agree'])
 309                  {
 310                      $this->template->set_var('value_tos_agree', 'checked');
 311                  }
 312              }
 313              else
 314              {
 315                  $this->template->set_block ('form', 'tos', 'blank');
 316              }
 317  
 318              $this->template->pfp('out','form');
 319              $this->footer();
 320          }
 321  
 322          //
 323          // username
 324          //
 325  		function lostpw1($errors = '',$r_reg = '')
 326          {
 327              $this->header();
 328              $this->template->set_file(array(
 329                  '_lostpw_select' => 'lostpw_select.tpl'
 330              ));
 331              $this->template->set_block('_lostpw_select','form');
 332  
 333              if ($errors)
 334              {
 335                  $this->template->set_var('errors',$GLOBALS['egw']->common->error_list($errors));
 336              }
 337              
 338              $this->template->set_var('lang_lost_password',lang('Lost Password')) ;
 339              $this->template->set_var('form_action',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.lostpw1'));
 340              $this->template->set_var('lang_explain',lang('After you enter your username, instructions to change your password will be sent to you by e-mail to the address you gave when you registered.'));
 341              $this->template->set_var('lang_username',lang('Username'));
 342              $this->template->set_var('lang_submit',lang('Submit'));
 343  
 344              $this->template->pfp('out','form');
 345              $this->footer();
 346          }
 347  
 348          //
 349          // change password
 350          //
 351  		function lostpw3($errors = '',$r_reg = '',$lid = '')
 352          {
 353              $this->header();
 354              $this->template->set_file(array(
 355                  '_lostpw_change' => 'lostpw_change.tpl'
 356              ));
 357              $this->template->set_block('_lostpw_change','form');
 358  
 359              if ($errors)
 360              {
 361                  $this->template->set_var('errors',$GLOBALS['egw']->common->error_list($errors));
 362              }
 363  
 364              $this->template->set_var('form_action',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.lostpw3'));
 365              $this->template->set_var('value_username', $lid);
 366              $this->template->set_var('lang_changepassword',lang("Change password for user"));
 367              $this->template->set_var('lang_enter_password',lang('Enter your new password'));
 368              $this->template->set_var('lang_reenter_password',lang('Re-enter your password'));
 369              $this->template->set_var('lang_change',lang('Change'));
 370  
 371              $this->template->pfp('out','form');
 372              $this->footer();
 373          }
 374  
 375          //
 376          // password was changed
 377          //
 378  		function lostpw4()
 379          {
 380              $this->header();
 381              $this->template->set_file(array(
 382                  'screen' => 'lostpw_changed.tpl'
 383              ));
 384  
 385              $message=lang('Your password was changed. You can go back to the <a href="%1">login</a> page.',$GLOBALS['egw']->link('/login.php'));
 386              $this->template->set_var('message',$message);
 387  
 388              $this->template->pfp('out','screen');
 389              $this->footer();
 390          }
 391  
 392  		function lostid1($errors = '',$r_reg = '')
 393          {
 394              $this->header();
 395              $this->template->set_file(array(
 396                  '_lostid_select' => 'lostid_select.tpl'
 397              ));
 398              $this->template->set_block('_lostid_select','form');
 399  
 400              if ($errors)
 401              {
 402                  $this->template->set_var('errors',$GLOBALS['egw']->common->error_list($errors));
 403              }
 404              $this->template->set_var('lang_lost_user_id',lang('Lost User Id')) ;
 405              $this->template->set_var('form_action',$GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.lostid1'));
 406              $this->template->set_var('lang_explain',lang('After you enter your email address, the user accounts associated with this email address will be mailed to that address.'));
 407              $this->template->set_var('lang_email',lang('email address'));
 408              $this->template->set_var('lang_submit',lang('Submit'));
 409  
 410              $this->template->pfp('out','form');
 411              $this->footer();
 412          }
 413          
 414  		function get_input_field ($field_info, $post_values)
 415          {
 416              $r_regs=$_POST['r_reg'];
 417              $o_regs=$_POST['o_reg'];
 418  
 419              $post_value = $post_values[$field_info['field_name']];
 420  
 421              $name = $field_info['field_name'];
 422              $values = explode (",", $field_info['field_values']);
 423              $required = $field_info['field_required'];
 424              $type = $field_info['field_type'];
 425  
 426              if (!$type)
 427              {
 428                  $type = 'text';
 429              }
 430  
 431              if ($type == 'gender')
 432              {
 433                  $values = array (
 434                      lang('Male'),
 435                      lang('Female')
 436                  );
 437  
 438                  $type = 'dropdown';
 439              }
 440  
 441              if ($required == 'Y')
 442              {
 443                  $a = 'r_reg';
 444              }
 445              else
 446              {
 447                  $a = 'o_reg';
 448              }
 449  
 450              if ($type == 'text' || $type == 'email' || $type == 'first_name' ||
 451              $type == 'last_name' || $type == 'address' || $type == 'city' ||
 452              $type == 'zip' || $type == 'phone')
 453              {
 454                  $rstring = '<input type=text name="' . $a . '[' . $name . ']" value="' . $post_value . '">';
 455              }
 456  
 457              if ($type == 'textarea')
 458              {
 459                  $rstring = '<textarea name="' . $a . '[' . $name . ']" value="' . $post_value . '" cols="40" rows="5">' . $post_value . '</textarea>';
 460              }
 461  
 462              if ($type == 'dropdown')
 463              {
 464                  if (!is_array ($values))
 465                  {
 466                      $rstring = "Error: Dropdown list '$name' has no values";
 467                  }
 468                  else
 469                  {
 470                      $rstring = '<select name="' . $a . '[' . $name . ']"><option value=""> </option>';
 471                      while (list (,$value) = each ($values))
 472                      {
 473                          $value = trim ($value);
 474  
 475                          unset ($selected);
 476                          if ($value == $post_value)
 477                          {
 478                              $selected = "selected";
 479                          }
 480  
 481                          $rstring .= '<option value="' . $value . '" ' . $selected . '>' . $value . '</option>';
 482                      }
 483  
 484                      $rstring .= "</select>";
 485                  }
 486              }
 487  
 488              if ($type == 'checkbox')
 489              {
 490                  unset ($checked);
 491                  if ($post_value)
 492                  $checked = "checked";
 493  
 494                  $rstring = '<input type=checkbox name="' . $a . '[' . $name . ']" ' . $checked . '>';
 495              }
 496  
 497              if ($type == 'birthday' || $type == 'state' || $type == 'country')
 498              {
 499                  $sbox =& CreateObject ('phpgwapi.sbox');
 500              }
 501  
 502              if ($type == 'state')
 503              {
 504                  $rstring = $sbox->list_states ($a . '[' . $name . ']', $post_value);
 505              }
 506  
 507              if ($type == 'country')
 508              {
 509                  $vselected=$post_value;
 510                  $aname=$a . '[' . $name . ']';
 511                  
 512                  $str = '<select name="'.$aname.'">'."\n"
 513                  . ' <option value="  "'.($vselected == '  '?' selected':'').'>'.lang('Select One').'</option>'."\n";
 514                  reset($sbox->country_array);
 515                  while(list($vkey,$vvalue) = each($sbox->country_array))
 516                  {
 517                      $str .= ' <option value="'.$vkey.'"'.($vselected == $vkey?' selected':'') . '>'.$vvalue.'</option>'."\n";
 518                  }
 519                  $str .= '</select>'."\n";
 520  
 521                  $rstring = $str;
 522              }
 523  
 524              if ($type == 'birthday')
 525              {
 526                  $rstring = $sbox->getmonthtext ($a . '[' . $name . '_month]', $post_values[$name . '_month']);
 527                  $rstring .= $sbox->getdays ($a . '[' . $name . '_day]', $post_values[$name . '_day']);
 528                  $rstring .= $sbox->getyears ($a . '[' . $name . '_year]', $post_values[$name . '_year'], 1900, date ('Y') + 1);
 529              }
 530  
 531              return $rstring;
 532          }
 533          
 534  
 535  		function simple_screen($template_file, $text = '',$vars=false,$head_subj='')
 536          {
 537              //$this->setLang();
 538              $this->header($head_subj);
 539  
 540              $this->template->set_file(array(
 541                  'screen' => $template_file
 542              ));
 543  
 544              if ($text)
 545              {
 546                  $this->template->set_var ('extra_text', $text);
 547              }
 548  
 549              if(is_array($vars))
 550              {
 551                  $this->template->set_var ($vars);
 552              }
 553  
 554              $this->template->pfp('out','screen');
 555              $this->footer();
 556              exit;
 557          }
 558  
 559  		function ready_to_activate()
 560          {
 561              $this->set_lang_code();
 562  
 563              global $config;
 564  //            $reg_id=$_GET['reg_id'];
 565  
 566              if ($config['activate_account'] == 'email')
 567              {
 568                  $var[lang_email_confirm]=lang('We have sent a confirmation email to your email address. You must click on the link within 2 hours. If you do not, it may take a few days until your loginid will become available again.');
 569  
 570                  $this->simple_screen('confirm_email_sent.tpl','',$var);
 571              }
 572              else
 573              {
 574  
 575                  /* ($config['activate_account'] == 'immediately') */
 576                  $GLOBALS['egw']->redirect($GLOBALS['egw']->link('/registration/index.php','menuaction=registration.boreg.step4&lang_code='.$this->lang_code.'&reg_id=' . $this->bo->reg_id));
 577              }
 578          }
 579  
 580  		function email_sent_lostpw()
 581          {
 582              $vars[message]=lang('We have sent a mail with instructions to change your password. You should follow the included link within two hours. If you do not, you will have to go to the lost password screen again.');
 583              $this->simple_screen('confirm_email_sent_lostpw.tpl','',$vars);
 584          }
 585          
 586  		function email_sent_lostid($email)
 587          {
 588              $vars[message]=sprintf(lang("We have sent a mail to your email account: %s with your lost user ids."),$email);
 589              $this->simple_screen('confirm_email_sent_lostpw.tpl','',$vars);
 590          }
 591  
 592  		function welcome_screen()
 593          {
 594              $this->set_lang_code();
 595              $this->header();
 596  
 597              $login_url = $GLOBALS['egw']->link('/login.php');
 598              
 599              $message = lang('Your account is now active!  Click <a href="%s">here</a> to log into your account.') ;
 600              $message = sprintf($message,$login_url) ;
 601  
 602              $this->template->set_file(array(
 603                  'screen' => 'welcome_message.tpl'
 604              ));
 605  
 606              $this->template->set_var('lang_your_account_is_active',$message);
 607  
 608              $this->template->pfp('out','screen');
 609              $this->footer();
 610          }
 611  
 612  		function tos()
 613          {
 614              global $config;
 615              $var[tos_text]= $config['tos_text'];
 616              $var[lang_close_window]= '<a href="javascript:self.close()">'.lang('Close Window').'</a>';
 617              
 618              $this->simple_screen('tos.tpl','',$var,lang('Terms of Service'));
 619          }
 620      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7