home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / administrator / users / register.php < prev   
PHP Script  |  2004-03-08  |  7KB  |  195 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14. $GO_SECURITY->authenticate(true);
  15. require($GO_LANGUAGE->get_language_file('users'));
  16. require($GO_LANGUAGE->get_language_file('common'));
  17. require($GO_CONFIG->class_path."users.class.inc");
  18. $users = new users();
  19.  
  20. $datepicker = new date_picker();
  21. $GO_HEADER['head'] = $datepicker->get_header();
  22.  
  23. $page_title = $registration_title;
  24. require($GO_THEME->theme_path."header.inc");
  25.  
  26. require($GO_CONFIG->class_path."/validate.class.inc");
  27. $val = new validate;
  28.  
  29. $module_acl = isset($_POST['module_acl']) ? $_POST['module_acl'] : array();
  30.  
  31. if ($_SERVER['REQUEST_METHOD'] == "POST")
  32. {
  33.     $val->error_required = $error_required;
  34.     $val->error_min_length = $error_min_length;
  35.     $val->error_max_length = $error_max_length;
  36.     $val->error_expression = $error_email;
  37.  
  38.     $val->name="first_name";
  39.     $val->input=$_POST['first_name'];
  40.     $val->max_length=50;
  41.     $val->required=true;
  42.     $val->validate_input();
  43.  
  44.     $val->name="last_name";
  45.     $val->input=$_POST['last_name'];
  46.     $val->max_length=50;
  47.     $val->required=true;
  48.     $val->validate_input();
  49.  
  50.     $val->name="username";
  51.     $val->input=$_POST['username'];
  52.     $val->min_length=3;
  53.     $val->max_length=20;
  54.     $val->required=true;
  55.     $val->validate_input();
  56.  
  57.     $val->name="pass1";
  58.     $val->input=$_POST['pass1'];
  59.     $val->min_length=3;
  60.     $val->max_length=20;
  61.     $val->required=true;
  62.     $val->validate_input();
  63.  
  64.     $val->name="pass2";
  65.     $val->input=$_POST['pass2'];
  66.     $val->min_length=3;
  67.     $val->max_length=20;
  68.     $val->required=true;
  69.     $val->validate_input();
  70.  
  71.  
  72.     $val->name="email";
  73.     $val->input=$_POST['email'];
  74.     $val->max_length=75;
  75.  
  76.     if (!isset($_POST['create_email']))
  77.     {
  78.         $val->required=true;
  79.     }
  80.  
  81.     $val->expression="^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?([a-z0-9])?$";
  82.     $val->validate_input();
  83.  
  84.     $val->error_match = $error_match_pass;
  85.     $val->name="pass1";
  86.     $val->match1=$_POST['pass1'];
  87.     $val->match2=$_POST['pass2'];
  88.     $val->validate_input();
  89.  
  90.     if (!$val->validated)
  91.     {
  92.         $error ="<p class='Error'>".$errors_in_form."</p>";
  93.     //check if username already exists
  94.     }elseif($users->get_profile_by_username($_POST['username']))
  95.     {
  96.         $error = "<p class='Error'>".$error_username_exists."</p>";
  97.     //check if email is already registered
  98.     }elseif($users->email_exists($_POST['email']))
  99.     {
  100.         $error =  "<p class='Error'>".$error_email_exists."</p>";
  101.     }else
  102.     {
  103.         $birthday = date_to_db_date($_POST['birthday']);
  104.  
  105.         $email = ($_POST['email'] == '') ? $_POST['username'].'@'.$GO_CONFIG->inmail_host : $_POST['email'];
  106.  
  107.         //get a new acl_id for the user
  108.         if ($acl_id = $GO_SECURITY->get_new_acl($email))
  109.         {
  110.             $create_samba_user = isset($_POST['create_samba_user']) ? true : false;
  111.             $middle_name = trim($_POST['middle_name']);
  112.             $authcode = $users->random_password();
  113.             //register the new user. function returns new user_id or -1 on failure.
  114.             if ($new_user_id = $users->add_user($_POST['username'],$_POST['pass1'], $_POST['first_name'], $middle_name, $_POST['last_name'], $_POST['initials'], $_POST['title'], $_POST['sex'], $birthday, $email, $authcode, $_POST['work_phone'], $_POST['home_phone'], $_POST['fax'], $_POST['cellular'], $_POST['country'], $_POST['state'], $_POST['city'], $_POST['zip'], $_POST['address'], $_POST['company'], $_POST['work_country'], $_POST['work_state'], $_POST['work_city'], $_POST['work_zip'], $_POST['work_address'], $_POST['work_fax'], $_POST['homepage'], $_POST['department'], $_POST['function'], $_POST['language'], $_POST['theme'], $acl_id, $create_samba_user))
  115.             {
  116.                 $GO_SECURITY->set_acl_owner($acl_id, $new_user_id);
  117.  
  118.                 if (isset($_POST['create_email']))
  119.                 {
  120.                     require_once($GO_CONFIG->class_path."email.class.inc");
  121.                     $email_client = new email();
  122.                     require($GO_LANGUAGE->get_language_file('email'));
  123.                     if (!$account_id = $email_client->add_account($new_user_id, $GO_CONFIG->inmail_type,$GO_CONFIG->local_email_host, $GO_CONFIG->inmail_port, $GO_CONFIG->inmail_root, $_POST['username'], $_POST['pass1'], $_POST['name'], $_POST['username']."@".$GO_CONFIG->inmail_host, "", $ml_sent_items, $ml_spam, $ml_trash))
  124.                     {
  125.                         echo "<p class=\"Error\">".$registration_email_error."</p>";
  126.                         echo "<p class=\"Error\">".$email_client->last_error."</p>";
  127.                     }
  128.                 }
  129.  
  130.                 //send email to the user with password
  131.                 $middle_name = $middle_name ==  '' ? '' : $middle_name.' ';
  132.  
  133.                 $registration_mail_body = str_replace("%sex%", $sir_madam[$_POST['sex']], $registration_mail_body);
  134.                 $registration_mail_body = str_replace("%last_name%", $_POST['last_name'], $registration_mail_body);
  135.                 $registration_mail_body = str_replace("%middle_name%", $middle_name, $registration_mail_body);
  136.                 $registration_mail_body = str_replace("%first_name%", $_POST['first_name'], $registration_mail_body);
  137.                 $registration_mail_body = str_replace("%username%",$_POST['username'], $registration_mail_body);
  138.                 $registration_mail_body = str_replace("%password%",$_POST['pass1'], $registration_mail_body);
  139.                 $registration_mail_body .= "\n\n".$GO_CONFIG->full_url;
  140.                 sendmail($email,  $GO_CONFIG->webmaster_email, $GO_CONFIG->title, $registration_mail_subject, $registration_mail_body);
  141.                 //add the user to the everyone group
  142.                 require_once($GO_CONFIG->class_path."groups.class.inc");
  143.                 $groups = new groups();
  144.                 $groups->add_user_to_group($new_user_id,$GO_SECURITY->group_everyone);
  145.  
  146.                 //add administrator to the users acl
  147.                 $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_root, $acl_id);
  148.  
  149.                 //add the user to it's own acl
  150.                 $GO_SECURITY->add_user_to_acl($new_user_id, $acl_id);
  151.  
  152.                 //if user want's to be visible to any one add the everyone group to the users acl_id
  153.                 if (isset($_POST['visible']))
  154.                 {
  155.                     $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_everyone, $acl_id);
  156.                 }
  157.  
  158.                 //set module permissions
  159.                 for ($i=0;$i<count($module_acl);$i++)
  160.                 {
  161.                     $GO_SECURITY->add_user_to_acl($new_user_id, $_POST['module_acl'][$i]);
  162.                 }
  163.  
  164.                 //create Group-Office home directory
  165.                 $old_umask = umask(000);
  166.                 mkdir($GO_CONFIG->file_storage_path.$_POST['username'], $GO_CONFIG->create_mode);
  167.                 umask($old_umask);
  168.  
  169.                 //confirm registration to the user and exit the script so the form won't load
  170.                 echo $registration_success." <b>".$email."</b>";
  171.                 echo '<br /><br />';
  172.                 $button = new button($cmdContinue, "javascript:document.location='index.php';");
  173.                 echo '</td></tr></table>';
  174.                 require($GO_THEME->theme_path."footer.inc");
  175.                 exit;
  176.             }else
  177.             {
  178.                     $error = "<p class=\"Error\">".$registration_failure."</p>";
  179.             }
  180.         }else
  181.         {
  182.                 $error = "<p class=\"Error\">".$registration_failure."</p>";
  183.         }
  184.     }
  185. }
  186. if (!$users->max_users_reached())
  187. {
  188.         require("register_form.inc");
  189. }else
  190. {
  191.         echo '<h1>'.$max_user_limit.'</h1>'.$max_users_text;
  192. }
  193. require($GO_THEME->theme_path."footer.inc");
  194. ?>
  195.