function __handleUser($row) { global $ilDB, $lng; if (!is_array($this->settings)) { include_once './Services/User/classes/class.ilObjUserFolder.php'; $this->setSettings(ilObjUserFolder::getExportSettings()); } $prefs = ilObjUser::_getPreferences($row["usr_id"]); if (strlen($row["language"]) == 0) { $row["language"] = $lng->getDefaultLanguage(); } $attrs = array('Id' => "il_" . IL_INST_ID . "_usr_" . $row["usr_id"], 'Language' => $row["language"], 'Action' => "Update"); $this->xmlStartTag("User", $attrs); $this->xmlElement("Login", null, $row["login"]); if ($this->attachRoles == TRUE) { include_once './Services/AccessControl/classes/class.ilObjRole.php'; $query = sprintf("SELECT object_data.title, object_data.description, rbac_fa.* " . "FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s " . "AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id", $ilDB->quote($row["usr_id"], 'integer')); $rbacresult = $ilDB->query($query); while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC)) { if ($rbacrow["assign"] != "y") { continue; } $type = ""; if ($rbacrow["parent"] == ROLE_FOLDER_ID) { $type = "Global"; } else { $type = "Local"; } if (strlen($type)) { $this->xmlElement("Role", array("Id" => "il_" . IL_INST_ID . "_role_" . $rbacrow["rol_id"], "Type" => $type), $rbacrow["title"]); } } } $this->__addElement("Firstname", $row["firstname"]); $this->__addElement("Lastname", $row["lastname"]); $this->__addElement("Title", $row["title"]); if ($this->canExport("PersonalPicture", "upload")) { $imageData = $this->getPictureValue($row["usr_id"]); if ($imageData) { $value = array_shift($imageData); //$imageData["value"]; $this->__addElement("PersonalPicture", $value, $imageData, "upload"); } } $this->__addElement("Gender", $row["gender"]); $this->__addElement("Email", $row["email"]); $this->__addElement("Birthday", $row["birthday"]); $this->__addElement("Institution", $row["institution"]); $this->__addElement("Street", $row["street"]); $this->__addElement("City", $row["city"]); $this->__addElement("PostalCode", $row["zipcode"], null, "zipcode"); $this->__addElement("Country", $row["country"]); $this->__addElement("PhoneOffice", $row["phone_office"], null, "phone_office"); $this->__addElement("PhoneHome", $row["phone_home"], null, "phone_home"); $this->__addElement("PhoneMobile", $row["phone_mobile"], null, "phone_mobile"); $this->__addElement("Fax", $row["fax"]); $this->__addElement("Hobby", $row["hobby"]); $this->__addElementMulti("GeneralInterest", $row["interests_general"], null, "interests_general"); $this->__addElementMulti("OfferingHelp", $row["interests_help_offered"], null, "interests_help_offered"); $this->__addElementMulti("LookingForHelp", $row["interests_help_looking"], null, "interests_help_looking"); $this->__addElement("Department", $row["department"]); $this->__addElement("Comment", $row["referral_comment"], null, "referral_comment"); $this->__addElement("Matriculation", $row["matriculation"]); $this->__addElement("Active", $row["active"] ? "true" : "false"); $this->__addElement("ClientIP", $row["client_ip"], null, "client_ip"); $this->__addElement("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner"); $this->__addElement("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited"); $this->__addElement("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from"); $this->__addElement("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until"); $this->__addElement("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message"); $this->__addElement("ApproveDate", $row["approve_date"], null, "approve_date"); $this->__addElement("AgreeDate", $row["agree_date"], null, "agree_date"); if (strlen($row["auth_mode"]) > 0) { $this->__addElement("AuthMode", null, array("type" => $row["auth_mode"]), "auth_mode", true); } if (strlen($row["ext_account"]) > 0) { $this->__addElement("ExternalAccount", $row["ext_account"], null, "ext_account", true); } if ($this->canExport("Look", "skin_style")) { $this->__addElement("Look", null, array("Skin" => $prefs["skin"], "Style" => $prefs["style"]), "skin_style", true); } $this->__addElement("LastUpdate", $row["last_update"], null, "last_update"); $this->__addElement("LastLogin", $row["last_login"], null, "last_login"); include_once "./Services/User/classes/class.ilUserDefinedData.php"; $udf_data = new ilUserDefinedData($row['usr_id']); $udf_data->addToXML($this, $this->settings); $msgrs = array("skype" => "im_skype", "yahoo" => "im_yahoo", "msn" => "im_msn", "aim" => "im_aim", "icq" => "im_icq", "delicious" => "delicious", "external" => "ext_account", "jabber" => "im_jabber", "voip" => "im_voip"); foreach ($msgrs as $type => $fieldname) { $this->__addElement("AccountInfo", $row[$fieldname], array("Type" => $type), "instant_messengers"); } $this->__addElement("GMapsInfo", null, array("longitude" => $row["longitude"], "latitude" => $row["latitude"], "zoom" => $row["loc_zoom"])); $this->__addElement("Feedhash", $row["feed_hash"]); if ($this->attachPreferences || $this->canExport("prefs", "preferences")) { $this->__handlePreferences($prefs, $row); } $this->xmlEndTag('User'); }
/** * Parse data * @return * * @global ilRbacReview $rbacreview */ public function parse() { global $rbacreview; $this->determineOffsetAndOrder(); include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); unset($additional_fields['consultation_hour']); unset($additional_fields['prtf']); $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData($this->getOrderField(), $this->getOrderDirection(), $this->getOffset(), $this->getLimit(), '', '', null, false, false, 0, $this->getRoleId(), null, $usr_data_fields, $part); foreach ((array) $usr_data['set'] as $user) { $usr_ids[] = $user['usr_id']; } // merge course data $course_user_data = $this->getParentObject()->readMemberData($usr_ids, $this->type == 'admin', $this->getSelectedColumns()); $a_user_data = array(); foreach ((array) $usr_data['set'] as $ud) { $a_user_data[$ud['usr_id']] = array_merge($ud, $course_user_data[$ud['usr_id']]); if ($this->show_lp_status_sync) { // #9912 / #13208 $passed_info = ""; if ($a_user_data[$ud['usr_id']]["passed_info"]) { $pinfo = $a_user_data[$ud['usr_id']]["passed_info"]; if ($pinfo["user_id"]) { if ($pinfo["user_id"] < 0) { $passed_info = $this->lng->txt("crs_passed_status_system"); } else { if ($pinfo["user_id"] > 0) { $name = ilObjUser::_lookupName($pinfo["user_id"]); $passed_info = $this->lng->txt("crs_passed_status_manual_by") . ": " . $name["login"]; } } } if ($pinfo["timestamp"]) { $passed_info .= "<br />" . ilDatePresentation::formatDate($pinfo["timestamp"]); } } $a_user_data[$ud['usr_id']]["passed_info"] = $passed_info; } } // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { // #7264: as we get data for all course members filter against user data if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } // add last edit date include_once './Services/Membership/classes/class.ilObjectCustomUserFieldHistory.php'; foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getParentObject()->object->getId()) as $usr_id => $edit_info) { if (!isset($a_user_data[$usr_id])) { continue; } include_once './Services/PrivacySecurity/classes/class.ilPrivacySettings.php'; if ($usr_id == $edit_info['update_user']) { $a_user_data[$usr_id]['odf_last_update'] = ''; $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['lng']->txt('cdf_edited_by_self'); if (ilPrivacySettings::_getInstance()->enabledAccessTimesByType($this->getParentObject()->object->getType())) { $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $a_user_data[$usr_id]['odf_info_txt'] .= ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } else { $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user']; $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $name = ilObjUser::_lookupName($edit_info['update_user']); $a_user_data[$usr_id]['odf_info_txt'] = $name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } // consultation hours if ($this->isColumnSelected('consultation_hour')) { include_once './Services/Booking/classes/class.ilBookingEntry.php'; foreach (ilBookingEntry::lookupManagedBookingsForObject($this->getParentObject()->object->getId(), $GLOBALS['ilUser']->getId()) as $buser => $booking) { if (isset($a_user_data[$buser])) { $a_user_data[$buser]['consultation_hour'] = $booking[0]['dt']; $a_user_data[$buser]['consultation_hour_end'] = $booking[0]['dtend']; $a_user_data[$buser]['consultation_hours'] = $booking; } } } $this->setMaxCount($usr_data['cnt'] ? $usr_data['cnt'] : 0); return $this->setData($a_user_data); }
function createExcelExport(&$settings, &$data, $filename, $a_mode) { include_once "./Services/Excel/classes/class.ilExcelUtils.php"; include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php"; $adapter = new ilExcelWriterAdapter($filename, FALSE); $workbook = $adapter->getWorkbook(); // Creating a worksheet $format_bold =& $workbook->addFormat(); $format_bold->setBold(); $format_percent =& $workbook->addFormat(); $format_percent->setNumFormat("0.00%"); $format_datetime =& $workbook->addFormat(); $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss"); $format_title =& $workbook->addFormat(); $format_title->setBold(); $format_title->setColor('black'); $format_title->setPattern(1); $format_title->setFgColor('silver'); $worksheet =& $workbook->addWorksheet(); $row = 0; $col = 0; $udf_ex_fields = $this->getUserDefinedExportFields(); // title row foreach ($settings as $value) { if ($value == 'ext_account') { $value = 'user_ext_account'; } $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title); $col++; } foreach ($udf_ex_fields as $f) { $worksheet->write($row, $col, ilExcelUtils::_convert_text($f["name"], $a_mode), $format_title); $col++; } $this->lng->loadLanguageModule("meta"); foreach ($data as $index => $rowdata) { $row++; $col = 0; // standard fields foreach ($settings as $fieldname) { $value = $rowdata[$fieldname]; switch ($fieldname) { case "language": $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("meta_l_" . $value), $a_mode)); break; case "time_limit_from": case "time_limit_until": $date = strftime("%Y-%m-%d %H:%M:%S", $value); if (preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $date, $matches)) { $worksheet->write($row, $col, ilUtil::excelTime($matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]), $format_datetime); } break; case "last_login": case "last_update": case "create_date": case "approve_date": case "agree_date": if (preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $value, $matches)) { $worksheet->write($row, $col, ilUtil::excelTime($matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]), $format_datetime); } break; case "interests_general": case "interests_help_offered": case "interests_help_looking": if (is_array($value) && sizeof($value)) { $value = implode(", ", $value); } else { $value = null; } // fallthrough // fallthrough default: $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode)); break; } $col++; } // custom fields reset($udf_ex_fields); if (count($udf_ex_fields) > 0) { include_once "./Services/User/classes/class.ilUserDefinedData.php"; $udf = new ilUserDefinedData($rowdata["usr_id"]); foreach ($udf_ex_fields as $f) { $worksheet->write($row, $col, ilExcelUtils::_convert_text($udf->get("f_" . $f["id"]), $a_mode)); $col++; } } } $workbook->close(); }
/** * read data * * @access protected * @param * @return */ public function readSubscriberData() { include_once './Services/Membership/classes/class.ilParticipants.php'; $sub_data = ilParticipants::lookupSubscribersData($this->getParentObject()->object->getId()); $sub_ids = array(); foreach ($sub_data as $usr_id => $usr_data) { $sub_ids[] = $usr_id; } $this->determineOffsetAndOrder(); include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData($this->getOrderField(), $this->getOrderDirection(), $this->getOffset(), $this->getLimit(), '', '', null, false, false, 0, 0, null, $usr_data_fields, $sub_ids); foreach ((array) $usr_data['set'] as $user) { $usr_ids[] = $user['usr_id']; } // merge course data $course_user_data = $this->getParentObject()->readMemberData($usr_ids, $this->type == 'admin'); $a_user_data = array(); foreach ((array) $usr_data['set'] as $ud) { $a_user_data[$ud['usr_id']] = array_merge($ud, (array) $course_user_data[$ud['usr_id']]); } // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { // #7264: as we get data for all course members filter against user data if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } // add last edit date include_once './Services/Membership/classes/class.ilObjectCustomUserFieldHistory.php'; foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getParentObject()->object->getId()) as $usr_id => $edit_info) { if (!isset($a_user_data[$usr_id])) { continue; } include_once './Services/PrivacySecurity/classes/class.ilPrivacySettings.php'; if ($usr_id == $edit_info['update_user']) { $a_user_data[$usr_id]['odf_last_update'] = ''; $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['lng']->txt('cdf_edited_by_self'); if (ilPrivacySettings::_getInstance()->enabledAccessTimesByType($this->getParentObject()->object->getType())) { $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $a_user_data[$usr_id]['odf_info_txt'] .= ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } else { $a_user_data[$usr_id]['odf_last_update'] = $edit_info['update_user']; $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $name = ilObjUser::_lookupName($edit_info['update_user']); $a_user_data[$usr_id]['odf_info_txt'] = $name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } // Waiting list subscription foreach ($sub_data as $usr_id => $usr_data) { if (!in_array($usr_id, $usr_ids)) { continue; } $a_user_data[$usr_id]['sub_time'] = $usr_data['time']; $a_user_data[$usr_id]['subject'] = $usr_data['subject']; } $this->setMaxCount(count($sub_ids)); return $this->setData($a_user_data); }
/** * Parse data * @return * * @global ilRbacReview $rbacreview */ public function parse() { global $rbacreview; $this->determineOffsetAndOrder(); include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData($this->getOrderField(), $this->getOrderDirection(), $this->getOffset(), $this->getLimit(), '', '', null, false, false, 0, $this->getRoleId(), null, $usr_data_fields, $part); foreach ((array) $usr_data['set'] as $user) { $usr_ids[] = $user['usr_id']; } // merge course data $course_user_data = $this->getParentObject()->readMemberData($usr_ids, $this->type == 'admin'); $a_user_data = array(); foreach ((array) $usr_data['set'] as $ud) { $a_user_data[$ud['usr_id']] = array_merge($ud, $course_user_data[$ud['usr_id']]); if ($this->show_lp_status_sync) { // #9912 $passed_info = ""; if ($a_user_data[$ud['usr_id']]["passed_info"]["user_id"]) { $pinfo = $a_user_data[$ud['usr_id']]["passed_info"]; if ($pinfo["user_id"] < 0) { $passed_info = "LP"; } else { $name = ilObjUser::_lookupName($pinfo["user_id"]); $passed_info = $name["login"]; $passed_info .= "<br />" . ilDatePresentation::formatDate($pinfo["timestamp"]); } } $a_user_data[$ud['usr_id']]["passed_info"] = $passed_info; } } // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { // #7264: as we get data for all course members filter against user data if (!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } $this->setMaxCount($usr_data['cnt'] ? $usr_data['cnt'] : 0); return $this->setData($a_user_data); }
function deleteValue($a_field_id, $a_value_id) { global $ilDB; $definition = $this->getDefinition($a_field_id); $counter = 0; $new_values = array(); foreach ($definition['field_values'] as $value) { if ($counter++ != $a_value_id) { $new_values[] = $value; } else { $old_value = $value; } } $values = array('field_values' => array('clob', serialize($new_values))); $ilDB->update('udf_definition', $values, array('field_id' => array('integer', $a_field_id))); // sets value to '' where old value is $old_value include_once "./Services/User/classes/class.ilUserDefinedData.php"; ilUserDefinedData::deleteFieldValue($a_field_id, $old_value); // fianally read data $this->__read(); return true; }
/** * handler for end of element when in import user mode. */ function importEndTag($a_xml_parser, $a_name) { global $ilias, $rbacadmin, $rbacreview, $ilUser, $lng, $ilSetting; switch ($a_name) { case "Role": $this->roles[$this->current_role_id]["name"] = $this->cdata; $this->roles[$this->current_role_id]["type"] = $this->current_role_type; $this->roles[$this->current_role_id]["action"] = $this->current_role_action; break; case "PersonalPicture": switch ($this->personalPicture["encoding"]) { case "Base64": $this->personalPicture["content"] = base64_decode($this->cdata); break; case "UUEncode": // this only works with PHP >= 5 if (version_compare(PHP_VERSION, '5', '>=')) { $this->personalPicture["content"] = convert_uudecode($this->cdata); } break; } break; case "User": $this->userObj->setFullname(); // Fetch the user_id from the database, if we didn't have it in xml file // fetch as well, if we are trying to insert -> recognize duplicates! if ($this->user_id == -1 || $this->action == "Insert") { $user_id = ilObjUser::getUserIdByLogin($this->userObj->getLogin()); } else { $user_id = $this->user_id; } //echo $user_id.":".$this->userObj->getLogin(); // Handle conflicts switch ($this->conflict_rule) { case IL_FAIL_ON_CONFLICT: // do not change action break; case IL_UPDATE_ON_CONFLICT: switch ($this->action) { case "Insert": if ($user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Insert", "Update")); $this->action = "Update"; } break; case "Update": if (!$user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_replaced"), "Update", "Insert")); $this->action = "Insert"; } break; case "Delete": if (!$user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete")); $this->action = "Ignore"; } break; } break; case IL_IGNORE_ON_CONFLICT: switch ($this->action) { case "Insert": if ($user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Insert")); $this->action = "Ignore"; } break; case "Update": if (!$user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Update")); $this->action = "Ignore"; } break; case "Delete": if (!$user_id) { $this->logWarning($this->userObj->getLogin(), sprintf($lng->txt("usrimport_action_ignored"), "Delete")); $this->action = "Ignore"; } break; } break; } // check external account conflict (if external account is already used) // note: we cannot apply conflict rules in the same manner as to logins here // so we ignore records with already existing external accounts. //echo $this->userObj->getAuthMode().'h'; $am = $this->userObj->getAuthMode() == "default" || $this->userObj->getAuthMode() == "" ? ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) : $this->userObj->getAuthMode(); $loginForExternalAccount = $this->userObj->getExternalAccount() == "" ? "" : ilObjUser::_checkExternalAuthAccount($am, $this->userObj->getExternalAccount()); switch ($this->action) { case "Insert": if ($loginForExternalAccount != "") { $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_insert_ext_account_exists") . " (" . $this->userObj->getExternalAccount() . ")"); $this->action = "Ignore"; } break; case "Update": // this variable describes the ILIAS login which belongs to the given external account!!! // it is NOT nescessarily the ILIAS login of the current user record !! // so if we found an ILIAS login according to the authentication method // check if the ILIAS login belongs to the current user record, otherwise somebody else is using it! if ($loginForExternalAccount != "") { // check if we changed the value! $externalAccountHasChanged = $this->userObj->getExternalAccount() != ilObjUser::_lookupExternalAccount($this->user_id); // if it has changed and the external login if ($externalAccountHasChanged && trim($loginForExternalAccount) != trim($this->userObj->getLogin())) { $this->logWarning($this->userObj->getLogin(), $lng->txt("usrimport_no_update_ext_account_exists") . " (" . $this->userObj->getExternalAccount() . ")"); $this->action = "Ignore"; } } break; } // Perform the action switch ($this->action) { case "Insert": if ($user_id) { $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_insert")); } else { if (!strlen($this->currPassword) == 0) { switch ($this->currPasswordType) { case "ILIAS2": $this->userObj->setPasswd($this->currPassword, IL_PASSWD_CRYPT); break; case "ILIAS3": $this->userObj->setPasswd($this->currPassword, IL_PASSWD_MD5); break; case "PLAIN": $this->userObj->setPasswd($this->currPassword, IL_PASSWD_PLAIN); $this->acc_mail->setUserPassword($this->currPassword); break; } } else { // this does the trick for empty passwords // since a MD5 string has always 32 characters, // no hashed password combination will ever equal to // an empty string $this->userObj->setPasswd("", IL_PASSWD_MD5); } $this->userObj->setTitle($this->userObj->getFullname()); $this->userObj->setDescription($this->userObj->getEmail()); if (!$this->time_limit_owner_set) { $this->userObj->setTimeLimitOwner($this->getFolderId()); } // default time limit settings if (!$this->time_limit_set) { $this->userObj->setTimeLimitUnlimited(1); $this->userObj->setTimeLimitMessage(0); if (!$this->approve_date_set) { $this->userObj->setApproveDate(date("Y-m-d H:i:s")); } } $this->userObj->setActive($this->currActive == 'true' || is_null($this->currActive)); // Finally before saving new user. // Check if profile is incomplete // #8759 if (count($this->udf_data)) { $this->userObj->setUserDefinedData($this->udf_data); } $this->userObj->setProfileIncomplete($this->checkProfileIncomplete($this->userObj)); $this->userObj->create(); //insert user data in table user_data $this->userObj->saveAsNew(false); // Set default prefs $this->userObj->setPref('hits_per_page', $ilSetting->get('hits_per_page', 30)); $this->userObj->setPref('show_users_online', $ilSetting->get('show_users_online', 'y')); if (count($this->prefs)) { foreach ($this->prefs as $key => $value) { if ($key != "mail_incoming_type" && $key != "mail_signature" && $key != "mail_linebreak") { $this->userObj->setPref($key, $value); } } } $this->userObj->writePrefs(); // update mail preferences, to be extended $this->updateMailPreferences($this->userObj->getId()); if (is_array($this->personalPicture)) { if (strlen($this->personalPicture["content"])) { $extension = "jpg"; if (preg_match("/.*(png|jpg|gif|jpeg)\$/", $this->personalPicture["imagetype"], $matches)) { $extension = $matches[1]; } $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".{$extension}"); if (strlen($tmp_name)) { ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId()); unlink($tmp_name); } } } if ($this->ilincdata["id"]) { include_once 'Modules/ILinc/classes/class.ilObjiLincUser.php'; $ilinc_user = new ilObjiLincUser($this->userObj); $ilinc_user->setVar("id", $this->ilincdata["id"]); $ilinc_user->setVar("login", $this->ilincdata["login"]); $ilinc_user->setVar("passwd", $this->ilincdata["password"]); $ilinc_user->update(); } //set role entries foreach ($this->roles as $role_id => $role) { if ($this->role_assign[$role_id]) { $this->assignToRole($this->userObj, $this->role_assign[$role_id]); } } if (count($this->udf_data)) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $udd = new ilUserDefinedData($this->userObj->getId()); foreach ($this->udf_data as $field => $value) { $udd->set("f_" . $field, $value); } $udd->update(); } $this->sendAccountMail(); $this->logSuccess($this->userObj->getLogin(), $this->userObj->getId(), "Insert"); // reset account mail object $this->acc_mail->reset(); } break; case "Update": if (!$user_id) { $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_update")); } else { $updateUser = new ilObjUser($user_id); $updateUser->read(); $updateUser->readPrefs(); if ($this->currPassword != null) { switch ($this->currPasswordType) { case "ILIAS2": $updateUser->setPasswd($this->currPassword, IL_PASSWD_CRYPT); break; case "ILIAS3": $updateUser->setPasswd($this->currPassword, IL_PASSWD_MD5); break; case "PLAIN": $updateUser->setPasswd($this->currPassword, IL_PASSWD_PLAIN); $this->acc_mail->setUserPassword($this->currPassword); break; } } if (!is_null($this->userObj->getFirstname())) { $updateUser->setFirstname($this->userObj->getFirstname()); } if (!is_null($this->userObj->getLastname())) { $updateUser->setLastname($this->userObj->getLastname()); } if (!is_null($this->userObj->getUTitle())) { $updateUser->setUTitle($this->userObj->getUTitle()); } if (!is_null($this->userObj->getGender())) { $updateUser->setGender($this->userObj->getGender()); } if (!is_null($this->userObj->getEmail())) { $updateUser->setEmail($this->userObj->getEmail()); } if (!is_null($this->userObj->getBirthday())) { $updateUser->setBirthday($this->userObj->getBirthday()); } if (!is_null($this->userObj->getInstitution())) { $updateUser->setInstitution($this->userObj->getInstitution()); } if (!is_null($this->userObj->getStreet())) { $updateUser->setStreet($this->userObj->getStreet()); } if (!is_null($this->userObj->getCity())) { $updateUser->setCity($this->userObj->getCity()); } if (!is_null($this->userObj->getZipCode())) { $updateUser->setZipCode($this->userObj->getZipCode()); } if (!is_null($this->userObj->getCountry())) { $updateUser->setCountry($this->userObj->getCountry()); } if (!is_null($this->userObj->getPhoneOffice())) { $updateUser->setPhoneOffice($this->userObj->getPhoneOffice()); } if (!is_null($this->userObj->getPhoneHome())) { $updateUser->setPhoneHome($this->userObj->getPhoneHome()); } if (!is_null($this->userObj->getPhoneMobile())) { $updateUser->setPhoneMobile($this->userObj->getPhoneMobile()); } if (!is_null($this->userObj->getFax())) { $updateUser->setFax($this->userObj->getFax()); } if (!is_null($this->userObj->getHobby())) { $updateUser->setHobby($this->userObj->getHobby()); } if (!is_null($this->userObj->getComment())) { $updateUser->setComment($this->userObj->getComment()); } if (!is_null($this->userObj->getDepartment())) { $updateUser->setDepartment($this->userObj->getDepartment()); } if (!is_null($this->userObj->getMatriculation())) { $updateUser->setMatriculation($this->userObj->getMatriculation()); } if (!is_null($this->currActive)) { $updateUser->setActive($this->currActive == "true", is_object($ilUser) ? $ilUser->getId() : 0); } if (!is_null($this->userObj->getClientIP())) { $updateUser->setClientIP($this->userObj->getClientIP()); } if (!is_null($this->userObj->getTimeLimitUnlimited())) { $updateUser->setTimeLimitUnlimited($this->userObj->getTimeLimitUnlimited()); } if (!is_null($this->userObj->getTimeLimitFrom())) { $updateUser->setTimeLimitFrom($this->userObj->getTimeLimitFrom()); } if (!is_null($this->userObj->getTimeLimitUntil())) { $updateUser->setTimeLimitUntil($this->userObj->getTimeLimitUntil()); } if (!is_null($this->userObj->getTimeLimitMessage())) { $updateUser->setTimeLimitMessage($this->userObj->getTimeLimitMessage()); } if (!is_null($this->userObj->getApproveDate())) { $updateUser->setApproveDate($this->userObj->getApproveDate()); } if (!is_null($this->userObj->getAgreeDate())) { $updateUser->setAgreeDate($this->userObj->getAgreeDate()); } if (!is_null($this->userObj->getLanguage())) { $updateUser->setLanguage($this->userObj->getLanguage()); } if (!is_null($this->userObj->getExternalAccount())) { $updateUser->setExternalAccount($this->userObj->getExternalAccount()); } // Fixed: if auth_mode is not set, it was always overwritten with auth_default #if (! is_null($this->userObj->getAuthMode())) $updateUser->setAuthMode($this->userObj->getAuthMode()); if ($this->auth_mode_set) { $updateUser->setAuthMode($this->userObj->getAuthMode()); } if (!is_null($this->userObj->getInstantMessengerId("aim"))) { $updateUser->setInstantMessengerId("aim", $this->userObj->getInstantMessengerId("aim")); } if (!is_null($this->userObj->getInstantMessengerId("msn"))) { $updateUser->setInstantMessengerId("msn", $this->userObj->getInstantMessengerId("msn")); } if (!is_null($this->userObj->getInstantMessengerId("icq"))) { $updateUser->setInstantMessengerId("icq", $this->userObj->getInstantMessengerId("icq")); } if (!is_null($this->userObj->getInstantMessengerId("yahoo"))) { $updateUser->setInstantMessengerId("yahoo", $this->userObj->getInstantMessengerId("yahoo")); } if (!is_null($this->userObj->getInstantMessengerId("skype"))) { $updateUser->setInstantMessengerId("skype", $this->userObj->getInstantMessengerId("skype")); } if (!is_null($this->userObj->getInstantMessengerId("jabber"))) { $updateUser->setInstantMessengerId("jabber", $this->userObj->getInstantMessengerId("jabber")); } if (!is_null($this->userObj->getInstantMessengerId("voip"))) { $updateUser->setInstantMessengerId("voip", $this->userObj->getInstantMessengerId("voip")); } // Special handlin since it defaults to 7 (USER_FOLDER_ID) if ($this->time_limit_owner_set) { $updateUser->setTimeLimitOwner($this->userObj->getTimeLimitOwner()); } if (count($this->prefs)) { foreach ($this->prefs as $key => $value) { if ($key != "mail_incoming_type" && $key != "mail_signature" && $key != "mail_linebreak") { $updateUser->setPref($key, $value); } } } // save user preferences (skin and style) if ($this->updateLookAndSkin) { $updateUser->setPref("skin", $this->userObj->getPref("skin")); $updateUser->setPref("style", $this->userObj->getPref("style")); } $updateUser->writePrefs(); // update mail preferences, to be extended $this->updateMailPreferences($updateUser->getId()); // #8759 if (count($this->udf_data)) { $updateUser->setUserDefinedData($this->udf_data); } $updateUser->setProfileIncomplete($this->checkProfileIncomplete($updateUser)); $updateUser->setTitle($updateUser->getFullname()); $updateUser->setDescription($updateUser->getEmail()); $updateUser->update(); if ($this->ilincdata["id"]) { include_once 'Modules/ILinc/classes/class.ilObjiLincUser.php'; $ilinc_user = new ilObjiLincUser($updateUser); $ilinc_user->setVar("id", $this->ilincdata["id"]); $ilinc_user->setVar("login", $this->ilincdata["login"]); $ilinc_user->setVar("passwd", $this->ilincdata["password"]); $ilinc_user->update(); } if (count($this->udf_data)) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $udd = new ilUserDefinedData($updateUser->getId()); foreach ($this->udf_data as $field => $value) { $udd->set("f_" . $field, $value); } $udd->update(); } // update login if (!is_null($this->userObj->getLogin()) && $this->user_id != -1) { try { $updateUser->updateLogin($this->userObj->getLogin()); } catch (ilUserException $e) { } } // if language has changed if (is_array($this->personalPicture)) { if (strlen($this->personalPicture["content"])) { $extension = "jpg"; if (preg_match("/.*(png|jpg|gif|jpeg)\$/", $this->personalPicture["imagetype"], $matches)) { $extension = $matches[1]; } $tmp_name = $this->saveTempImage($this->personalPicture["content"], ".{$extension}"); if (strlen($tmp_name)) { ilObjUser::_uploadPersonalPicture($tmp_name, $this->userObj->getId()); unlink($tmp_name); } } } //update role entries //------------------- foreach ($this->roles as $role_id => $role) { if ($this->role_assign[$role_id]) { switch ($role["action"]) { case "Assign": $this->assignToRole($updateUser, $this->role_assign[$role_id]); break; case "AssignWithParents": $this->assignToRoleWithParents($updateUser, $this->role_assign[$role_id]); break; case "Detach": $this->detachFromRole($updateUser, $this->role_assign[$role_id]); break; } } } $this->logSuccess($updateUser->getLogin(), $user_id, "Update"); } break; case "Delete": if (!$user_id) { $this->logFailure($this->userObj->getLogin(), $lng->txt("usrimport_cant_delete")); } else { $deleteUser = new ilObjUser($user_id); $deleteUser->delete(); $this->logSuccess($this->userObj->getLogin(), $user_id, "Delete"); } break; } // init role array for next user $this->roles = array(); break; case "Login": $this->userObj->setLogin($this->cdata); break; case "Password": $this->currPassword = $this->cdata; break; case "Firstname": $this->userObj->setFirstname($this->cdata); break; case "Lastname": $this->userObj->setLastname($this->cdata); break; case "Title": $this->userObj->setUTitle($this->cdata); break; case "Gender": $this->userObj->setGender($this->cdata); break; case "Email": $this->userObj->setEmail($this->cdata); break; case "Birthday": $timestamp = strtotime($this->cdata); if ($timestamp !== false) { $this->userObj->setBirthday($this->cdata); } break; case "Institution": $this->userObj->setInstitution($this->cdata); break; case "Street": $this->userObj->setStreet($this->cdata); break; case "City": $this->userObj->setCity($this->cdata); break; case "PostalCode": $this->userObj->setZipCode($this->cdata); break; case "Country": $this->userObj->setCountry($this->cdata); break; case "PhoneOffice": $this->userObj->setPhoneOffice($this->cdata); break; case "PhoneHome": $this->userObj->setPhoneHome($this->cdata); break; case "PhoneMobile": $this->userObj->setPhoneMobile($this->cdata); break; case "Fax": $this->userObj->setFax($this->cdata); break; case "Hobby": $this->userObj->setHobby($this->cdata); break; case "Comment": $this->userObj->setComment($this->cdata); break; case "Department": $this->userObj->setDepartment($this->cdata); break; case "Matriculation": $this->userObj->setMatriculation($this->cdata); break; case "Active": $this->currActive = $this->cdata; break; case "ClientIP": $this->userObj->setClientIP($this->cdata); break; case "TimeLimitOwner": $this->time_limit_owner_set = true; $this->userObj->setTimeLimitOwner($this->cdata); break; case "TimeLimitUnlimited": $this->time_limit_set = true; $this->userObj->setTimeLimitUnlimited($this->cdata); break; case "TimeLimitFrom": if (is_numeric($this->cdata)) { // Treat cdata as a unix timestamp $this->userObj->setTimeLimitFrom($this->cdata); } else { // Try to convert cdata into unix timestamp, or ignore it $timestamp = strtotime($this->cdata); if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") { $this->userObj->setTimeLimitFrom($timestamp); } elseif ($this->cdata == "0000-00-00 00:00:00") { $this->userObj->setTimeLimitFrom(null); } } break; case "TimeLimitUntil": if (is_numeric($this->cdata)) { // Treat cdata as a unix timestamp $this->userObj->setTimeLimitUntil($this->cdata); } else { // Try to convert cdata into unix timestamp, or ignore it $timestamp = strtotime($this->cdata); if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") { $this->userObj->setTimeLimitUntil($timestamp); } elseif ($this->cdata == "0000-00-00 00:00:00") { $this->userObj->setTimeLimitUntil(null); } } break; case "TimeLimitMessage": $this->userObj->setTimeLimitMessage($this->cdata); break; case "ApproveDate": $this->approve_date_set = true; if (is_numeric($this->cdata)) { // Treat cdata as a unix timestamp $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX); $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME)); } else { // Try to convert cdata into unix timestamp, or ignore it $timestamp = strtotime($this->cdata); if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") { $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX); $this->userObj->setApproveDate($tmp_date->get(IL_CAL_DATETIME)); } elseif ($this->cdata == "0000-00-00 00:00:00") { $this->userObj->setApproveDate(null); } } break; case "AgreeDate": if (is_numeric($this->cdata)) { // Treat cdata as a unix timestamp $tmp_date = new ilDateTime($this->cdata, IL_CAL_UNIX); $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME)); } else { // Try to convert cdata into unix timestamp, or ignore it $timestamp = strtotime($this->cdata); if ($timestamp !== false && trim($this->cdata) != "0000-00-00 00:00:00") { $tmp_date = new ilDateTime($timestamp, IL_CAL_UNIX); $this->userObj->setAgreeDate($tmp_date->get(IL_CAL_DATETIME)); } elseif ($this->cdata == "0000-00-00 00:00:00") { $this->userObj->setAgreeDate(null); } } break; case "iLincID": $this->ilincdata["id"] = $this->cdata; break; case "iLincLogin": $this->{$ilincdata}["login"] = $this->cdata; break; case "iLincPasswd": $this->{$ilincdata}["password"] = $this->cdata; //$this->userObj->setiLincData($this->ilincdata); break; case "ExternalAccount": $this->userObj->setExternalAccount($this->cdata); break; case "Look": $this->updateLookAndSkin = false; if (!$this->hideSkin) { // TODO: what to do with disabled skins? is it possible to change the skin via import? if (strlen($this->skin) > 0 && strlen($this->style) > 0) { if (is_array($this->userStyles)) { if (in_array($this->skin . ":" . $this->style, $this->userStyles)) { $this->userObj->setPref("skin", $this->skin); $this->userObj->setPref("style", $this->style); $this->updateLookAndSkin = true; } } } } break; case 'UserDefinedField': include_once './Services/User/classes/class.ilUserDefinedFields.php'; $udf = ilUserDefinedFields::_getInstance(); if ($field_id = $udf->fetchFieldIdFromImportId($this->tmp_udf_id)) { $this->udf_data[$field_id] = $this->cdata; } elseif ($field_id = $udf->fetchFieldIdFromName($this->tmp_udf_name)) { $this->udf_data[$field_id] = $this->cdata; } break; case 'AccountInfo': if ($this->current_messenger_type == "delicious") { $this->userObj->setDelicious($this->cdata); } elseif ($this->current_messenger_type == "external") { $this->userObj->setExternalAccount($this->cdata); } else { $this->userObj->setInstantMessengerId($this->current_messenger_type, $this->cdata); } break; case 'Pref': if ($this->currentPrefKey != null && strlen(trim($this->cdata)) > 0 && ilUserXMLWriter::isPrefExportable($this->currentPrefKey)) { $this->prefs[$this->currentPrefKey] = trim($this->cdata); } $this->currentPrefKey = null; break; } }
function deleteUserDefinedFieldEntries() { global $ilDB; include_once "./Services/User/classes/class.ilUserDefinedData.php"; ilUserDefinedData::deleteEntriesOfUser($this->getId()); // wrong place... /* $query = "DELETE FROM udf_data ". "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer'); $res = $ilDB->manipulate($query);*/ return true; }
/** * Parse user data * @param array $a_user_data * @return */ public function parse($a_user_data) { include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); switch ($this->type) { case 'admin': $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getAdmins(); break; case 'member': $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getMembers(); break; } $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData('login', 'ASC', 0, 9999, '', '', null, false, false, 0, 0, null, $usr_data_fields, $part); // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($part, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { if ($a_user_data[$usr_id]) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } return $this->setData($a_user_data); }
function update() { global $lng, $ilCtrl; $user_field_definitions = ilUserDefinedFields::_getInstance(); $user_field_definitions->setFieldType($this->field_definition["field_type"]); // gather old select options $old_options = null; if ($this->field_id) { $old_values = $user_field_definitions->getDefinition($this->field_id); if ($old_values["field_type"] == UDF_TYPE_SELECT) { $old_options = $old_values["field_values"]; } $perms = $this->permissions->hasPermissions(ilUDFPermissionHelper::CONTEXT_FIELD, $this->field_id, array(array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper::SUBACTION_FIELD_TITLE), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper::SUBACTION_FIELD_PROPERTIES), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_COURSES), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_REQUIRED), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_EXPORT), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_SEARCHABLE), array(ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper::SUBACTION_FIELD_ACCESS_CERTIFICATE))); } $access = array(); $form = $this->initForm("edit"); if ($this->validateForm($form, $user_field_definitions, $access, $perms) && $this->field_id) { // field values are set in validateForm()... if (!$perms || $perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY][ilUDFPermissionHelper::SUBACTION_FIELD_PROPERTIES]) { // diff old select options against new to handle deleted values properly if (is_array($old_options)) { foreach ($old_options as $old_option) { if (!in_array($old_option, $user_field_definitions->getFieldValues())) { ilUserDefinedData::deleteFieldValue($this->field_id, $old_option); } } } } else { if (is_array($old_options)) { $user_field_definitions->setFieldValues($old_options); } } if (!$perms || $perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_PROPERTY][ilUDFPermissionHelper::SUBACTION_FIELD_TITLE]) { $user_field_definitions->setFieldName($form->getInput("name")); } else { $user_field_definitions->setFieldName($this->field_definition["field_name"]); } $user_field_definitions->enableVisible($access['visible']); $user_field_definitions->enableVisibleRegistration((int) $access['visib_reg']); $user_field_definitions->enableVisibleLocalUserAdministration($access['visib_lua']); $user_field_definitions->enableCourseExport($access['course_export']); $user_field_definitions->enableGroupExport($access['group_export']); $user_field_definitions->enableChangeable($access['changeable']); $user_field_definitions->enableChangeableLocalUserAdministration($access['changeable_lua']); $user_field_definitions->enableRequired($access['required']); $user_field_definitions->enableExport($access['export']); $user_field_definitions->enableSearchable($access['searchable']); $user_field_definitions->enableCertificate($access['certificate']); $user_field_definitions->update($this->field_id); if ($access['course_export']) { include_once 'Services/Membership/classes/class.ilMemberAgreement.php'; ilMemberAgreement::_reset(); } ilUtil::sendSuccess($lng->txt('udf_added_field'), true); $ilCtrl->redirect($this); } $form->setValuesByPost(); $this->edit($form); }
/** * Parse user data * @param array $a_user_data * @return */ public function parse($a_user_data) { include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); unset($additional_fields['consultation_hour']); unset($additional_fields['prtf']); switch ($this->type) { case 'admin': $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getAdmins(); break; case 'member': $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole()); break; case 'role': $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole()); break; } $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData('login', 'ASC', 0, 9999, '', '', null, false, false, 0, 0, null, $usr_data_fields, $part); // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($part, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { if ($a_user_data[$usr_id]) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } // consultation hours if ($this->isColumnSelected('consultation_hour')) { include_once './Services/Booking/classes/class.ilBookingEntry.php'; foreach (ilBookingEntry::lookupManagedBookingsForObject($this->getParentObject()->object->getId(), $GLOBALS['ilUser']->getId()) as $buser => $booking) { if (isset($a_user_data[$buser])) { $a_user_data[$buser]['consultation_hour'] = $booking[0]['dt']; $a_user_data[$buser]['consultation_hour_end'] = $booking[0]['dtend']; $a_user_data[$buser]['consultation_hours'] = $booking; } } } return $this->setData($a_user_data); }
/** * Parse user data * @return * @param array $a_user_ids */ public function parseUserIds($a_user_ids) { if (!$a_user_ids) { $this->setData(array()); return true; } $additional_fields = $this->getSelectedColumns(); $parse_access = false; if (isset($additional_fields['access_until'])) { $parse_access = true; unset($additional_fields['access_until']); } $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } include_once './Services/User/classes/class.ilUserQuery.php'; $usr_data = ilUserQuery::getUserListData('login', 'ASC', 0, 999999, '', '', null, false, false, 0, 0, null, $usr_data_fields, $a_user_ids); if ($this->admin_mode && $parse_access) { // see ilUserTableGUI $current_time = time(); foreach ($usr_data['set'] as $k => $user) { if ($user['active']) { if ($user["time_limit_unlimited"]) { $txt_access = $this->lng->txt("access_unlimited"); $usr_data["set"][$k]["access_class"] = "smallgreen"; } elseif ($user["time_limit_until"] < $current_time) { $txt_access = $this->lng->txt("access_expired"); $usr_data["set"][$k]["access_class"] = "smallred"; } else { $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"], IL_CAL_UNIX)); $usr_data["set"][$k]["access_class"] = "small"; } } else { $txt_access = $this->lng->txt("inactive"); $usr_data["set"][$k]["access_class"] = "smallred"; } $usr_data["set"][$k]["access_until"] = $txt_access; } } // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids); $users = array(); $counter = 0; foreach ($usr_data['set'] as $set) { $users[$counter] = $set; foreach ($udf_ids as $udf_field) { $users[$counter]['udf_' . $udf_field] = $data[$set['usr_id']][$udf_field]; } ++$counter; } } else { $users = $usr_data['set']; } if ($this->getType() == self::TYPE_GLOBAL_SEARCH) { if ($this->getLuceneResult() instanceof ilLuceneSearchResult) { foreach ($users as $counter => $ud) { $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance($ud['usr_id']); } } } $this->setData($users); }
/** * Parse user data * @param array $a_user_data * @return */ public function parse($a_user_data) { include_once './Services/User/classes/class.ilUserQuery.php'; $additional_fields = $this->getSelectedColumns(); unset($additional_fields["firstname"]); unset($additional_fields["lastname"]); unset($additional_fields["last_login"]); unset($additional_fields["access_until"]); unset($additional_fields['consultation_hour']); unset($additional_fields['prtf']); switch ($this->type) { case 'admin': $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getAdmins(); break; case 'member': $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole()); break; case 'role': $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole()); break; } $udf_ids = $usr_data_fields = $odf_ids = array(); foreach ($additional_fields as $field) { if (substr($field, 0, 3) == 'udf') { $udf_ids[] = substr($field, 4); continue; } if (substr($field, 0, 3) == 'odf') { $odf_ids[] = substr($field, 4); continue; } $usr_data_fields[] = $field; } $usr_data = ilUserQuery::getUserListData('login', 'ASC', 0, 9999, '', '', null, false, false, 0, 0, null, $usr_data_fields, $part); // Custom user data fields if ($udf_ids) { include_once './Services/User/classes/class.ilUserDefinedData.php'; $data = ilUserDefinedData::lookupData($part, $udf_ids); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { $a_user_data[$usr_id]['udf_' . $field_id] = $value; } } } // Object specific user data fields if ($odf_ids) { include_once './Modules/Course/classes/Export/class.ilCourseUserData.php'; $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId()); foreach ($data as $usr_id => $fields) { if (!$this->checkAcceptance($usr_id)) { continue; } foreach ($fields as $field_id => $value) { if ($a_user_data[$usr_id]) { $a_user_data[$usr_id]['odf_' . $field_id] = $value; } } } // add last edit date include_once './Services/Membership/classes/class.ilObjectCustomUserFieldHistory.php'; foreach (ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getParentObject()->object->getId()) as $usr_id => $edit_info) { if (!isset($a_user_data[$usr_id])) { continue; } include_once './Services/PrivacySecurity/classes/class.ilPrivacySettings.php'; if ($usr_id == $edit_info['update_user']) { $a_user_data[$usr_id]['odf_last_update'] = ''; $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['lng']->txt('cdf_edited_by_self'); if (ilPrivacySettings::_getInstance()->enabledAccessTimesByType($this->getParentObject()->object->getType())) { $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $a_user_data[$usr_id]['odf_info_txt'] .= ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } else { $a_user_data[$usr_id]['odf_last_update'] = $edit_info['edit_user']; $a_user_data[$usr_id]['odf_last_update'] .= '_' . $edit_info['editing_time']->get(IL_CAL_UNIX); $name = ilObjUser::_lookupName($edit_info['update_user']); $a_user_data[$usr_id]['odf_info_txt'] = $name['firstname'] . ' ' . $name['lastname'] . ', ' . ilDatePresentation::formatDate($edit_info['editing_time']); } } } foreach ($usr_data['set'] as $user) { // Check acceptance if (!$this->checkAcceptance($user['usr_id'])) { continue; } // DONE: accepted foreach ($usr_data_fields as $field) { $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : ''; } } // consultation hours if ($this->isColumnSelected('consultation_hour')) { include_once './Services/Booking/classes/class.ilBookingEntry.php'; foreach (ilBookingEntry::lookupManagedBookingsForObject($this->getParentObject()->object->getId(), $GLOBALS['ilUser']->getId()) as $buser => $booking) { if (isset($a_user_data[$buser])) { $a_user_data[$buser]['consultation_hour'] = $booking[0]['dt']; $a_user_data[$buser]['consultation_hour_end'] = $booking[0]['dtend']; $a_user_data[$buser]['consultation_hours'] = $booking; } } } return $this->setData($a_user_data); }
function update() { global $lng, $ilCtrl; $user_field_definitions = ilUserDefinedFields::_getInstance(); $user_field_definitions->setFieldType($this->field_definition["field_type"]); // gather old select options $old_options = null; if ($this->field_id) { $old_values = $user_field_definitions->getDefinition($this->field_id); if ($old_values["field_type"] == UDF_TYPE_SELECT) { $old_options = $old_values["field_values"]; } } $access = array(); $form = $this->initForm("edit"); if ($this->validateForm($form, $user_field_definitions, $access) && $this->field_id) { // field values are set in validateForm()... // diff old select options against new to handle deleted values properly if (is_array($old_options)) { foreach ($old_options as $old_option) { if (!in_array($old_option, $user_field_definitions->getFieldValues())) { ilUserDefinedData::deleteFieldValue($this->field_id, $old_option); } } } $user_field_definitions->setFieldName($form->getInput("name")); $user_field_definitions->enableVisible($access['visible']); $user_field_definitions->enableVisibleRegistration((int) $access['visib_reg']); $user_field_definitions->enableVisibleLocalUserAdministration($access['visib_lua']); $user_field_definitions->enableCourseExport($access['course_export']); $user_field_definitions->enableGroupExport($access['group_export']); $user_field_definitions->enableChangeable($access['changeable']); $user_field_definitions->enableChangeableLocalUserAdministration($access['changeable_lua']); $user_field_definitions->enableRequired($access['required']); $user_field_definitions->enableExport($access['export']); $user_field_definitions->enableSearchable($access['searchable']); $user_field_definitions->enableCertificate($access['certificate']); $user_field_definitions->update($this->field_id); if ($access['course_export']) { include_once 'Services/Membership/classes/class.ilMemberAgreement.php'; ilMemberAgreement::_reset(); } ilUtil::sendSuccess($lng->txt('udf_added_field'), true); $ilCtrl->redirect($this); } $form->setValuesByPost(); $this->edit($form); }