/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
1 by Henrik G.
First seed of Lenasys ... Needs to be Organized Further
1
<?php
2
3
4
//parseNames.php
5
	//Do parsing
6
	$studentList=trim($_POST['studentList']);
7
	$toBeReplaced=array("\t","\x0B","\0"); 
8
	$studentList=str_replace($toBeReplaced," ",$studentList); //Convert all types of white space into spaces
9
	$lines=explode("\n", $studentList); //Separate parsing data into lines based on new line char
10
	$students=array();
11
	$counter=0;
12
	foreach($lines as $line){ //Parse each line into a student
13
		
14
		//echo "<br /> ".$line." <br />";
15
		$words=explode(" ", $line);    //Separate the line into parts based on spaces
16
		$ssn=$words[0];                //First word is the SSN
17
		//Add names:
18
		$name=$words[1];
19
		$i=2;
20
		while(substr($name, -1)!=","){ //Find ,-sign to determine how many names there are
21
			$name.=" ".$words[$i];
22
			$i++;
23
			echo $name."<br>";
24
		}
25
		$name.=" ".$words[$i]; //First name
26
		$atPos=stripos($words[count($words)-1],"@");       //Find the position of the @-sign to determine where the login name ends in the last word (that holds the e-mail address)
27
		$login=substr($words[count($words)-1],0,$atPos) ;  //Parse login name
28
		$students[$counter]['ssn']=$ssn;
29
		$students[$counter]['name']=$name;
30
		$students[$counter]['login']=$login;
31
		$students[$counter]['passw']=generatePassword(8);
32
		$counter++;
33
	}
34
	
35
	//Insert students i Student-table and add them to the StudentCourseRegistration-table for the selected course occasion
36
		$succeeded=0;
37
			$failed=0;
38
	for($i=0;$i<count($students);$i++){
39
		$selectQuery="SELECT * FROM Student WHERE ssn=:SSN OR loginName=:LOGIN;";
40
		$select_stmt = $pdo->prepare($selectQuery);
41
		$select_stmt->bindParam(':SSN', $students[$i]['ssn']);
42
		$select_stmt->bindParam(':LOGIN', $students[$i]['login']);
43
		$select_stmt->execute();
44
		if($select_stmt->rowCount()>0){
45
			$failed++;
46
			$students[$i]['passw']="HAS PASSWORD";
47
		} else {					
48
			$insertQuery="INSERT INTO Student(ssn,name,loginName,passw) VALUES(:SSN,:NAME,:LOGIN,:PASSWORD);"; 
49
			$insert_stmt = $pdo->prepare($insertQuery);
50
			$insert_stmt->bindParam(':SSN', $students[$i]['ssn']);
51
			$insert_stmt->bindParam(':NAME', $students[$i]['name']);
52
			$insert_stmt->bindParam(':LOGIN', $students[$i]['login']);
53
			$insert_stmt->bindParam(':PASSWORD', md5($students[$i]['passw']));
54
			
55
			if($insert_stmt->execute()){
56
				$succeeded++;
57
			} 
58
		}
59
		
60
		$insertQuery="INSERT IGNORE INTO StudentCourseRegistration(studentSsn,courseName,courseOccasion) VALUES(:SSN,:CNAME,:COCCASION);";
61
		$insert_stmt = $pdo->prepare($insertQuery);
62
		$insert_stmt->bindParam(':SSN', $students[$i]['ssn']);
63
        $insert_stmt->bindParam(':CNAME', $_POST['course']);
64
        $occation=$_POST['semester']."-".$_POST['year']." LP".$_POST['period'];
65
		$insert_stmt->bindParam(':COCCASION', $occation);
66
		$insert_stmt->execute();
67
	}
68
	
69
	
70
	//Display result
71
	$content="registerStudents/parsingResult.html.php";
72
?>