[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/user/ -> user_add.php (source)

   1  <?php // $Id: user_add.php,v 1.84 2007/02/05 15:06:50 mathieu Exp $
   2  /**
   3   * CLAROLINE
   4   *
   5   * This tool allow to add a user in his course (an din the platform)
   6   * @version 1.8 $Revision: 1.84 $
   7   * @copyright 2001-2007 Universite catholique de Louvain (UCL)
   8   * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
   9   * @see http://www.claroline.net/wiki/index.php/CLUSR
  10   * @author Claro Team <cvs@claroline.net>
  11   * @package CLUSR
  12   */
  13  /*=====================================================================
  14   Init Section
  15   =====================================================================*/
  16  
  17  $tlabelReq = 'CLUSR';
  18  $gidReset = true;
  19  
  20  require  '../inc/claro_init_global.inc.php';
  21  
  22  // Security check
  23  if ( ! claro_is_in_a_course() || ! claro_is_course_allowed() ) claro_disp_auth_form(true);
  24  $can_add_single_user     = (bool) (claro_is_course_manager()
  25                       && get_conf('is_coursemanager_allowed_to_add_single_user') )
  26                       || claro_is_platform_admin();
  27  if ( ! $can_add_single_user ) claro_die(get_lang('Not allowed'));
  28  
  29  // include configuration file
  30  include claro_get_conf_repository() . 'user_profile.conf.php';
  31  
  32  // include libraries
  33  require_once get_path('incRepositorySys') . '/lib/user.lib.php';
  34  require_once get_path('incRepositorySys') . '/lib/course_user.lib.php';
  35  require_once get_path('incRepositorySys') . '/lib/sendmail.lib.php';
  36  
  37  // Initialise variables
  38  $nameTools        = get_lang('Add a user');
  39  $interbredcrump[] = array ('url' => 'user.php', 'name' => get_lang('Users') );
  40  
  41  $messageList = array();
  42  $messageList['warning'] = array();
  43  $messageList['error'] = array();
  44  
  45  $platformRegSucceed = false;
  46  $courseRegSucceed   = false;
  47  
  48  /*=====================================================================
  49                                  MAIN SECTION
  50   =====================================================================*/
  51  
  52  // Initialise field variable from subscription form
  53  $userData = user_initialise();
  54  
  55  $cmd = isset($_REQUEST['cmd']) ? $cmd = $_REQUEST['cmd'] : null;
  56  
  57  if ( (isset($_REQUEST['applySearch'] ) && ( $_REQUEST['applySearch'] != '' )))
  58  {
  59      $cmd = 'applySearch';
  60  }
  61  
  62  $userData['lastname'     ] = isset($_REQUEST['lastname'        ]) ? strip_tags(trim($_REQUEST['lastname'    ])) : null;
  63  $userData['firstname'    ] = isset($_REQUEST['firstname'       ]) ? strip_tags(trim($_REQUEST['firstname'   ])) : null;
  64  $userData['officialCode' ] = isset($_REQUEST['officialCode'    ]) ? strip_tags(trim($_REQUEST['officialCode'])) : null;
  65  $userData['username'     ] = isset($_REQUEST['username'        ]) ? strip_tags(trim($_REQUEST['username'    ])) : null;
  66  $userData['email'        ] = isset($_REQUEST['email'           ]) ? strip_tags(trim($_REQUEST['email'       ])) : null;
  67  $userData['phone'        ] = isset($_REQUEST['phone'           ]) ? strip_tags(trim($_REQUEST['phone'       ])) : null;
  68  $userData['password'     ] = isset($_REQUEST['password'        ]) ? trim($_REQUEST['password'               ])  : null;
  69  $userData['password_conf'] = isset($_REQUEST['password_conf'   ]) ? trim($_REQUEST['password_conf'          ])  : null;
  70  
  71  $userData['status'     ] = isset($_REQUEST['status'     ]) ? (int)  $_REQUEST['status'     ] : null;
  72  $userData['tutor'      ] = isset($_REQUEST['tutor'      ]) ? (bool) $_REQUEST['tutor'      ] : null;
  73  $userData['courseAdmin'] = isset($_REQUEST['courseAdmin']) ? (bool) $_REQUEST['courseAdmin'] : null;
  74  
  75  $userData['confirmUserCreate'] = isset($_REQUEST['confirmUserCreate']) ? $_REQUEST['confirmUserCreate'] : null;
  76  
  77  $userId = isset($_REQUEST['userId']) ? (int) $_REQUEST['userId'] : null;
  78  
  79  $displayResultTable = false;
  80  $displayForm        = true;
  81  $errorMsgList       = array();
  82  
  83  if ( $cmd == 'registration' )
  84  {
  85      /*
  86       * Two possible ways to enroll a user to a course :
  87       * Enrollment of a completly new user from $userData
  88       * Enrollment of an existing user form its $userId
  89       */
  90  
  91      if ( $userData && ! $userId)
  92      {
  93          $errorMsgList = user_validate_form_registration($userData);
  94  
  95          if ( count($errorMsgList) == 0 ) $validUserData = true;
  96          else                             $validUserData = false;
  97  
  98          if ( in_array(get_lang('This official code is already used by another user.'), $errorMsgList) ) // validation exception ...
  99          {
 100              $userList = user_search( array('officialCode' => $userData['officialCode']),
 101                                       claro_get_current_course_id(), false, true);
 102  
 103              $messageList['error'][] = get_lang('This official code is already used by another user.')
 104                             . '<br />' . get_lang('Take one of these options') . ' : '
 105                             . '<ul>'
 106                             . '<li>'
 107                             . '<a href="#resultTable" onclick="highlight(\'resultTable\');">'
 108                             . get_lang('Click on the enrollment command beside the concerned user')
 109                             . '</a>'
 110                             . '</li>'
 111                             . '<li>'
 112                             . '<a href="'.$_SERVER['PHP_SELF'].'?cmd=cancel'. claro_url_relay_context('&amp;') . '">' . get_lang('Cancel the operation') . '</a>'
 113                             . '</li>'
 114                             . '</ul>';
 115  
 116               $displayResultTable = true;
 117          }
 118          elseif (    ! $userData['confirmUserCreate']
 119                   && ! ( empty($userData['lastname']) && empty($userData['email']) ) )
 120          {
 121              $userList = user_search( array('lastname' => $userData['lastname'    ],
 122                                             'email'    => $userData['email'       ]),
 123                                       claro_get_current_course_id(), false, true);
 124              if ( count($userList) > 0 )
 125              {
 126                   // PREPARE THE URL command TO CONFIRM THE USER CREATION
 127                   $confirmUserCreateUrl = array();
 128                   foreach($userData as $thisDataKey => $thisDataValue)
 129                   {
 130                      $confirmUserCreateUrl[] = $thisDataKey .'=' . urlencode($thisDataValue);
 131                   }
 132  
 133                   $confirmUserCreateUrl = $_SERVER['PHP_SELF']
 134                                         . '?cmd=registration&amp;'
 135                                         . implode('&amp;', $confirmUserCreateUrl)
 136                                         . '&amp;confirmUserCreate=1'
 137                                         . claro_url_relay_context('&amp;');
 138  
 139  
 140                   $messageList['warning'][] .= get_lang('Notice') . '. '
 141                  . get_lang('Users with similar settings exist on the system yet')
 142                  . '<br />' . get_lang('Take one of these options') . ' : '
 143                  . '<ul>'
 144                  . '<li>'
 145                  . '<a href="#resultTable" onclick="highlight(\'resultTable\');">'
 146                  . get_lang('Click on the enrollment command beside the concerned user')
 147                  . '</a>'
 148                  . '</li>'
 149                  . '<li>'
 150                  . '<a href="'.$confirmUserCreateUrl.'">'
 151                  . get_lang('Confirm the creation of a new user')
 152                  . '</a>'
 153                  . '<br /><small>'
 154                  . $userData['lastname'    ] . ' ' . $userData['firstname']
 155                  . $userData['officialCode'] . ' ' . $userData['email']
 156                  . '</small>'
 157                  . '</li>'
 158                  . '<li>'
 159                  . '<a href="'.$_SERVER['PHP_SELF'].'?cmd=cancel'. claro_url_relay_context('&amp;').'">' . get_lang('Cancel the operation') . '</a>'
 160                  . '</li>'
 161                  . '</ul>';
 162  
 163                  $displayForm        = false;
 164                  $displayResultTable = true;
 165              }
 166          }
 167          else
 168          {
 169              $userList = array();
 170          }
 171  
 172          if ( count($errorMsgList) > 0 && count($userList) == 0 )
 173          {
 174              if (array_key_exists('error', $messageList)) $messageList['error'] = array_merge($messageList['error'], $errorMsgList);
 175              else                                         $messageList['error'] = $errorMsgList;
 176  
 177          }
 178      }
 179  
 180      if ( ! $userId && $validUserData && count($userList) == 0 )
 181      {
 182          $userData['language'] = null;
 183          $userId = user_create($userData);
 184  
 185          if ($userId) user_send_registration_mail($userId, $userData);
 186      }
 187  
 188      if ( $userId )
 189      {
 190          $courseRegSucceed = user_add_to_course($userId, claro_get_current_course_id(), $userData['courseAdmin'], $userData['tutor'],false);
 191  
 192      }
 193      else
 194      {
 195          $courseRegSucceed = false;
 196      }
 197  } // end if $cmd == 'registration'
 198  
 199  if ($cmd == 'applySearch')
 200  {
 201      // search on username, official_code, ...
 202  
 203      $displayResultTable = TRUE;
 204  
 205      if ( ! (   empty($userData['lastname'    ])
 206              && empty($userData['email'       ])
 207              && empty($userData['officialCode']) ) )
 208      {
 209          $userList = user_search( array('lastname'     => $userData['lastname'],
 210                                         'email'        => $userData['email'],
 211                                         'officialCode' => $userData['officialCode']),
 212                                         claro_get_current_course_id());
 213      }
 214      else
 215          $userList = array();
 216  } // if $cmd == 'applySearch'
 217  
 218  // Send mail notification
 219  if ( $courseRegSucceed )
 220  {
 221      $userData = user_get_properties($userId);
 222  
 223      user_send_enroll_to_course_mail($userId, $userData );
 224      // display message
 225      $messageList['info'][]= get_lang('%firstname %lastname has been registered to your course',
 226                              array ( '%firstname' => $userData['firstname'],
 227                                      '%lastname'  => $userData['lastname'])
 228                             );
 229  }
 230  
 231  
 232  /*=====================================================================
 233   Display Section
 234   =====================================================================*/
 235  
 236  $htmlHeadXtra[] =
 237  "<script>
 238  highlight.previousValue = new Array();
 239  
 240  function highlight(elementId)
 241  {
 242      if (highlight.previousValue[elementId] == null)
 243      {
 244          this.element = document.getElementById(elementId);
 245          highlight.previousValue[elementId] = this.element.style.border;
 246          this.element.style.border='solid 2px red';
 247          setTimeout('highlight(\"' + elementId + '\")', 700);
 248      }
 249      else
 250      {
 251          document.getElementById(elementId).style.border=highlight.previousValue[elementId];
 252          delete highlight.previousValue[elementId];
 253      }
 254  }
 255  </script>";
 256  
 257  // display header
 258  include get_path('incRepositorySys') . '/claro_init_header.inc.php';
 259  
 260  echo claro_html_tool_title(array('mainTitle' =>$nameTools, 'supraTitle' => get_lang('Users')),
 261                  'help_user.php');
 262  echo claro_html_msg_list($messageList);
 263  
 264  if ( $courseRegSucceed )
 265  {
 266      echo '<p><a href="user.php' . claro_url_relay_context('?') . '">&lt;&lt; ' . get_lang('Back to user list') . '</a></p>' . "\n";
 267  }
 268  else
 269  {
 270      if ($displayResultTable) //display result of search (if any)
 271      {
 272          $regUrlAddParam = '';
 273          if ( $userData['tutor'        ] ) $regUrlAddParam .= '&amp;tutor=1';
 274          if ( $userData['courseAdmin'  ] ) $regUrlAddParam .= '&amp;courseAdmin=1';
 275  
 276          echo '<a name="resultTable"></a>'
 277          .    '<table id="resultTable" class="claroTable emphaseLine" border="0" cellspacing="2">' . "\n"
 278          .    '<thead>' . "\n"
 279          .    '<tr class="superHeader">'
 280          .    '<th colspan="5">' . get_lang('Search result') . '</th>'
 281          .    '</tr>'
 282          .    '<tr class="headerX" align="center" valign="top">' . "\n"
 283          .    '<th>' . get_lang('Last name')           . '</th>' . "\n"
 284          .    '<th>' . get_lang('First name')          . '</th>' . "\n"
 285          .    '<th>' . get_lang('Email')               . '</th>' . "\n"
 286          .    '<th>' . get_lang('Administrative code') . '</th>' . "\n"
 287          .    '<th>' . get_lang('Enrol as student')            . '</th>' . "\n"
 288          .    '</tr>' . "\n"
 289          .    '</thead>' . "\n"
 290          .    '<tbody>' . "\n"
 291          ;
 292  
 293          foreach ($userList as $thisUser)
 294          {
 295             echo '<tr valign="top">' . "\n"
 296             .    '<td>' . $thisUser['lastname'    ] . '</td>' . "\n"
 297             .    '<td>' . $thisUser['firstname'   ] . '</td>' . "\n"
 298             .    '<td>' . $thisUser['email'       ] . '</td>' . "\n"
 299             .    '<td>' . $thisUser['officialCode'] . '</td>' . "\n"
 300             .    '<td align="center">' . "\n"
 301             ;
 302  
 303              // deal with already registered users found in result
 304  
 305              if ( empty($thisUser['registered']) )
 306              {
 307                  echo '<a href="' . $_SERVER['PHP_SELF']
 308                  .    '?cmd=registration'
 309                  .    '&amp;userId=' . $thisUser['uid'] . $regUrlAddParam . claro_url_relay_context('&amp;'). '">'
 310                  .    '<img src="' . get_path('imgRepositoryWeb') . 'enroll.gif" alt="' . get_lang('Enrol as student') . '" />'
 311                  .    '</a>'
 312                  ;
 313              }
 314              else
 315              {
 316                  echo '<span class="highlight">'
 317                  .    get_lang('Already enroled')
 318                  .    '</span>'
 319                  ;
 320              }
 321  
 322              echo '</td>' . "\n"
 323              .    '</tr>' . "\n"
 324              ;
 325          }
 326  
 327          if ( sizeof($userList) == 0 )
 328          {
 329              echo '<td align="center" colspan="5">' . get_lang('No user found') . '</td>';
 330          }
 331  
 332          echo '</tbody>'
 333          .    '</table>'
 334          .    '<hr />'
 335          ;
 336      }
 337  
 338      //display form to add a user
 339  
 340      if ($displayForm)
 341      {
 342          echo '<p>' . get_lang('Add user manually') . ' :</p>'
 343          .    '<p>' . get_lang('He or she will receive email confirmation with login and password') . '</p>' . "\n"
 344          .    user_html_form_add_new_user($userData)
 345          ;
 346      }
 347  } // end else of if ( $courseRegSucceed )
 348  
 349  // display footer
 350  include get_path('incRepositorySys') . '/claro_init_footer.inc.php';
 351  
 352  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics