/** * Parse table content */ public function parse() { $this->initTable(); // @TODO add filter $users = $this->getParentObject()->object->getTrackedUsers($this->filter['lastname']); $attempts = $this->getParentObject()->object->getAttemptsForUsers(); $versions = $this->getParentObject()->object->getModuleVersionForUsers(); include_once './Services/PrivacySecurity/classes/class.ilPrivacySettings.php'; $privacy = ilPrivacySettings::_getInstance(); $allowExportPrivacy = $privacy->enabledExportSCORM(); $data = array(); foreach ($users as $user) { $tmp = array(); $tmp['user'] = $user['user_id']; if ($allowExportPrivacy == true) { $tmp['name'] = $user['lastname'] . ', ' . $user['firstname']; } else { $tmp['name'] = $user['user_id']; } $dt = new ilDateTime($user['last_access'], IL_CAL_DATETIME); $tmp['last_access'] = $dt->get(IL_CAL_UNIX); $tmp['attempts'] = (int) $attempts[$user['user_id']]; $tmp['version'] = (int) $versions[$user['user_id']]; $data[] = $tmp; } $this->setData($data); }
/** * Calculates schedules. */ public function calculate() { $events = $this->getEvents(); // we need category type for booking handling $ids = array(); foreach ($events as $event) { $ids[] = $event->getEntryId(); } $counter = 0; foreach ($events as $event) { $this->schedule[$counter]['event'] = $event; $this->schedule[$counter]['dstart'] = $event->getStart()->get(IL_CAL_UNIX); $this->schedule[$counter]['dend'] = $event->getEnd()->get(IL_CAL_UNIX); $this->schedule[$counter]['fullday'] = $event->isFullday(); if (!$event->isFullday()) { switch ($this->type) { case self::TYPE_DAY: case self::TYPE_WEEK: // store date info (used for calculation of overlapping events) $start_date = new ilDateTime($this->schedule[$counter]['dstart'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['start_info'] = $start_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); $end_date = new ilDateTime($this->schedule[$counter]['dend'], IL_CAL_UNIX, $this->timezone); $this->schedule[$counter]['end_info'] = $end_date->get(IL_CAL_FKT_GETDATE, '', $this->timezone); break; default: break; } } $counter++; if ($this->areEventsLimited() && $counter >= $this->getEventsLimit()) { break; } } }
public function run() { global $ilSetting, $ilDB; $status = ilCronJobResult::STATUS_NO_ACTION; $days_before = $ilSetting->get('ch_reminder_days'); $now = new ilDateTime(time(), IL_CAL_UNIX); $limit = clone $now; $limit->increment(IL_CAL_DAY, $days_before); $counter = 0; $query = 'SELECT * FROM booking_user ' . 'JOIN cal_entries ON entry_id = cal_id ' . 'WHERE notification_sent = ' . $ilDB->quote(0, 'integer') . ' ' . 'AND starta > ' . $ilDB->quote($now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' . 'AND starta <= ' . $ilDB->quote($limit->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp'); $res = $ilDB->query($query); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php'; $mail = new ilCalendarMailNotification(); $mail->setAppointmentId($row->entry_id); $mail->setRecipients(array($row->user_id)); $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_REMINDER); $mail->send(); // update notification $query = 'UPDATE booking_user ' . 'SET notification_sent = ' . $ilDB->quote(1, 'integer') . ' ' . 'WHERE user_id = ' . $ilDB->quote($row->user_id, 'integer') . ' ' . 'AND entry_id = ' . $ilDB->quote($row->entry_id, 'integer'); $ilDB->manipulate($query); $counter++; } if ($counter) { $status = ilCronJobResult::STATUS_OK; } $result = new ilCronJobResult(); $result->setStatus($status); return $result; }
/** * Handle an event in a listener. * * @param string $a_component component, e.g. "Modules/Forum" or "Services/User" * @param string $a_event event e.g. "createUser", "updateUser", "deleteUser", ... * @param array $a_parameter parameter array (assoc), array("name" => ..., "phone_office" => ...) */ static function handleEvent($a_component, $a_event, $a_parameter) { global $ilLog; $ilLog->write(__METHOD__ . ': Listening to event from: ' . $a_component); switch ($a_component) { case 'Services/User': switch ($a_event) { case 'afterCreation': $user = $a_parameter['user_obj']; $this->handleMembership($user); break; } break; case 'Modules/Course': switch ($a_event) { case 'addSubscriber': case 'addParticipant': if (ilObjUser::_lookupAuthMode($a_parameter['usr_id']) == 'ecs') { if (!($user = ilObjectFactory::getInstanceByObjId($a_parameter['usr_id']))) { $GLOBALS['ilLog']->write(__METHOD__ . ': No valid user found for usr_id ' . $a_parameter['usr_id']); return true; } include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; $server_id = ilECSImport::lookupServerId($a_parameter['usr_id']); $GLOBALS['ilLog']->write(__METHOD__ . ': Found server id: ' . $server_id); include_once 'Services/WebServices/ECS/classes/class.ilECSSetting.php'; $settings = ilECSSetting::getInstanceByServerId($server_id); $end = new ilDateTime(time(), IL_CAL_UNIX); $end->increment(IL_CAL_MONTH, $settings->getDuration()); if ($user->getTimeLimitUntil() < $end->get(IL_CAL_UNIX)) { $user->setTimeLimitUntil($end->get(IL_CAL_UNIX)); $user->update(); } self::_sendNotification($settings, $user); unset($user); } break; } break; } }
protected function buildJson(ilECSSetting $a_server) { $json = $this->getJsonCore('application/ecs-file'); $json->version = $this->content_obj->getVersion(); require_once "./Services/History/classes/class.ilHistory.php"; $entries = ilHistory::_getEntriesForObject($this->content_obj->getId(), $this->content_obj->getType()); if (count($entries)) { $entry = array_shift($entries); $entry = new ilDateTime($entry["date"], IL_CAL_DATETIME); $json->version_date = $entry->get(IL_CAL_UNIX); } else { $json->version_date = time(); } return $json; }
public function getLuceneSearchString($a_value) { // see ilADTDateTimeSearchBridgeRange::importFromPost(); if ($a_value["tgl"]) { $start = mktime($a_value["lower"]["time"]["h"], $a_value["lower"]["time"]["m"], 1, $a_value["lower"]["date"]["m"], $a_value["lower"]["date"]["d"], $a_value["lower"]["date"]["y"]); $end = mktime($a_value["upper"]["time"]["h"], $a_value["upper"]["time"]["m"], 1, $a_value["upper"]["date"]["m"], $a_value["upper"]["date"]["d"], $a_value["upper"]["date"]["y"]); if ($start && $end && $start > $end) { $tmp = $start; $start = $end; $end = $tmp; } $start = new ilDateTime($start, IL_CAL_UNIX); $end = new ilDateTime($end, IL_CAL_UNIX); return "{" . $start->get(IL_CAL_DATETIME) . " TO " . $end->get(IL_CAL_DATETIME) . "}"; } }
/** * Get appointment ids by consultation hour group * @param type $a_user_id * @param type $a_ch_group_id * @param ilDateTime $start */ public static function getAppointmentIdsByGroup($a_user_id, $a_ch_group_id, ilDateTime $start = null) { global $ilDB; // @todo check start time include_once './Services/Calendar/classes/class.ilCalendarCategory.php'; $type = ilCalendarCategory::TYPE_CH; $start_limit = ''; if ($start instanceof ilDateTime) { $start_limit = 'AND ce.starta >= ' . $ilDB->quote($start->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp'); } $query = 'SELECT ce.cal_id FROM cal_entries ce ' . 'JOIN cal_cat_assignments ca ON ce.cal_id = ca.cal_id ' . 'JOIN cal_categories cc ON ca.cat_id = cc.cat_id ' . 'JOIN booking_entry be ON ce.context_id = be.booking_id ' . 'WHERE cc.obj_id = ' . $ilDB->quote($a_user_id, 'integer') . ' ' . 'AND cc.type = ' . $ilDB->quote($type, 'integer') . ' ' . 'AND be.booking_group = ' . $ilDB->quote($a_ch_group_id, 'integer') . ' ' . $start_limit . ' ' . 'ORDER BY ce.starta '; $res = $ilDB->query($query); $app_ids = array(); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $app_ids[] = $row->cal_id; } return $app_ids; }
/** * Parse table content */ public function parse() { $this->initTable(); // @TODO add filter $users = $this->getParentObject()->object->getTrackedUsers($this->filter['lastname']); $attempts = $this->getParentObject()->object->getAttemptsForUsers(); $versions = $this->getParentObject()->object->getModuleVersionForUsers(); $data = array(); foreach ($users as $user) { $tmp = array(); $tmp['user'] = $user['user_id']; $tmp['firstname'] = $user['firstname']; $tmp['lastname'] = $user['lastname']; $dt = new ilDateTime($user['last_access'], IL_CAL_DATETIME); $tmp['last_access'] = $dt->get(IL_CAL_UNIX); $tmp['attempts'] = (int) $attempts[$user['user_id']]; $tmp['version'] = (int) $versions[$user['user_id']]; $data[] = $tmp; } $this->setData($data); }
function _getProgress($a_user_id, $a_obj_id) { require_once 'Services/Tracking/classes/class.ilChangeEvent.php'; $events = ilChangeEvent::_lookupReadEvents($a_obj_id, $a_user_id); include_once './Services/Calendar/classes/class.ilDateTime.php'; foreach ($events as $row) { $tmp_date = new ilDateTime($row['last_access'], IL_CAL_UNIX); $row['last_access'] = $tmp_date->get(IL_CAL_TIMESTAMP); if ($progress) { $progress['spent_seconds'] += $row['spent_seconds']; $progress['access_time'] = max($progress['access_time'], $row['last_access']); } else { $progress['obj_id'] = $row['obj_id']; $progress['user_id'] = $row['usr_id']; $progress['spent_seconds'] = $row['spent_seconds']; $progress['access_time'] = $row['last_access']; $progress['visits'] = $row['read_count']; } } return $progress ? $progress : array(); }
/** * Check input, strip slashes etc. set alert, if input is not ok. * * @return boolean Input ok, true/false */ function checkInput() { global $lng, $ilUser; $ok = true; $_POST[$this->getPostVar()]["date"]["y"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]); $_POST[$this->getPostVar()]["date"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]); $_POST[$this->getPostVar()]["date"]["d"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]); $_POST[$this->getPostVar()]["time"]["h"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]); $_POST[$this->getPostVar()]["time"]["m"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]); $_POST[$this->getPostVar()]["time"]["s"] = ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]); // verify date $dt['year'] = (int) $_POST[$this->getPostVar()]['date']['y']; $dt['mon'] = (int) $_POST[$this->getPostVar()]['date']['m']; $dt['mday'] = (int) $_POST[$this->getPostVar()]['date']['d']; $dt['hours'] = (int) $_POST[$this->getPostVar()]['time']['h']; $dt['minutes'] = (int) $_POST[$this->getPostVar()]['time']['m']; $dt['seconds'] = (int) $_POST[$this->getPostVar()]['time']['s']; if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0 && $this->getRequired()) { $this->date = null; $this->setAlert($lng->txt("msg_input_is_required")); return false; } else { if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0) { $this->date = null; $_POST[$this->getPostVar()]['date'] = ""; // #10413 } else { if (!checkdate((int) $dt['mon'], (int) $dt['mday'], (int) $dt['year'])) { $this->date = null; $this->setAlert($lng->txt("exc_date_not_valid")); return false; } $date = new ilDateTime($dt, IL_CAL_FKT_GETDATE, $ilUser->getTimeZone()); $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE, 'Y-m-d', $ilUser->getTimeZone()); $this->setDate($date); } } return true; }
public function createVmsSessionCode($a_vuser_id, $a_group_id, ilDateTime $expires) { $GLOBALS['ilLog']->write('Creating new vms session code'); try { $this->initClient(); $req = new stdClass(); $req->sessioncode = new stdClass(); $req->sessioncode->userid = (int) $a_vuser_id; $req->sessioncode->groupid = (int) $a_group_id; $req->sessioncode->codelength = self::CODELENGTH; $req->sessioncode->expirationdate = $expires->get(IL_CAL_FKT_DATE, 'YmdHi', self::CONVERT_TIMZONE); $req->sessioncode->timezone = self::WS_TIMEZONE; $reps = $this->getClient()->createVmsSessionCode($req); ilViteroSessionStore::getInstance()->addSession($a_vuser_id, $reps->code, $expires, self::SESSION_TYPE_VMS); return $reps->code; } catch (SoapFault $e) { $code = $this->parseErrorCode($e); $GLOBALS['ilLog']->write(__METHOD__ . ': Creating vms session code failed with message: ' . $code); $GLOBALS['ilLog']->write(__METHOD__ . ': Last request: ' . $this->getClient()->__getLastRequest()); $GLOBALS['ilLog']->write(__METHOD__ . ': Last request: ' . $this->getClient()->__getLastResponse()); throw new ilViteroConnectorException($e->getMessage(), $code); } }
/** * save one entry * * @access public * */ public function save() { global $ilDB; $next_id = $ilDB->nextId('cal_entries'); $now = new ilDateTime(time(), IL_CAL_UNIX); $utc_timestamp = $now->get(IL_CAL_TIMESTAMP, '', ilTimeZone::UTC); $query = "INSERT INTO cal_entries (cal_id,title,last_update,subtitle,description,location,fullday,starta,enda, " . "informations,auto_generated,context_id,translation_type, completion, is_milestone, notification) " . "VALUES( " . $ilDB->quote($next_id, 'integer') . ", " . $this->db->quote($this->getTitle(), 'text') . ", " . $ilDB->quote($utc_timestamp, 'timestamp') . ", " . $this->db->quote($this->getSubtitle(), 'text') . ", " . $this->db->quote($this->getDescription(), 'text') . ", " . $this->db->quote($this->getLocation(), 'text') . ", " . $ilDB->quote($this->isFullday() ? 1 : 0, 'integer') . ", " . $this->db->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " . $this->db->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " . $this->db->quote($this->getFurtherInformations(), 'text') . ", " . $this->db->quote($this->isAutoGenerated(), 'integer') . ", " . $this->db->quote($this->getContextId(), 'integer') . ", " . $this->db->quote($this->getTranslationType(), 'integer') . ", " . $this->db->quote($this->getCompletion(), 'integer') . ", " . $this->db->quote($this->isMilestone() ? 1 : 0, 'integer') . ", " . $this->db->quote($this->isNotificationEnabled() ? 1 : 0, 'integer') . ' ' . ")"; $res = $ilDB->manipulate($query); $this->entry_id = $next_id; return true; }
/** * confirmation screen for export file deletion */ function confirmDeleteExportFileObject() { global $ilTabs; $this->handleWriteAccess(); $ilTabs->activateTab("export"); if (!isset($_POST["file"])) { ilUtil::sendFailure($this->lng->txt("no_checkbox"), true); $this->ctrl->redirect($this, "export"); } ilUtil::sendQuestion($this->lng->txt("info_delete_sure")); $export_dir = $this->object->getExportDirectory(); $export_files = $this->object->getExportFiles($export_dir); $data = array(); if (count($_POST["file"]) > 0) { foreach ($_POST["file"] as $exp_file) { $file_arr = explode("__", $exp_file); $date = new ilDateTime($file_arr[0], IL_CAL_UNIX); array_push($data, array('file' => $exp_file, 'size' => filesize($export_dir . "/" . $exp_file), 'date' => $date->get(IL_CAL_DATETIME))); } } include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php"; $table_gui = new ilSurveyExportTableGUI($this, 'export', true); $table_gui->setData($data); $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML()); }
/** * save Record * * @param string $a_mode values: create | edit */ public function save() { global $tpl, $ilUser, $lng, $ilCtrl; $this->initForm(); if ($this->form->checkInput()) { $record_obj = ilDataCollectionCache::getRecordCache($this->record_id); $date_obj = new ilDateTime(time(), IL_CAL_UNIX); $record_obj->setTableId($this->table_id); $record_obj->setLastUpdate($date_obj->get(IL_CAL_DATETIME)); $record_obj->setLastEditBy($ilUser->getId()); $create_mode = false; if (ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id)) { $all_fields = $this->table->getRecordFields(); } else { $all_fields = $this->table->getEditableFields(); } $fail = ""; //Check if we can create this record. foreach ($all_fields as $field) { try { $value = $this->form->getInput("field_" . $field->getId()); $field->checkValidity($value, $this->record_id); } catch (ilDataCollectionInputException $e) { $fail .= $field->getTitle() . ": " . $e . "<br>"; } } if ($fail) { ilUtil::sendFailure($fail, true); $this->sendFailure(); return; } if (!isset($this->record_id)) { if (!$this->table->hasPermissionToAddRecord($this->parent_obj->ref_id)) { $this->accessDenied(); return; } $record_obj->setOwner($ilUser->getId()); $record_obj->setCreateDate($date_obj->get(IL_CAL_DATETIME)); $record_obj->setTableId($this->table_id); $record_obj->doCreate(); $this->record_id = $record_obj->getId(); $create_mode = true; } else { if (!$record_obj->hasPermissionToEdit($this->parent_obj->ref_id)) { $this->accessDenied(); return; } } //edit values, they are valid we already checked them above foreach ($all_fields as $field) { $value = $this->form->getInput("field_" . $field->getId()); //deletion flag on MOB inputs. if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_MOB && $this->form->getItemByPostVar("field_" . $field->getId())->getDeletionFlag()) { $value = -1; } $record_obj->setRecordFieldValue($field->getId(), $value); } // Do we need to set a new owner for this record? if (!$create_mode) { $owner_id = ilObjUser::_lookupId($_POST['field_owner']); if (!$owner_id) { ilUtil::sendFailure($lng->txt('user_not_known')); $this->sendFailure(); return; } $record_obj->setOwner($owner_id); } if ($create_mode) { ilObjDataCollection::sendNotification("new_record", $this->table_id, $record_obj->getId()); } $record_obj->doUpdate(); ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true); $ilCtrl->setParameter($this, "table_id", $this->table_id); $ilCtrl->setParameter($this, "record_id", $this->record_id); $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords"); } else { global $tpl; $this->form->setValuesByPost(); $tpl->setContent($this->form->getHTML()); } }
/** * Search database for all tree entries having no valid parent (=> no valid path to root node) * and stores result in $this->unbound_objects * Result also contains childs that are marked as deleted! Deleted childs has * a negative number in ["deleted"] otherwise NULL. * * @access public * @return boolean false if analyze mode disabled or nothing found * @see this::getUnboundObjects() * @see this::restoreUnboundObjects() */ function findDeletedObjects() { // check mode: analyze if ($this->mode["scan"] !== true) { return false; } // init $this->deleted_objects = array(); $this->writeScanLogLine("\nfindDeletedObjects:"); // Delete objects, start with the oldest objects first $query = "SELECT object_data.*,tree.tree,tree.child,tree.parent,deleted " . "FROM object_data " . "LEFT JOIN object_reference ON object_data.obj_id=object_reference.obj_id " . "LEFT JOIN tree ON tree.child=object_reference.ref_id " . " WHERE tree != 1 " . " ORDER BY deleted"; $r = $this->db->query($query); include_once './Services/Calendar/classes/class.ilDateTime.php'; while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) { $tmp_date = new ilDateTime($row->deleted, IL_CAL_DATETIME); $this->deleted_objects[] = array("child" => $row->child, "parent" => $row->parent, "tree" => $row->tree, "type" => $row->type, "title" => $row->title, "desc" => $row->description, "owner" => $row->owner, "deleted" => $row->deleted, "deleted_timestamp" => $tmp_date->get(IL_CAL_UNIX), "create_date" => $row->create_date, "last_update" => $row->last_update); } if (count($this->deleted_objects) > 0) { $this->writeScanLogArray(array(array_keys($this->deleted_objects[0]))); $this->writeScanLogArray($this->deleted_objects); return true; } $this->writeScanLogLine("none"); return false; }
/** * Save settings. */ function saveSettings() { global $ilCtrl, $ilUser; $this->initSettingsForm(); if ($this->settings_form->checkInput()) { $news_set = new ilSetting("news"); $enable_internal_rss = $news_set->get("enable_rss_for_internal"); if ($enable_internal_rss) { ilBlockSetting::_write($this->getBlockType(), "public_notifications", $_POST["notifications_public"], 0, $this->block_id); ilBlockSetting::_write($this->getBlockType(), "public_feed", $_POST["notifications_public_feed"], 0, $this->block_id); ilBlockSetting::_write($this->getBlockType(), "default_visibility", $_POST["default_visibility"], 0, $this->block_id); } if ($this->getProperty("hide_news_block_option")) { ilBlockSetting::_write($this->getBlockType(), "hide_news_block", $_POST["hide_news_block"], 0, $this->block_id); ilBlockSetting::_write($this->getBlockType(), "hide_news_per_date", $_POST["hide_news_per_date"], 0, $this->block_id); // hide date $hd = $this->settings_form->getInput("hide_news_date"); $hide_date = new ilDateTime($hd["date"] . " " . $hd["time"], IL_CAL_DATETIME, $ilUser->getTimeZone()); ilBlockSetting::_write($this->getBlockType(), "hide_news_date", $hide_date->get(IL_CAL_DATETIME), 0, $this->block_id); } include_once "./Services/News/classes/class.ilNewsCache.php"; $cache = new ilNewsCache(); $cache->deleteEntry($ilUser->getId() . ":" . $_GET["ref_id"]); $ilCtrl->returnToParent($this); } else { $this->settings_form->setValuesByPost(); return $this->settings_form->getHtml(); } }
/** * 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; } }
/** * Gets all bookings for a room in a time span * * @param $room_id * @param $start * @param $end * @param $type * * @return array bookings */ public function getBookingsForRoomInTimeSpan($room_id, $start, $end, $type) { $query = 'SELECT b.id id FROM ' . dbc::BOOKINGS_TABLE . ' b'; if ($type != 4) { $query .= ' WHERE ((date_from <= ' . $this->ilDB->quote($end->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ' AND date_to >= ' . $this->ilDB->quote($start->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ') OR (date_from <= ' . $this->ilDB->quote($end->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ' ))'; } else { $date = new ilDateTime(mktime(0, 0, 0), IL_CAL_UNIX); $query .= ' WHERE date_from >= ' . $this->ilDB->quote($date->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp'); } $query .= ' AND room_id = ' . $this->ilDB->quote($room_id, 'integer') . ' AND pool_id = ' . $this->ilDB->quote($this->pool_id, 'integer') . ' ORDER BY date_from'; $res = $this->ilDB->query($query); $events = array(); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $events[] = $row; } return $events; }
/** * Import records from Excel file * * @param $file * @param bool $simulate */ private function importRecords($file, $simulate = false) { global $ilUser, $lng; include_once "./Modules/DataCollection/libs/ExcelReader/excel_reader2.php"; $warnings = array(); try { $excel = new Spreadsheet_Excel_Reader($file); } catch (Exception $e) { $warnings[] = $lng->txt("dcl_file_not_readable"); } if (count($warnings)) { $this->endImport(0, $warnings); return; } $field_names = array(); for ($i = 1; $i <= $excel->colcount(); $i++) { $field_names[$i] = $excel->val(1, $i); } $fields = $this->getImportFieldsFromTitles($field_names, $warnings); for ($i = 2; $i <= $excel->rowcount(); $i++) { $record = new ilDataCollectionRecord(); $record->setTableId($this->table_obj->getId()); $record->setOwner($ilUser->getId()); $date_obj = new ilDateTime(time(), IL_CAL_UNIX); $record->setCreateDate($date_obj->get(IL_CAL_DATETIME)); $record->setTableId($this->table_id); if (!$simulate) { $record->doCreate(); } foreach ($fields as $col => $field) { $value = $excel->val($i, $col); $value = utf8_encode($value); try { if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) { $old = $value; $value = $this->getReferenceFromValue($field, $value); if (!$value) { $warnings[] = "(" . $i . ", " . $this->getExcelCharForInteger($col) . ") " . $lng->txt("dcl_no_such_reference") . " " . $old; } } else { if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) { $value = array('date' => date('Y-m-d', strtotime($value)), 'time' => '00:00:00'); } } $field->checkValidity($value, $record->getId()); if (!$simulate) { $record->setRecordFieldValue($field->getId(), $value); } } catch (ilDataCollectionInputException $e) { $warnings[] = "(" . $i . ", " . $this->getExcelCharForInteger($col) . ") " . $e; } } if (!$simulate) { $record->doUpdate(); } if ($i - 1 > $this->max_imports) { $warnings[] = $lng->txt("dcl_max_import") . ($excel->rowcount() - 1) . " > " . $this->max_imports; break; } } $this->endImport($i - 2, $warnings); }
public static function applyAccessLimits(ilObjUser $user, $code) { include_once './Services/Registration/classes/class.ilRegistrationCode.php'; $code_data = ilRegistrationCode::getCodeData($code); if ($code_data["alimit"]) { switch ($code_data["alimit"]) { case "absolute": $end = new ilDateTime($code_data['alimitdt'], IL_CAL_DATE); //$user->setTimeLimitFrom(time()); $user->setTimeLimitUntil($end->get(IL_CAL_UNIX)); $user->setTimeLimitUnlimited(0); break; case "relative": $rel = unserialize($code_data["alimitdt"]); include_once './Services/Calendar/classes/class.ilDateTime.php'; $end = new ilDateTime(time(), IL_CAL_UNIX); if ($rel['y'] > 0) { $end->increment(IL_CAL_YEAR, $rel['y']); } if ($rel['m'] > 0) { $end->increment(IL_CAL_MONTH, $rel['m']); } if ($rel['d'] > 0) { $end->increment(IL_CAL_DAY, $rel['d']); } //$user->setTimeLimitFrom(time()); $user->setTimeLimitUntil($end->get(IL_CAL_UNIX)); $user->setTimeLimitUnlimited(0); break; case 'unlimited': $user->setTimeLimitUnlimited(1); break; } } else { $user->setTimeLimitUnlimited(1); } }
/** * Verify Token * * @return boolean valid t/f */ private function verifyToken() { global $ilDB, $ilUser; if (is_object($ilUser) && is_object($ilDB) && $ilUser->getId() > 0 && $ilUser->getId() != ANONYMOUS_USER_ID) { if ($_GET["rtoken"] == "") { #echo "ilCtrl::No Request Token Given!"; // for debugging, maybe changed later return false; } $set = $ilDB->query("SELECT * FROM il_request_token WHERE " . " user_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " . " token = " . $ilDB->quote($_GET[self::IL_RTOKEN_NAME]), "text"); if ($ilDB->numRows($set) > 0) { // remove used token /* $ilDB->query("DELETE FROM il_request_token WHERE ". " user_id = ".$ilDB->quote($ilUser->getId())." AND ". " token = ".$ilDB->quote($_GET[self::IL_RTOKEN_NAME])); */ // remove tokens from older sessions // if we do this immediately, working with multiple windows does not work: // - window one: open form (with token a) // - window two: open form (with token b) // - submit window one: a is verified, but b must not be deleted immediately, otherwise // - window two: submit results in invalid token // see also bug #13551 $dt = new ilDateTime(time(), IL_CAL_UNIX); $dt->increment(IL_CAL_DAY, -1); $dt->increment(IL_CAL_HOUR, -12); $ilDB->manipulate("DELETE FROM il_request_token WHERE " . " user_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " . " session_id != " . $ilDB->quote(session_id(), "text") . " AND " . " stamp < " . $ilDB->quote($dt->get(IL_CAL_DATETIME), "timestamp")); return true; } else { return false; } if ($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]] != "") { // remove used token unset($_SESSION["rtokens"][$_GET[self::IL_RTOKEN_NAME]]); // remove old tokens if (count($_SESSION["rtokens"]) > 100) { $to_remove = array(); $sec = 7200; // two hours foreach ($_SESSION["rtokens"] as $tok => $time) { if (time() - $time > $sec) { $to_remove[] = $tok; } } foreach ($to_remove as $tok) { unset($_SESSION["rtokens"][$tok]); } } return true; } return false; } else { return true; // do not verify, if user or db object is missing } return false; }
/** * update * * @access public * @return */ public function update() { global $ilErr, $ilAccess, $tpl, $ilUser; // #19997 - see ilObjectListGUI::insertTimingsCommand() if (!$ilAccess->checkAccess('write', '', $this->parent_ref_id) && !$ilAccess->checkAccess('write', '', $this->getItemId())) { $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->MESSAGE); } $this->initFormEdit(); if ($this->form->checkInput()) { include_once "Services/Object/classes/class.ilObjectActivation.php"; $activation = new ilObjectActivation(); $activation->setTimingType($this->form->getInput('timing_type')); $date = $this->form->getInput('timing_start'); $date = new ilDateTime($date['date'] . ' ' . $date['time'], IL_CAL_DATETIME, $ilUser->getTimeZone()); $activation->setTimingStart($date->get(IL_CAL_UNIX)); $date = $this->form->getInput('timing_end'); $date = new ilDateTime($date['date'] . ' ' . $date['time'], IL_CAL_DATETIME, $ilUser->getTimeZone()); $activation->setTimingEnd($date->get(IL_CAL_UNIX)); $date = $this->form->getInput('sug_start'); $date = new ilDate($date['date'], IL_CAL_DATE); $activation->setSuggestionStart($date->get(IL_CAL_UNIX)); $date = $this->form->getInput('sug_end'); $date = new ilDate($date['date'], IL_CAL_DATE); $activation->setSuggestionEnd($date->get(IL_CAL_UNIX)); $date = $this->form->getInput('early_start'); $date = new ilDate($date['date'], IL_CAL_DATE); $activation->setEarliestStart($date->get(IL_CAL_UNIX)); $date = $this->form->getInput('late_end'); $date = new ilDate($date['date'], IL_CAL_DATE); $activation->setLatestEnd($date->get(IL_CAL_UNIX)); $activation->toggleVisible((bool) $this->form->getInput('visible')); $activation->toggleChangeable((bool) $this->form->getInput('changeable')); if (!$activation->validateActivation()) { ilUtil::sendFailure($ilErr->getMessage()); $this->form->setValuesByPost(); $tpl->setContent($this->form->getHTML()); return false; } else { $activation->update($this->getItemId()); ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); $this->ctrl->redirect($this, "edit"); } } else { $this->form->setValuesByPost(); $tpl->setContent($this->form->getHTML()); } }
/** * Export selected user tracking data * @global ilDB $ilDB * @global ilObjUser $ilUser * @param bool $a_all * @param array $a_users */ public function exportSelected($a_all, $a_users = array()) { global $ilDB, $ilUser, $ilSetting; $inst_id = $ilSetting->get('inst_id', 0); // Get all scos $scos = array(); //get all SCO's of this object $query = 'SELECT scorm_object.obj_id, scorm_object.title, ' . 'scorm_object.c_type, scorm_object.slm_id, scorm_object.obj_id scoid ' . 'FROM scorm_object, sc_item, sc_resource ' . 'WHERE (scorm_object.slm_id = %s ' . 'AND scorm_object.obj_id = sc_item.obj_id ' . 'AND sc_item.identifierref = sc_resource.import_id ' . 'AND sc_resource.scormtype = %s) ' . 'GROUP BY scorm_object.obj_id, scorm_object.title, scorm_object.c_type, ' . 'scorm_object.slm_id, scorm_object.obj_id '; $res = $ilDB->queryF($query, array('integer', 'text'), array($this->getId(), 'sco')); while ($row = $ilDB->fetchAssoc($res)) { $scos[] = $row['scoid']; } $users = array(); if ($a_all) { $query = 'SELECT user_id FROM scorm_tracking ' . 'WHERE obj_id = ' . $ilDB->quote($this->getId(), 'integer') . ' ' . 'GROUP BY user_id'; $res = $ilDB->query($query); while ($row = $ilDB->fetchAssoc($res)) { $users[] = $row['user_id']; } } else { $users = $a_users; } // get all completed include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php'; $completed = ilObjSCORMTracking::_getCompleted($scos, $this->getId()); $last = ilObjSCORMTracking::lookupLastAccessTimes($this->getId()); include_once './Services/Utilities/classes/class.ilCSVWriter.php'; $csv = new ilCSVWriter(); $csv->setSeparator(';'); foreach (array('Department', 'Login', 'Lastname', 'Firstname', 'Email', 'Date', 'Status') as $col) { $csv->addColumn($col); } // Read user data $query = 'SELECT usr_id,login,firstname,lastname,department,email ' . 'FROM usr_data ' . 'WHERE ' . $ilDB->in('usr_id', $users, false, 'integer'); $res = $ilDB->query($query); while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) { $csv->addRow(); $csv->addColumn((string) $row->department); $csv->addColumn((string) $row->login); $csv->addColumn((string) $row->lastname); $csv->addColumn((string) $row->firstname); $csv->addColumn((string) $row->email); if (isset($last[$row->usr_id])) { $dt = new ilDateTime($last[$row->usr_id], IL_CAL_DATETIME); $csv->addColumn((string) $dt->get(IL_CAL_FKT_DATE, 'd.m.Y')); } else { $csv->addColumn(''); } $csv->addColumn(in_array($row->usr_id, $completed) ? 1 : 0); } ilUtil::deliverData($csv->getCSVString(), 'scorm_tracking_' . $this->getRefId() . '_' . time() . '.csv'); }
/** * Called when the a log should be exported */ public function exportLogObject() { $from = mktime($_POST['log_from']['time']['h'], $_POST['log_from']['time']['m'], 0, $_POST['log_from']['date']['m'], $_POST['log_from']['date']['d'], $_POST['log_from']['date']['y']); $until = mktime($_POST['log_until']['time']['h'], $_POST['log_until']['time']['m'], 0, $_POST['log_until']['date']['m'], $_POST['log_until']['date']['d'], $_POST['log_until']['date']['y']); $test = $_POST['sel_test']; $csv = array(); $separator = ";"; $row = array($this->lng->txt("assessment_log_datetime"), $this->lng->txt("user"), $this->lng->txt("assessment_log_text"), $this->lng->txt("question")); include_once "./Modules/Test/classes/class.ilObjTest.php"; include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $available_tests =& ilObjTest::_getAvailableTests(1); array_push($csv, ilUtil::processCSVRow($row, TRUE, $separator)); $log_output =& $this->object->getLog($from, $until, $test); $users = array(); foreach ($log_output as $key => $log) { if (!array_key_exists($log["user_fi"], $users)) { $users[$log["user_fi"]] = ilObjUser::_lookupName($log["user_fi"]); } $title = ""; if ($log["question_fi"] || $log["original_fi"]) { $title = assQuestion::_getQuestionTitle($log["question_fi"]); if (strlen($title) == 0) { $title = assQuestion::_getQuestionTitle($log["original_fi"]); } $title = $this->lng->txt("assessment_log_question") . ": " . $title; } $csvrow = array(); $date = new ilDateTime($log['tstamp'], IL_CAL_UNIX); array_push($csvrow, $date->get(IL_CAL_FKT_DATE, 'Y-m-d H:i')); array_push($csvrow, trim($users[$log["user_fi"]]["title"] . " " . $users[$log["user_fi"]]["firstname"] . " " . $users[$log["user_fi"]]["lastname"])); array_push($csvrow, trim($log["logtext"])); array_push($csvrow, $title); array_push($csv, ilUtil::processCSVRow($csvrow, TRUE, $separator)); } $csvoutput = ""; foreach ($csv as $row) { $csvoutput .= join($row, $separator) . "\n"; } ilUtil::deliverData($csvoutput, str_replace(" ", "_", "log_" . $from . "_" . $until . "_" . $available_tests[$test]) . ".csv"); }
/** * get formatted date * * @access public * @param int format type * @param string format string */ public function get($a_format, $a_format_str = '') { return parent::get($a_format, $a_format_str); }
/** * Compose a mail that tells the creator that somenone has left */ private function composeParticipationCancelMailForCreator($a_user_id, $a_creator_id) { $lng = $this->lng; $user = $this->ilRoomSharingDatabase->getUserById($a_user_id); $this->initLanguage($a_creator_id); $this->initMail(); $this->setSubject($lng->txt('rep_robj_xrs_mail_participation_creator_subject')); $this->setBody(ilMail::getSalutation($a_creator_id, $this->getLanguage())); $this->appendBody("\n\n"); $this->appendBody($lng->txt('rep_robj_xrs_mail_participation_creator_message') . "\n"); $this->appendBody($lng->txt('rep_robj_xrs_user') . ": "); $this->appendBody($user['firstname'] . " " . $user['lastname'] . " (" . $user['login'] . ")\n"); $this->appendBody($lng->txt('rep_robj_xrs_booking') . ":\n"); $booking = $this->bookings[0]; $roomname = $this->ilRoomSharingDatabase->getRoomName($booking['room_id']); $datestart = new ilDateTime($booking['date_from'], IL_CAL_DATETIME); $dateend = new ilDateTime($booking['date_to'], IL_CAL_DATETIME); $this->appendBody($lng->txt('rep_robj_xrs_room') . " "); $this->appendBody($roomname . " "); $this->appendBody($lng->txt('rep_robj_xrs_from') . " "); $this->appendBody($datestart->get(IL_CAL_FKT_DATE, 'd.m.Y H:s') . " "); $this->appendBody($lng->txt('rep_robj_xrs_to') . " "); $this->appendBody($dateend->get(IL_CAL_FKT_DATE, 'd.m.Y H:s') . "\n"); }
function getData() { global $ilCtrl, $lng; $seed = new ilDate(date('Y-m-d', time()), IL_CAL_DATE); include_once './Services/Calendar/classes/class.ilCalendarSchedule.php'; $schedule = new ilCalendarSchedule($seed, ilCalendarSchedule::TYPE_PD_UPCOMING); $schedule->addSubitemCalendars(true); // #12007 $schedule->setEventsLimit(20); $schedule->calculate(); $events = $schedule->getScheduledEvents(); // #13809 $data = array(); if (sizeof($events)) { foreach ($events as $item) { $start = $item["dstart"]; $end = $item["dend"]; if ($item["fullday"]) { $start = new ilDate($start, IL_CAL_UNIX); $end = new ilDate($end, IL_CAL_UNIX); } else { $start = new ilDateTime($start, IL_CAL_UNIX); $end = new ilDateTime($end, IL_CAL_UNIX); } $ilCtrl->clearParametersByClass('ilcalendardaygui'); $ilCtrl->setParameterByClass('ilcalendardaygui', 'seed', $start->get(IL_CAL_DATE)); $link = $ilCtrl->getLinkTargetByClass('ilcalendardaygui', ''); $ilCtrl->clearParametersByClass('ilcalendardaygui'); $data[] = array("date" => ilDatePresentation::formatPeriod($start, $end), "title" => $item["event"]->getPresentationTitle(), "url" => $link); } $this->setEnableNumInfo(true); } else { $data[] = array("date" => $lng->txt("msg_no_search_result"), "title" => "", "url" => ""); $this->setEnableNumInfo(false); } return $data; }
/** * Get all object-based tracking data for user and parent object * * @param int $a_user_id * @param int $a_parent_obj_id * @param int $a_parent_ref_id * @param string $a_order_field * @param string $a_order_dir * @param int $a_offset * @param int $a_limit * @param array $a_filters * @param array $a_additional_fields * @param bool $use_collection * @return array cnt, set */ static function getObjectsDataForUser($a_user_id, $a_parent_obj_id, $a_parent_ref_id, $a_order_field = "", $a_order_dir = "", $a_offset = 0, $a_limit = 9999, array $a_filters = NULL, array $a_additional_fields = NULL, $use_collection = true) { global $ilDB; $fields = array("object_data.obj_id", "title", "type"); self::buildColumns($fields, $a_additional_fields); $objects = self::getObjectIds($a_parent_obj_id, $a_parent_ref_id, $use_collection, true, array($a_user_id)); $query = " FROM object_data LEFT JOIN read_event ON (object_data.obj_id = read_event.obj_id AND" . " read_event.usr_id = " . $ilDB->quote($a_user_id, "integer") . ")" . " LEFT JOIN ut_lp_marks ON (ut_lp_marks.usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND" . " ut_lp_marks.obj_id = object_data.obj_id)" . " WHERE " . $ilDB->in("object_data.obj_id", $objects["object_ids"], false, "integer") . self::buildFilters(array(), $a_filters); $queries = array(); $queries[] = array("fields" => $fields, "query" => $query); // objectives data if ($objects["objectives_parent_id"]) { $objective_fields = array("crs_objectives.objective_id AS obj_id", "title", $ilDB->quote("lobj", "text") . " as type"); if (is_array($a_additional_fields)) { foreach ($a_additional_fields as $field) { if ($field != "status") { $objective_fields[] = "NULL AS " . $field; } else { include_once "Services/Tracking/classes/class.ilLPStatus.php"; $objective_fields[] = "CASE WHEN status IS NOT NULL THEN " . LP_STATUS_COMPLETED_NUM . " ELSE NULL END AS status"; } } } $where = array(); $where[] = "crs_objectives.crs_id = " . $ilDB->quote($objects["objectives_parent_id"], "integer"); $objectives_query = " FROM crs_objectives" . " LEFT JOIN crs_objective_status ON (crs_objectives.objective_id = crs_objective_status.objective_id" . " AND crs_objective_status.user_id = " . $ilDB->quote($a_user_id, "integer") . ")" . self::buildFilters($where, $a_filters); $queries[] = array("fields" => $objective_fields, "query" => $objectives_query, "count" => "crs_objectives.objective_id"); } if (!in_array($a_order_field, $fields)) { $a_order_field = "title"; } $result = self::executeQueries($queries, $a_order_field, $a_order_dir, $a_offset, $a_limit); if ($result["cnt"]) { // session data $sessions = self::getSessionData($a_user_id, $objects["object_ids"]); foreach ($result["set"] as $idx => $item) { if ($item["type"] == "sess") { $session = $sessions[$item["obj_id"]]; $result["set"][$idx]["title"] = $session["title"]; $result["set"][$idx]["sort_title"] = $session["e_start"]; // $result["set"][$idx]["status"] = (int)$session["status"]; } $result["set"][$idx]["ref_id"] = $objects["ref_ids"][$item["obj_id"]]; } // scos data (:TODO: will not be part of offset/limit) if ($objects["scorm"]) { include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php"; $subtype = ilObjSAHSLearningModule::_lookupSubType($a_parent_obj_id); if ($subtype == "scorm2004") { include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php"; $sobj = new ilObjSCORM2004LearningModule($a_parent_ref_id, true); $scos_tracking = $sobj->getTrackingDataAgg($a_user_id, true); } else { include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php"; $sobj = new ilObjSCORMLearningModule($a_parent_ref_id, true); $scos_tracking = array(); foreach ($sobj->getTrackingDataAgg($a_user_id) as $item) { // format: hhhh:mm:ss ?! if ($item["time"]) { $time = explode(":", $item["time"]); $item["time"] = $time[0] * 60 * 60 + $time[1] * 60 + $time[2]; } $scos_tracking[$item["sco_id"]] = array("session_time" => $item["time"]); } } foreach ($objects["scorm"]["scos"] as $sco) { $row = array("title" => $objects["scorm"]["scos_title"][$sco], "type" => "sco"); $status = LP_STATUS_NOT_ATTEMPTED_NUM; if (in_array($a_user_id, $objects["scorm"]["completed"][$sco])) { $status = LP_STATUS_COMPLETED_NUM; } else { if (in_array($a_user_id, $objects["scorm"]["failed"][$sco])) { $status = LP_STATUS_FAILED_NUM; } else { if (in_array($a_user_id, $objects["scorm"]["in_progress"][$sco])) { $status = LP_STATUS_IN_PROGRESS_NUM; } } } $row["status"] = $status; // add available tracking data if (isset($scos_tracking[$sco])) { if (isset($scos_tracking[$sco]["last_access"])) { $date = new ilDateTime($scos_tracking[$sco]["last_access"], IL_CAL_DATETIME); $row["last_access"] = $date->get(IL_CAL_UNIX); } $row["spent_seconds"] = $scos_tracking[$sco]["session_time"]; } $result["set"][] = $row; $result["cnt"]++; } } } return $result; }
/** * compare two dates and check start is after end * This method does not consider tz offsets. * So you have to take care that both dates are defined in the the same timezone * * @access public * @param object ilDateTime * @param object ilDateTime * @param string field used for comparison. E.g <code>IL_CAL_YEAR</code> checks if start is one or more years after than end * @param string timezone * @static */ public static function _after(ilDateTime $start, ilDateTime $end, $a_compare_field = '', $a_tz = '') { switch ($a_compare_field) { case IL_CAL_YEAR: return $start->get(IL_CAL_FKT_DATE, 'Y', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Y', $a_tz); case IL_CAL_MONTH: return (int) $start->get(IL_CAL_FKT_DATE, 'Ym', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ym', $a_tz); case IL_CAL_DAY: return (int) $start->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz) > $end->get(IL_CAL_FKT_DATE, 'Ymd', $a_tz); case '': default: return $start->get(IL_CAL_UNIX) > $end->get(IL_CAL_UNIX); } }
/** * Import record * * @param * @return */ function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) { switch ($a_entity) { case "sess": include_once "./Modules/Session/classes/class.ilObjSession.php"; include_once "./Modules/Session/classes/class.ilSessionAppointment.php"; if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { $newObj = new ilObjSession(); $newObj->setType("sess"); $newObj->create(true); } $newObj->setTitle($a_rec["Title"]); $newObj->setDescription($a_rec["Description"]); $newObj->setLocation($a_rec["Location"]); $newObj->setName($a_rec["TutorName"]); $newObj->setPhone($a_rec["TutorPhone"]); $newObj->setEmail($a_rec["TutorEmail"]); $newObj->setDetails($a_rec["Details"]); $newObj->update(); $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC"); $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC"); //echo "<br>".$start->get(IL_CAL_UNIX); //echo "<br>".$start->get(IL_CAL_DATETIME); $app = new ilSessionAppointment(); $app->setStart($a_rec["EventStart"]); $app->setEnd($a_rec["EventEnd"]); $app->setStartingTime($start->get(IL_CAL_UNIX)); $app->setEndingTime($end->get(IL_CAL_UNIX)); $app->toggleFullTime($a_rec["Fulltime"]); $app->setSessionId($newObj->getId()); $app->create(); //$newObj->setAppointments(array($app)); //$newObj->update(); $this->current_obj = $newObj; $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId()); //var_dump($a_mapping->mappings["Services/News"]["news_context"]); break; case "sess_item": if ($obj_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['ItemId'])) { $ref_id = current(ilObject::_getAllReferences($obj_id)); include_once './Modules/Session/classes/class.ilEventItems.php'; $evi = new ilEventItems($this->current_obj->getId()); $evi->addItem($ref_id); $evi->update(); } break; } }