249
* This parser a user list from ladok.
249
* This parses a user list from ladok and returns an array with users.
250
250
* RESTRICTED-LEVEL: Teacher
252
public function parseLadok() {
253
//Check that a user is logged in, has the right privileges (is teacher) and not is the users own username.
254
if($this->isLoggedIn() && $this->getUserType() === 'Teacher' && $this->getUserName() != $userName) {
252
public function parseLadok($string) {
253
//Check that a user is logged in and has the right privileges (is teacher).
254
if($this->isLoggedIn() && $this->getUserType() === 'Teacher') {
255
$userArray = array();
257
//Populate array with users from ladok
258
$ladokUsers = preg_split( '/\r\n|\r|\n/', $string);
261
foreach ($ladokUsers as $key => $value) {
262
$ladokUsers[$key] = trim($ladokUsers[$key]);
265
//Split after last name
266
foreach ($ladokUsers as $key => $value) {
267
$ladokUsers[$key] = explode(',', trim($ladokUsers[$key]));
270
//Replace whitespaces and tabs with divider.
271
foreach ($ladokUsers as $key => $value) {
272
foreach ($ladokUsers[$key] as $key2 => $value2) {
273
$ladokUsers[$key][$key2] = preg_replace('/\s+/', ' ', trim($ladokUsers[$key][$key2]));
277
//Generate user array
278
foreach ($ladokUsers as $key => $value) {
280
'ssn' => substr($ladokUsers[$key][0], 0, 11),
281
'lastname' => substr($ladokUsers[$key][0], 12, strlen($ladokUsers[$key][0])),
282
'firstname' => substr($ladokUsers[$key][1], 0, stripos($ladokUsers[$key][1], ' ')),
283
'email' => substr($ladokUsers[$key][1], (strrpos($ladokUsers[$key][1], ' ') + 1))
285
array_push($userArray, $temp);
288
//Return parsed user array