home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / administrator / users / edit_user.php next >
Encoding:
PHP Script  |  2004-03-08  |  16.1 KB  |  515 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. require($GO_LANGUAGE->get_language_file('users'));
  15. require($GO_LANGUAGE->get_language_file('common'));
  16.  
  17. $GO_SECURITY->authenticate(true);
  18.  
  19. require($GO_CONFIG->class_path."users.class.inc");
  20. require($GO_CONFIG->class_path."validate.class.inc");
  21. $val = new validate();
  22. $users = new users();
  23.  
  24. $return_to = (isset($_REQUEST['return_to']) && $_REQUEST['return_to'] != '') ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
  25.  
  26. if ($_SERVER['REQUEST_METHOD'] == "POST")
  27. {
  28.     if ($_REQUEST['pass1'] != '')
  29.     {
  30.         $val->error_min_length = $error_min_length;
  31.         $val->error_max_length = $error_max_length;
  32.         $val->error_match = $admin_pass_match;
  33.  
  34.         $val->name="pass1";
  35.         $val->input=$_POST['pass1'];
  36.         $val->min_length=3;
  37.         $val->max_length=20;
  38.         $val->validate_input();
  39.  
  40.         $val->name="pass2";
  41.         $val->input=$_POST['pass2'];
  42.         $val->min_length=3;
  43.         $val->max_length=20;
  44.         $val->validate_input();
  45.  
  46.         $val->name="pass";
  47.         $val->match1=$_POST['pass1'];
  48.         $val->match2=$_POST['pass2'];
  49.         $val->validate_input();
  50.  
  51.         if ($val->validated)
  52.         {
  53.             if(!$users->update_password($_POST['id'], $_POST['pass1']))
  54.             {
  55.                 $feedback = '<p class="Error">'.$strSaveError.'</p><br />';
  56.             }
  57.         }else
  58.         {
  59.             $feedback = '<p class="Error">'.$errors_in_form.'</p><br />';;
  60.         }
  61.     }
  62.  
  63.     $samba_user = isset($_POST['samba_user']) ? $_POST['samba_user'] : '';
  64.     $has_samba_account = isset($_POST['has_samba_account']) ? $_POST['has_samba_account'] : false;
  65.  
  66.     if ($has_samba_account == 'true' && $samba_user != '1')
  67.     {
  68.         $users->delete_samba_account($_POST['id']);
  69.     }
  70.  
  71.     if ($has_samba_account != 'true' && $samba_user == '1')
  72.     {
  73.         $users->create_samba_account($_POST['id']);
  74.     }
  75.  
  76.     $GO_MODULES->get_modules();
  77.     while ($GO_MODULES->next_record())
  78.     {
  79.         $was_granted = $GO_SECURITY->has_permission($_POST['id'], $GO_MODULES->f('acl_read'));
  80.         $is_granted = isset($_POST['module_acl']) ? in_array($GO_MODULES->f('acl_read'), $_POST['module_acl']) : false;
  81.  
  82.         if ($was_granted && !$is_granted)
  83.         {
  84.             $GO_SECURITY->delete_user_from_acl($_POST['id'], $GO_MODULES->f('acl_read'));
  85.         }
  86.  
  87.         if ($is_granted && !$was_granted)
  88.         {
  89.             $GO_SECURITY->add_user_to_acl($_POST['id'], $GO_MODULES->f('acl_read'));
  90.         }
  91.     }
  92.     $val = new validate();
  93.     //translate the given birthdayto gmt unix time
  94.     $birthday = date_to_db_date($_POST['birthday']);
  95.  
  96.     $val->error_required = $error_required;
  97.     $val->error_min_length = $error_min_length;
  98.     $val->error_max_length = $error_max_length;
  99.     $val->error_expression = $error_email;
  100.     $val->error_match = $error_match_auth;
  101.  
  102.  
  103.     $val->name="first_name";
  104.     $val->input=$_POST['first_name'];
  105.     $val->max_length=50;
  106.     $val->required=true;
  107.     $val->validate_input();
  108.  
  109.     $val->name="last_name";
  110.     $val->input=$_POST['first_name'];
  111.     $val->max_length=50;
  112.     $val->required=true;
  113.     $val->validate_input();
  114.  
  115.     $val->name="email";
  116.     $val->input=$_POST['email'];
  117.     $val->max_length=75;
  118.     $val->required=true;
  119.     $val->expression="^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?([a-z0-9])?$";
  120.     $val->validate_input();
  121.     if ($val->validated == true)
  122.     {
  123.         if (!$users->update_profile($_POST['id'], $_POST['first_name'],$_POST['middle_name'], $_POST['last_name'], $_POST['initials'], $_POST['title'], $_POST['sex'], $birthday, $_POST['email'], $_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']))
  124.         {
  125.             $feedback = "<p class=\"Error\">".$strSaveError."</p>";
  126.         }elseif ($_POST['close'] == 'true' && !isset($feedback))
  127.         {
  128.             header('Location: '.$return_to);
  129.             exit();
  130.         }
  131.     }else
  132.     {
  133.         $feedback ="<p class='Error'>".$errors_in_form."</p>";
  134.     }
  135. }
  136.  
  137. $datepicker = new date_picker();
  138. $GO_HEADER['head'] = $datepicker->get_header();
  139.  
  140. $page_title = $menu_users;
  141. require($GO_THEME->theme_path."header.inc");
  142.  
  143. $profile = $users->get_user($_REQUEST['id']);
  144. if (!$profile)
  145. {
  146.         $feedback = '<p class="Error">'.$strDataError.'</p>';
  147. }
  148. if ($profile["samba_user"] == 1) $samba_user_check = "checked";
  149. ?>
  150. <form method="post" name="user" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  151. <input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>" />
  152. <input type="hidden" name="return_to" value="<?php echo $return_to; ?>" />
  153. <input type="hidden" name="close" value="false" />
  154. <input type="hidden" name="task" value="" />
  155. <table border="0" cellpadding="10" cellspacing="0">
  156. <tr>
  157.     <td valign="top">
  158.     <?php
  159.     if (isset($feedback))
  160.     {
  161.         echo $feedback.'<br />';;
  162.     }
  163.     ?>
  164.     <table border="0" cellpadding="0" cellspacing="3" width="600">
  165.     <tr>
  166.         <td colspan="2"><h1><?php echo $user_profile; ?> <?php echo $profile['username']; ?></h1></td>
  167.     </tr>
  168.     <tr>
  169.         <td valign="top">
  170.         <table border="0" class="normal" cellpadding="2" cellspacing="0">
  171.  
  172.         <?php
  173.         if (isset($val->error["name"]))
  174.         {
  175.         ?>
  176.         <tr>
  177.             <td class="Error" colspan="2">
  178.                 <?php echo $val->error["name"]; ?>
  179.             </td>
  180.         </tr>
  181.         <?php } ?>
  182.         <tr heigth="25">
  183.             <td align="right" nowrap><?php echo $strFirstName; ?>*: </td>
  184.             <td width="100%"><input type="text" class="textbox"  name="first_name" size="30" maxlength="50" value="<?php echo $profile["first_name"]; ?>"></td>
  185.         </tr>
  186.         <tr heigth="25">
  187.             <td align="right" nowrap><?php echo $strMiddleName; ?>: </td>
  188.             <td width="100%"><input type="text" class="textbox"  name="middle_name" size="30" maxlength="50" value="<?php echo $profile["middle_name"]; ?>"></td>
  189.         </tr>
  190.         <tr heigth="25">
  191.             <td align="right" nowrap><?php echo $strLastName; ?>*: </td>
  192.             <td width="100%"><input type="text" class="textbox"  name="last_name" size="30" maxlength="50" value="<?php echo $profile["last_name"]; ?>"></td>
  193.         </tr>
  194.         <tr heigth="25">
  195.                 <td align="right" nowrap><?php echo $strTitle; ?> / <?php echo $strInitials; ?>: </td>
  196.                 <td width="100%"><input type="text" class="textbox"  name="title" size="11" maxlength="12" value="<?php echo $profile['title']; ?>"> / <input type="text" class="textbox"  name="initials" size="11" maxlength="50" value="<?php echo $profile['initials']; ?>"></td>
  197.         </tr>
  198.         <tr>
  199.             <td align="right" nowrap><?php echo $strSex; ?>:</td>
  200.             <td>
  201.             <?php
  202.             $radiolist = new radio_list('sex', $profile['sex']);
  203.             $radiolist->add_option('M', 'M', $strSexes['M']);
  204.             echo ' ';
  205.             $radiolist->add_option('F', 'F', $strSexes['F']);
  206.             ?>
  207.             </td>
  208.         </tr>
  209.         <tr>
  210.             <td align="right" nowrap><?php echo $strBirthday; ?>:</td>
  211.             <td>
  212.             <?php
  213.             $birthday = db_date_to_date($profile['birthday']);
  214.             $datepicker->print_date_picker('birthday', $_SESSION['GO_SESSION']['date_format'], $birthday);
  215.             ?>
  216.             </td>
  217.         </tr>
  218.         <tr><td colspan="2"> </td></tr>
  219.         <tr heigth="25">
  220.             <td align="right" nowrap><?php echo $strAddress; ?>: </td>
  221.             <td width="100%"><input type="text" class="textbox"  name="address" size="30" maxlength="50" value="<?php echo $profile["address"]; ?>"></td>
  222.         </tr>
  223.  
  224.         <tr heigth="25">
  225.             <td align="right" nowrap><?php echo $strZip; ?>: </td>
  226.             <td width="100%"><input type="text" class="textbox"  name="zip" size="30" maxlength="20" value="<?php echo $profile["zip"]; ?>"></td>
  227.         </tr>
  228.         <tr heigth="25">
  229.             <td align="right" nowrap><?php echo $strCity; ?>: </td>
  230.             <td width="100%"><input type="text" class="textbox"  name="city" size="30" maxlength="50" value="<?php echo $profile["city"]; ?>">        </td>
  231.         </tr>
  232.         <tr heigth="25">
  233.             <td align="right" nowrap><?php echo $strState; ?>: </td>
  234.             <td width="100%"><input type="text" class="textbox"  name="state" size="30" maxlength="30" value="<?php echo $profile["state"]; ?>"></td>
  235.         </tr>
  236.  
  237.         <tr heigth="25">
  238.             <td align="right" nowrap><?php echo $strCountry; ?>: </td>
  239.             <td width="100%"><input type="text" class="textbox"  name="country" size="30" maxlength="30" value="<?php echo $profile["country"]; ?>"></td>
  240.         </tr>
  241.         <tr><td colspan="2"> </td></tr>
  242.         <?php
  243.         if (isset($val->error["email"]))
  244.         {
  245.         ?>
  246.         <tr>
  247.             <td class="Error" colspan="2">
  248.                 <?php echo $val->error["email"]; ?>
  249.             </td>
  250.         </tr>
  251.         <?php } ?>
  252.  
  253.         <tr heigth="25">
  254.             <td align="right" nowrap><?php echo $strEmail; ?>*: </td>
  255.             <td><input type="text" class="textbox"  name="email" size="30" value="<?php echo $profile["email"]; ?>" maxlength="50"></td>
  256.         </tr>
  257.  
  258.         <tr heigth="25">
  259.             <td align="right" nowrap><?php echo $strPhone; ?>: </td>
  260.             <td><input type="text" class="textbox"  name="home_phone" size="30" value="<?php echo $profile["home_phone"]; ?>" maxlength="20"></td>
  261.         </tr>
  262.  
  263.         <tr heigth="25">
  264.             <td align="right" nowrap><?php echo $strFax; ?>: </td>
  265.             <td><input type="text" class="textbox"  name="fax" size="30" value="<?php echo $profile["fax"]; ?>" maxlength="20"></td>
  266.         </tr>
  267.  
  268.         <tr heigth="25">
  269.             <td align="right" nowrap><?php echo $strCellular; ?>: </td>
  270.             <td><input type="text" class="textbox"  name="cellular" size="30" value="<?php echo $profile["cellular"]; ?>" maxlength="20"></td>
  271.         </tr>
  272.  
  273.  
  274.         </table>
  275.         </td>
  276.         <td valign="top">
  277.         <table border="0" class="normal" cellpadding="2" cellspacing="0">
  278.  
  279.         <tr heigth="25">
  280.             <td align="right" nowrap><?php echo $strCompany; ?>: </td>
  281.             <td><input type="text" class="textbox"  name="company" size="30" value="<?php echo $profile["company"]; ?>" maxlength="50"></td>
  282.         </tr>
  283.         <tr heigth="25">
  284.             <td align="right" nowrap><?php echo $strDepartment; ?>: </td>
  285.             <td><input type="text" class="textbox"  name="department" size="30" value="<?php echo $profile["department"]; ?>" maxlength="50"></td>
  286.         </tr>
  287.  
  288.         <tr heigth="25">
  289.             <td align="right" nowrap><?php echo $strFunction; ?>: </td>
  290.             <td><input type="text" class="textbox" name="function" size="30" value="<?php echo $profile["function"]; ?>" maxlength="50"></td>
  291.         </tr>
  292.         <tr><td colspan="2"> </td></tr>
  293.         <tr>
  294.             <td align="right" nowrap>
  295.             <?php echo $strAddress; ?>: 
  296.             </td>
  297.             <td>
  298.             <input type="text" class="textbox"  name="work_address" size="30" value="<?php echo $profile["work_address"]; ?>" maxlength="100">
  299.             </td>
  300.         </tr>
  301.  
  302.         <tr>
  303.             <td align="right" nowrap>
  304.             <?php echo $strZip; ?>: 
  305.             </td>
  306.             <td>
  307.             <input type="text" class="textbox"  name="work_zip" size="30" value="<?php echo $profile["work_zip"]; ?>" maxlength="20">
  308.             </td>
  309.         </tr>
  310.         <tr>
  311.             <td align="right" nowrap>
  312.             <?php echo $strCity; ?>: 
  313.             </td>
  314.             <td>
  315.             <input type="text" class="textbox"  name="work_city" size="30" value="<?php echo $profile["work_city"]; ?>" maxlength="50">
  316.             </td>
  317.         </tr>
  318.  
  319.  
  320.         <tr>
  321.             <td align="right" nowrap>
  322.             <?php echo $strState; ?>: 
  323.             </td>
  324.             <td>
  325.             <input type="text" class="textbox"  name="work_state" size="30" value="<?php echo $profile["work_state"]; ?>" maxlength="50">
  326.             </td>
  327.         </tr>
  328.  
  329.         <tr>
  330.             <td align="right" nowrap>
  331.             <?php echo $strCountry; ?>: 
  332.             </td>
  333.             <td>
  334.             <input type="text" class="textbox"  name="work_country" size="30" value="<?php echo $profile["work_country"]; ?>" maxlength="50">
  335.             </td>
  336.         </tr>
  337.         <tr><td colspan="2"> </td></tr>
  338.         <tr>
  339.             <td align="right" nowrap>
  340.             <?php echo $strPhone; ?>: 
  341.             </td>
  342.             <td>
  343.             <input type="text" class="textbox"  name="work_phone" size="30" value="<?php echo $profile["work_phone"]; ?>" maxlength="20">
  344.             </td>
  345.         </tr>
  346.         <tr>
  347.             <td align="right" nowrap>
  348.             <?php echo $strFax; ?>: 
  349.             </td>
  350.             <td>
  351.             <input type="text" class="textbox"  name="work_fax" size="30" value="<?php echo $profile["work_fax"]; ?>" maxlength="20">
  352.             </td>
  353.         </tr>
  354.         <tr>
  355.             <td align="right" nowrap>
  356.             <?php echo $strHomepage; ?>: 
  357.             </td>
  358.             <td>
  359.             <input type="text" class="textbox"  name="homepage" size="30" value="<?php echo $profile["homepage"] ?>" maxlength="100">
  360.             </td>
  361.         </tr>
  362.  
  363.         </table>
  364.     </td>
  365.     </tr>
  366.     <tr>
  367.         <td colspan="2">
  368.  
  369.             <table border="0" cellpadding="0" cellspacing="3">
  370.             <tr>
  371.                 <td colspan="2"><h2><?php echo $ac_login_info; ?></h2></td>
  372.             </tr>
  373.             <tr>
  374.                 <td><?php echo $ac_registration_time; ?>:</td>
  375.                 <td><?php echo date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $profile["registration_time"]+($_SESSION['GO_SESSION']['timezone']*3600)); ?></td>
  376.             </tr>
  377.             <tr>
  378.                 <td><?php echo $ac_lastlogin; ?>:</td>
  379.                 <td><?php echo date($_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'], $profile["lastlogin"]+($_SESSION['GO_SESSION']['timezone']*3600)); ?></td>
  380.             </tr>
  381.             <tr>
  382.                 <td><?php echo $ac_logins; ?>:</td>
  383.                 <td><?php echo number_format($profile["logins"], 0, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator']); ?></td>
  384.             </tr>
  385.             </table>
  386.         </td>
  387.  </tr>
  388. <tr>
  389.      <td colspan="2"><br /><h2><?php echo $admin_modules; ?></h2></td>
  390. </tr>
  391. <tr>
  392.      <td colspan="2"><?php echo $admin_module_access; ?></td>
  393. </tr>
  394. <tr>
  395.     <td colspan="2">
  396.     <table border="0" cellpadding="4" cellspacing="0">
  397.     <?php
  398.  
  399.     $column_count = 1;
  400.     $columns=3;
  401.  
  402.  
  403.     if ($GO_CONFIG->enable_samba_accounts)
  404.     {
  405.         if ($profile["samba_user"] == 1)
  406.         {
  407.             echo '<input type="hidden" name="has_samba_account" value="true" />';
  408.             $samba_user_check = "checked";
  409.         }else
  410.         {
  411.             $samba_user_check = "";
  412.         }
  413.         echo '<tr><td nowrap><input type="checkbox" name="samba_user" value="1" '.$samba_user_check.' />'.$registration_samba.'</td>';
  414.         $column_count++;
  415.     }
  416.     $count = $GO_MODULES->get_modules();
  417.     while ($GO_MODULES->next_record())
  418.     {
  419.         if ($column_count == 0)
  420.         {
  421.             echo '<tr>';
  422.             $column_count++;
  423.         }
  424.         $check = $GO_SECURITY->has_permission($_REQUEST['id'], $GO_MODULES->f('acl_read')) ? 'checked' : '';
  425.         $lang_var = isset($lang_modules[$GO_MODULES->f('id')]) ? $lang_modules[$GO_MODULES->f('id')] : $GO_MODULES->f('id');
  426.         echo '<td nowrap><input type="checkbox" name="module_acl[]" value="'.$GO_MODULES->f('acl_read').'" '.$check.' />'.$lang_var.'</td>';
  427.         if($column_count==$columns)
  428.         {
  429.             $column_count=0;
  430.             echo '</tr>';
  431.         }else
  432.         {
  433.             $column_count++;
  434.         }
  435.     }
  436.     if ($column_count != 0)
  437.     {
  438.         for ($i=$column_count;$i<=$columns;$i++)
  439.         {
  440.             echo '<td> </td>';
  441.         }
  442.         echo '</tr>';
  443.     }
  444.     ?>
  445.     </table>
  446.     </td>
  447. </tr>
  448. <tr>
  449.     <td colspan="2">
  450.     <br />
  451.     <h2><?php echo $admin_change_password; ?></h2>
  452.     </td>
  453. </tr>
  454. <tr>
  455.     <td colspan="2">
  456.     <table border="0">
  457.     <?php
  458.     if (isset($val->error['pass']))
  459.     {
  460.         echo '<tr><td colspan="2" class="Error">'.$val->error['pass'].'</td></tr>';
  461.  
  462.     }
  463.  
  464.     if (isset($val->error['pass1']))
  465.     {
  466.         echo '<tr><td colspan="2" class="Error">'.$val->error['pass1'].'</td></tr>';
  467.  
  468.     }
  469.     ?>
  470.     <tr>
  471.         <td><?php echo $admin_password; ?>:</td>
  472.         <td><input class="textbox" name="pass1" type="password" /></td>
  473.     </tr>
  474.     <?php
  475.     if (isset($val->error['pass2']))
  476.     {
  477.         echo '<tr><td colspan="2" class="Error">'.$val->error['pass2'].'</td></tr>';
  478.  
  479.     }
  480.     ?>
  481.     <tr>
  482.         <td><?php echo $admin_confirm_password; ?>:</td>
  483.         <td><input class="textbox" name="pass2" type="password" /></td>
  484.     </tr>
  485.     </table>
  486.     </td>
  487. </tr>
  488. <tr>
  489.     <td colspan="2" class="cmd">
  490.     <br />
  491.     <?php
  492.     $button = new button($cmdOk, "javascript:_save('save', 'true')");
  493.     echo '  ';
  494.     $button = new button($cmdApply, "javascript:_save('save', 'false')");
  495.     echo '  ';
  496.     $button = new button($cmdClose, 'javascript:document.location=\''.$return_to.'\';');
  497.     ?>
  498. </td>
  499. </tr>
  500. </table>
  501. </td></tr></table>
  502. </form>
  503. <script type="text/javascript">
  504. function _save(task, close)
  505. {
  506.     document.forms[0].task.value = task;
  507.     document.forms[0].close.value = close;
  508.     document.forms[0].submit();
  509. }
  510. </script>
  511.  
  512. <?php
  513. require($GO_THEME->theme_path."footer.inc");
  514. ?>
  515.