Index: moodle/admin/uploaduser.php
--- moodle/admin/uploaduser.php Base (1.106)
+++ moodle/admin/uploaduser.php Locally Modified (Based On 1.106)
@@ -12,12 +12,18 @@
 $iid         = optional_param('iid', '', PARAM_INT);
 $previewrows = optional_param('previewrows', 10, PARAM_INT);
 $readcount   = optional_param('readcount', 0, PARAM_INT);
+$uploadtype  = optional_param('uutype', 0, PARAM_INT);
 
 define('UU_ADDNEW', 0);
 define('UU_ADDINC', 1);
 define('UU_ADD_UPDATE', 2);
 define('UU_UPDATE', 3);
 
+$choices = array(UU_ADDNEW    => get_string('uuoptype_addnew', 'admin'),
+                 UU_ADDINC    => get_string('uuoptype_addinc', 'admin'),
+                 UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'),
+                 UU_UPDATE     => get_string('uuoptype_update', 'admin'));
+
 @set_time_limit(3600); // 1 hour should be enough
 @raise_memory_limit('256M');
 if (function_exists('apache_child_terminate')) {
@@ -59,7 +65,7 @@
 $strduplicateusername       = get_string('duplicateusername', 'error');
 
 $struserauthunsupported     = get_string('userauthunsupported', 'error');
-$stremailduplicate          = get_string('useremailduplicate', 'error');;
+$stremailduplicate          = get_string('useremailduplicate', 'error');
 
 $errorstr                   = get_string('error');
 
@@ -92,7 +98,7 @@
         $cir = new csv_import_reader($iid, 'uploaduser');
 
         $content = $mform->get_file_content('userfile');
-
+        $optype = $formdata->uutype;
         $readcount = $cir->load_csv_content($content, $formdata->encoding, $formdata->delimiter_name, 'validate_user_upload_columns');
         unset($content);
 
@@ -122,7 +128,7 @@
 }
 $mform = new admin_uploaduser_form2(null, $columns);
 // get initial date from form1
