$firstname = get_key_value($userdata, "firstname"); if (empty($firstname) === true) { $firstname = 'no-firstname'; } $lastname = get_key_value($userdata, "lastname"); if (empty($lastname) === true) { $lastname = 'no-lastname'; } $email = get_key_value($userdata, "email"); $idnumber = get_key_value($userdata, "idnumber"); // the users id in the wordpress database, stored here for possible user-matching $cohort = get_key_value($userdata, "cohort"); // the cohort to map the user user; these can be set as enrolment options on one or more courses, if it doesn't exist then skip this step $group = get_key_value($userdata, "group"); $course = get_key_value($userdata, "course"); $updatefields = get_key_value($userdata, "updatable") != "false"; // if true or not set, update fields like email, username, etc. // mdl_user.idnumber is the wordpress wp_users.id // TODO: if (get_field('user', 'id', 'username', $username, 'deleted', 1, '')) ----> error since the user is now deleted if ($DB->record_exists('user', array('username' => $username, 'idnumber' => '', 'auth' => 'manual'))) { // update manually created user that has the same username but doesn't yet have the right idnumber $updateuser = get_complete_user_data('username', $username); $updateuser->idnumber = $idnumber; if ($updatefields) { $updateuser->email = $email; $updateuser->firstname = $firstname; $updateuser->lastname = $lastname; } // do not update username // do not update password, we don't know it // make sure we haven't exceeded any field limits
function parse_status_file($statusfile = STATUSFILE) { $file = fopen($statusfile, "r") or die("Unable to open '{$statusfile}' file!"); if (!$file) { die("File '{$statusfile}' not found!"); } $hoststatus = array(); $servicestatus = array(); $hostcomments = array(); $servicecomments = array(); $programstatus = array(); $info = array(); //counters for iteration through file $case = OUTOFBLOCK; $service_id = 0; $s_comment_id = 0; $h_comment_id = 0; $hostkey = ''; //keywords for string match $hoststring = 'hoststatus {'; $servicestring = 'servicestatus {'; $hostcommentstring = 'hostcomment {'; $servicecommentstring = 'servicecomment {'; $programstring = 'programstatus {'; $infostring = 'info {'; //begin parse while (!feof($file)) { $line = fgets($file); //Gets a line from file pointer. //////////////////////////NEW REVISION////////////////////////// if ($case == OUTOFBLOCK) { //host if (strpos($line, $hoststring) !== false) { $case = HOSTDEF; //enable grabbing of host variables //unset($hostkey); continue; } //service if (strpos($line, $servicestring) !== false) { $case = SERVICEDEF; //enable grabbing of service variables $servicestatus[$service_id] = array(); continue; } //hostcomment if (strpos($line, $hostcommentstring) !== false) { $case = HOSTCOMMENT; //enable grabbing of host variables //unset($hostkey); continue; } //service if (strpos($line, $servicecommentstring) !== false) { $case = SERVICECOMMENT; //enable grabbing of service variables $s_comment_id++; continue; } //program status if (strpos($line, $programstring) !== false) { $case = PROGRAM; continue; } //info if (strpos($line, $infostring) !== false) { $case = INFO; continue; } } //end OUTOFBLOCK IF //end of definition if (strpos($line, '}') !== false) { if ($case == SERVICEDEF) { $service_id++; } if ($case == SERVICECOMMENT) { $s_comment_id++; } if ($case == HOSTCOMMENT) { $h_comment_id++; } $case = OUTOFBLOCK; //turn off switches once a definition ends continue; } //capture key / value pair list($key, $value) = get_key_value($line); //grab variables according to the enabled boolean switch switch ($case) { case HOSTDEF: //do something if ($key == 'host_name' && !isset($hoststatus[$value])) { $hostkey = $value; $hoststatus[$hostkey] = array(); } $hoststatus[$hostkey][$key] = $value; break; case SERVICEDEF: $servicestatus[$service_id][$key] = $value; $servicestatus[$service_id]['service_id'] = $service_id; break; case HOSTCOMMENT: if (!isset($hostcomments[$h_comment_id])) { $hostcomments[$h_comment_id] = array(); } $hostcomments[$h_comment_id][$key] = $value; break; case SERVICECOMMENT: $servicecomments[$s_comment_id][$key] = $value; break; case INFO: $info[$key] = $value; break; case PROGRAM: $programstatus[$key] = $value; break; case OUTOFBLOCK: default: //switches are off, do nothing break; } //end of switch } //end of WHILE fclose($file); return array($hoststatus, $servicestatus, $hostcomments, $servicecomments, $programstatus, $info); }