-$mform->set_data(array('iid'=>$iid, 'previewrows'=>$previewrows, 'readcount'=>$readcount));
+$mform->set_data(array('iid'=>$iid, 'previewrows'=>$previewrows, 'readcount'=>$readcount, 'uutypelabel'=>$choices[$uploadtype], 'uutype'=>$uploadtype));
 
 // If a file has been uploaded, then process it
 if ($formdata = $mform->is_cancelled()) {
@@ -385,7 +391,7 @@
                 if ($existinguser) {
                     $usersskipped++;
                     $upt->track('status', $strusernotadded, 'warning');
-                    $skip = true;;
+                    $skip = true;
                 }
                 break;
 
@@ -746,106 +752,189 @@
 
 echo $OUTPUT->heading_with_help(get_string('uploaduserspreview', 'admin'), 'uploadusers2');
 
-$ri = 0;
 $cir->init();
 
-$filerows = array();
+$contents = array();
 while ($fields = $cir->next()) {
-    $ci = 0;
-    if ($ri > $previewrows) {
-        $arow .= '<tr class="r'.$ri++.'">';
-        foreach ($fields as $field) {
-            $arow .= '<td class="cell c'.$ci++.'">...</td>';
+    $errormsg = array();        
+    $rowcols = array();
+    foreach($fields as $key =>$field) {
+        $rowcols[$columns[$key]] = $field;
     }
-    $arow .= '</tr>';
+
+    $usernameexist = $DB->record_exists('user', array('username'=>$rowcols['username']));
+    $emailexist    = $DB->record_exists('user', array('email'=>$rowcols['email']));
+    $cleanusername = clean_param($rowcols['username'], PARAM_USERNAME);
+    $validusername = strcmp($rowcols['username'], $cleanusername);
+    $validemail = validate_email($rowcols['email']);    
+
+    if ($validusername != 0 || !$validemail) {        
+        if ($validusername != 0) {
+            $errormsg['username'] = get_string('invalidusernameupload');
+        }
+        if (!$validemail) {
+            $errormsg['email'] = get_string('invalidemail');
+        }        
+    }
+    
+    switch($optype) {
+        case UU_ADDNEW:
+            if ($usernameexist || $emailexist ) {
+               $rowcols['action'] = 'skipped';
+            } else {
+                $rowcols['action'] = 'create';
+            }
         break;
+
+        case UU_ADDINC:
+            if (!$usernameexist && !$emailexist) {
+                $rowcols['action'] = 'create';
+            } else if ($usernameexist && !$emailexist) {
+                $rowcols['action'] = 'addcountertousername';
+                $rowcols['username'] = increment_username($rowcols['username'], $CFG->mnet_localhost_id);
+            } else {
+                $rowcols['action'] = 'skipped';
             }
+            break;
 
-    $arow = '';
-    $errormsg = array();
-    $filerows[$ri] = array();
-    $arow .= '<tr class="r'.$ri.'">';
-    foreach ($fields as $key => $field) {
-        $errorclass = '';
-        if ($ci == 0) { //username field
-            $newusername = clean_param($field, PARAM_USERNAME);
-            if (strcmp($field, $newusername) != 0){
-                $errorclass = 'uuerror';
-                $errormsg[] = get_string('invalidusernameupload');
-            } else if ($DB->record_exists('user', array('username'=>$field)) || $DB->record_exists('user', array('username'=>$field)) ) {
-                $errorclass = 'uuerror';
-                $errormsg[] = get_string('usernameexists');
+        case UU_ADD_UPDATE:
+            $oldusernameexist = '';
+            if (isset($rowcols['oldusername'])) {
+                $oldusernameexist = $DB->record_exists('user', array('username'=>$rowcols['oldusername']));
             }
+            if ($usernameexist || $emailexist || $oldusernameexist ) {
+                $rowcols['action'] = 'update';                
             } else {
-            if ($ci == 4) {     //email field                
-                if ($DB->record_exists('user', array('email'=>$field))) {
-                    $errorclass = 'uuerror';
-                    $errormsg[] = get_string('emailexists');
+                $rowcols['action'] = 'create';
+            }
+            break;
 
-                } else if (!validate_email($field)) {
-                    $errorclass = 'uuerror';
-                    $errormsg[] = get_string('invalidemail');
+        case UU_UPDATE:
+            $oldusernameexist = '';
+            if (isset($rowcols['oldusername'])) {
+                $oldusernameexist = $DB->record_exists('user', array('username'=>$rowcols['oldusername']));
                 }
+
+            if ($usernameexist || $emailexist || !empty($oldusernameexist)) {
+                $rowcols['action'] = 'update';
+            } else {
+                $rowcols['action'] = "skipped";
             }
+            break;
         }
-        $arow .= '<td class="cell c'.$ci++.'">';
-        $arow .= '<div class="'.$errorclass.'">'.s($field). '</div>';
-        $arow .= '</td>';
 
-        if ($key == (count($fields) - 1) && !empty($errormsg)) {
-            $errormsg =  implode('<br />', $errormsg);
-            $arow .=  '<td>' . $errormsg . '</td>';
-            $filerows[$ri]['error'] = $errormsg;            
+    if (!empty($errormsg)){
+        $rowcols['error'] = array();
+        $rowcols['error'] = $errormsg;
     } 
+    if ($rowcols['action'] != 'skipped') {
+        $contents[] = $rowcols;
     }
-    $arow .= '</tr>';
-    $filerows[$ri]['content'] = $arow;
-    $ri++;
 }                          
 $cir->close();
 
-$validcontent = array();
-$invalidcontent = array();
-foreach ($filerows as $arow) {
-    if (array_key_exists('error', $arow)){
-        $invalidcontent[] = $arow['content'];
-        $mform = new admin_uploaduser_form3();
-    } else {
-        $validcontent[] = $arow['content'];
+//get heading
+$headings = array();
+foreach ($contents as $content) {
+    foreach($content as $key => $value) {
+        if (!in_array($key, $headings)) {
+            $headings[] = $key;            
         }
     }
+}
 
-$ri = 0;
-$ci = 0;
-echo '<table id="uupreview" class="generaltable boxaligncenter" summary="'.get_string('uploaduserspreview', 'admin').'">';
-echo '<tr class="heading r'.$ri++.'">';
-foreach ($columns as $col) {
-    echo '<th class="header c'.$ci++.'" scope="col">'.s($col).'</th>';
+$table = new html_table();
+$table->id = "uupreview";
+$table->set_classes = 'generaltable';
+$table->tablealign = 'center';
+$table->summary = get_string('uploaduserspreview', 'admin');
+$table->head = array();
+$table->data = array();
+
+//print heading
+foreach ($headings as $heading) {
+    $table->head[] = s($heading);
 }
-if (!empty($invalidcontent)) {
-    echo '<th class="header c'.$ci++.'" scope="col">'.moodle_strtolower(get_string('error', 'moodle')).'</th>';
-}
-echo '</tr>';
 
+$haserror = false;
 $countcontent = 0;
-if (empty($invalidcontent)) {
-    $countcontent = count($validcontent);
-    echo implode('', $validcontent);
+if (in_array('error', $headings)) {
+    //print error
+    $haserror = true;
+    
+    foreach ($contents as $content) {        
+        if (array_key_exists('error', $content)) {
+            $rows = new html_table_row();
+            foreach ($content as $key => $value) {
+                $cells = new html_table_cell();                
+                $errclass = '';
+                if (array_key_exists($key, $content['error'])) {
+                    $errclass = 'uuerror';
+                }
+                if ($key == 'error') {
+                    $value = join('<br />', $content['error']);
+                }
+                if ($key == 'action') {
+                    $value = get_string($content[$key]);
+                }
+                $cells->text = $value;
+                $cells->set_classes($errclass);
+                $rows->cells[] = $cells;
+            }
+            $countcontent++;
+            $table->data[] = $rows;
+        }                
+    }    
+    $mform = new admin_uploaduser_form3();
+    $mform->set_data(array('uutype'=>$uploadtype));   
+} else if (empty($contents)) {
+    $mform = new admin_uploaduser_form3();
+    $mform->set_data(array('uutype'=>$uploadtype));
 } else {
-    $countcontent = count($invalidcontent);
-    echo implode('', $invalidcontent);
+    //print content
+    foreach ($contents as $content) {        
+        $rows = new html_table_row();        
+        if ($countcontent >= $previewrows) {
+            foreach ($content as $con) {
+                $cells = new html_table_cell();
+                $cells->text = '...';
 }
-echo '</table>';
+            $rows->cells[] = $cells;
+            $table->data[] = $rows;
+            break;
+        }
+        foreach ($headings as $heading) {
+            $cells = new html_table_cell();
+            if(array_key_exists($heading, $content)) {
+                if ($heading == 'action') {
+                    $content[$heading] = get_string($content[$heading]);
+                }
+                $cells->text = $content[$heading];
+            } else {
+                $cells->text = '';
+            }
+            $rows->cells[] = $cells;
+        }        
+        $table->data[] = $rows;
+        $countcontent++;        
+    }
+}
+echo $OUTPUT->table($table);
 
-if (!empty($invalidcontent)) {
-    echo '<div class="centerpara">'.get_string('uploadinvalidpreprocessedcount', 'moodle', $countcontent).'</div>';
-    echo '<div class="">'.get_string('invalidusername', 'moodle').'</div>';
-    echo '<div class="">'.get_string('uploadfilecontainerror', 'moodle').'</div>';
+if ($haserror) {
+    
+    echo $OUTPUT->container(get_string('useruploadtype', 'moodle', $choices[$uploadtype]), 'centerpara');
+    echo $OUTPUT->container(get_string('uploadinvalidpreprocessedcount', 'moodle', $countcontent), 'centerpara');
+    echo $OUTPUT->container(get_string('invalidusername', 'moodle'), 'centerpara');
+    echo $OUTPUT->container(get_string('uploadfilecontainerror', 'moodle'), 'centerpara');
+} else if (empty($contents)) {
+    echo $OUTPUT->container(get_string('uupreprocessedcount', 'admin', $countcontent), 'centerpara');
+    echo $OUTPUT->container(get_string('uploadfilecontentsnovaliddata'), 'centerpara');
+    
 } else {
-    echo '<div class="">'.get_string('uupreprocessedcount', 'admin', $countcontent).'</div>';
+    echo $OUTPUT->container(get_string('uupreprocessedcount', 'admin', $countcontent), 'centerpara');
 }
 
-//echo '<div class="centerpara">'.get_string('uupreprocessedcount', 'admin', $readcount).'</div>';
 $mform->display();
 echo $OUTPUT->footer();
 die;
Index: moodle/admin/uploaduser_form.php
--- moodle/admin/uploaduser_form.php Base (1.16)
+++ moodle/admin/uploaduser_form.php Locally Modified (Based On 1.16)
@@ -33,6 +33,12 @@
         $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'admin'), $choices);
         $mform->setType('previewrows', PARAM_INT);
 
+        $choices = array(UU_ADDNEW    => get_string('uuoptype_addnew', 'admin'),
+                         UU_ADDINC    => get_string('uuoptype_addinc', 'admin'),
+                         UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'),
+                         UU_UPDATE     => get_string('uuoptype_update', 'admin'));
+        $mform->addElement('select', 'uutype', get_string('uuoptype', 'admin'), $choices);
+        
         $this->add_action_buttons(false, get_string('uploadusers'));
     }
 }
@@ -52,13 +58,8 @@
 
 // upload settings and file
         $mform->addElement('header', 'settingsheader', get_string('settings'));
+        $mform->addElement('static', 'uutypelabel', get_string('uuoptype', 'admin') );
 
-        $choices = array(UU_ADDNEW    => get_string('uuoptype_addnew', 'admin'),
-                         UU_ADDINC    => get_string('uuoptype_addinc', 'admin'),
-                         UU_ADD_UPDATE => get_string('uuoptype_addupdate', 'admin'),
-                         UU_UPDATE     => get_string('uuoptype_update', 'admin'));
-        $mform->addElement('select', 'uutype', get_string('uuoptype', 'admin'), $choices);
-
         $choices = array(0 => get_string('infilefield', 'auth'), 1 => get_string('createpasswordifneeded', 'auth'));
         $mform->addElement('select', 'uupasswordnew', get_string('uupasswordnew', 'admin'), $choices);
         $mform->setDefault('uupasswordnew', 0);
@@ -92,7 +93,7 @@
         $mform->disabledIf('uuallowdeletes', 'uutype', 'eq', UU_ADDINC);
 
         $mform->addElement('selectyesno', 'uunoemailduplicates', get_string('uunoemailduplicates', 'admin'));
-        $mform->setDefault('uunoemailduplicates', 0);
+        $mform->setDefault('uunoemailduplicates', 1);
 
         $choices = array(0 => get_string('no'),
                          1 => get_string('uubulknew', 'admin'),
@@ -257,6 +258,9 @@
         $mform->addElement('hidden', 'readcount');
         $mform->setType('readcount', PARAM_INT);
 
+        $mform->addElement('hidden', 'uutype');
+        $mform->setType('uutype', PARAM_INT);
+
         $this->add_action_buttons(true, get_string('uploadusers'));
     }
 
Index: moodle/lang/en_utf8/moodle.php
--- moodle/lang/en_utf8/moodle.php Base (1.276)
+++ moodle/lang/en_utf8/moodle.php Locally Modified (Based On 1.276)
@@ -1,4 +1,4 @@
-<?PHP // $Id: moodle.php,v 1.276 2010/01/28 02:12:30 rwijaya Exp $
+<?PHP // $Id: moodle.php,v 1.275 2010/01/25 09:40:05 mudrd8mz Exp $
       // moodle.php - created with Moodle 1.7 beta + (2006101003)
 
@@ -1729,6 +1730,7 @@
 $string['userselectorsearchanywhere'] = 'Match the search text anywhere in the user\'s name';
 $string['usersnew'] = 'New users';
 $string['usersnoaccesssince'] = 'Inactive for more than';
+$string['useruploadtype'] = 'User upload type: $a';
 $string['userswithfiles'] = 'Users with files';
 $string['userzones'] = 'User zones';
 $string['usethiscourse'] = 'Use this course';
@@ -1822,4 +1824,6 @@
 $string['chooseauthmethod'] = 'Choose authentication plugin';
 $string['nocourses'] = 'No courses';
 $string['requestedcourses'] = 'Requested courses';
+$string['addcountertousername'] = 'Create user by adding counter to username';
+$string['uploadfilecontentsnovaliddata'] = 'The uploaded file contains no valid data.';
 ?>
