Esempio n. 1
0
 public function setDate(ilDateTime $a_value = null)
 {
     if ($a_value && $a_value->isNull()) {
         $a_value = null;
     }
     $this->value = $a_value;
 }
 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;
 }
 /**
  * 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;
         }
     }
 }
 /**
  * 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);
 }
 /**
  * Fill row
  * @staticvar int $counter
  * @param array $set 
  */
 public function fillRow($set)
 {
     global $ilCtrl;
     $ilCtrl->setParameter($this->getParentObject(), 'server_id', $set['server_id']);
     $ilCtrl->setParameterByClass('ilecsmappingsettingsgui', 'server_id', $set['server_id']);
     if ($set['active']) {
         $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_ok.svg'));
         $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_activated'));
     } else {
         $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('icon_not_ok.svg'));
         $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_inactivated'));
     }
     $this->tpl->setVariable('VAL_TITLE', ilECSSetting::getInstanceByServerId($set['server_id'])->getTitle());
     $this->tpl->setVariable('LINK_EDIT', $ilCtrl->getLinkTarget($this->getParentObject(), 'edit'));
     $this->tpl->setVariable('TXT_SRV_ADDR', $this->lng->txt('ecs_server_addr'));
     if (ilECSSetting::getInstanceByServerId($set['server_id'])->getServer()) {
         $this->tpl->setVariable('VAL_DESC', ilECSSetting::getInstanceByServerId($set['server_id'])->getServer());
     } else {
         $this->tpl->setVariable('VAL_DESC', $this->lng->txt('ecs_not_configured'));
     }
     $dt = ilECSSetting::getInstanceByServerId($set['server_id'])->fetchCertificateExpiration();
     if ($dt != NULL) {
         $this->tpl->setVariable('TXT_CERT_VALID', $this->lng->txt('ecs_cert_valid_until'));
         $now = new ilDateTime(time(), IL_CAL_UNIX);
         $now->increment(IL_CAL_MONTH, 2);
         if (ilDateTime::_before($dt, $now)) {
             $this->tpl->setCurrentBlock('invalid');
             $this->tpl->setVariable('VAL_ICERT', ilDatePresentation::formatDate($dt));
             $this->tpl->parseCurrentBlock();
         } else {
             $this->tpl->setCurrentBlock('valid');
             $this->tpl->setVariable('VAL_VCERT', ilDatePresentation::formatDate($dt));
             $this->tpl->parseCurrentBlock();
         }
     }
     // Actions
     include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
     $list = new ilAdvancedSelectionListGUI();
     $list->setSelectionHeaderClass('small');
     $list->setItemLinkClass('small');
     $list->setId('actl_' . $set['server_id']);
     $list->setListTitle($this->lng->txt('actions'));
     if (ilECSSetting::getInstanceByServerId($set['server_id'])->isEnabled()) {
         $list->addItem($this->lng->txt('ecs_deactivate'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'deactivate'));
     } else {
         $list->addItem($this->lng->txt('ecs_activate'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'activate'));
     }
     $list->addItem($this->lng->txt('edit'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'edit'));
     $list->addItem($this->lng->txt('copy'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'cp'));
     $list->addItem($this->lng->txt('delete'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'delete'));
     $this->tpl->setVariable('ACTIONS', $list->getHTML());
     $ilCtrl->clearParameters($this->getParentObject());
 }
 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;
 }
 /**
  * lookup appointment
  *
  * @access public
  * @param int obj_id
  * @static
  */
 public static function _lookupAppointment($a_obj_id)
 {
     global $ilDB;
     $query = "SELECT * FROM event_appointment " . "WHERE event_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         $info['fullday'] = $row->fulltime;
         $date = new ilDateTime($row->e_start, IL_CAL_DATETIME, 'UTC');
         $info['start'] = $date->getUnixTime();
         $date = new ilDateTime($row->e_end, IL_CAL_DATETIME, 'UTC');
         $info['end'] = $date->getUnixTime();
         return $info;
     }
     return array();
 }
 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) . "}";
     }
 }
 /**
  * check if a date is today 
  * @param ilDateTime $date date to check
  * @return bool
  * @static
  */
 public static function _isToday($date)
 {
     global $ilUser;
     if (!is_object(self::$today)) {
         self::$today = new ilDateTime(time(), IL_CAL_UNIX, $ilUser->getTimeZone());
     }
     return ilDateTime::_equals(self::$today, $date, IL_CAL_DAY, $ilUser->getTimeZone());
 }
 /**
  * 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;
 }
 /**
  * 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;
     }
 }
 /**
  * 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);
     }
 }
 /**
  * Fill row
  * @param type $a_set
  */
 public function fillRow($row)
 {
     global $ilCtrl;
     $this->tpl->setVariable('START', $row['start_str']);
     $this->tpl->setVariable('NAME', $row['name']);
     $this->tpl->setVariable('COMMENT', $row['comment']);
     $this->tpl->setVariable('TITLE', $row['title']);
     $this->tpl->setVariable('VAL_ID', $row['id']);
     include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
     $list = new ilAdvancedSelectionListGUI();
     $list->setId('act_chboo_' . $row['id']);
     $list->setListTitle($this->lng->txt('actions'));
     $ilCtrl->setParameter($this->getParentObject(), 'bookuser', $row['id']);
     $start = new ilDateTime($row['start'], IL_CAL_UNIX);
     if (ilDateTime::_after($start, $this->today, IL_CAL_DAY)) {
         $list->addItem($this->lng->txt('cal_ch_reject_booking'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'confirmRejectBooking'));
     }
     $list->addItem($this->lng->txt('cal_ch_delete_booking'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'confirmDeleteBooking'));
     $this->tpl->setVariable('ACTIONS', $list->getHTML());
 }
 /**
  * Standard Version of Fill Row. Most likely to
  * be overwritten by derived class.
  */
 protected function fillRow($a_set)
 {
     global $lng, $ilCtrl;
     $now = new ilDateTime(time(), IL_CAL_UNIX);
     $this->tpl->setVariable("IMG_ALT", $lng->txt("obj_" . $a_set["type"]));
     $this->tpl->setVariable("IMG_SRC", ilObject::_getIcon($a_set["obj_id"], "small", $a_set["type"]));
     $this->tpl->setVariable("VAL_TITLE", $a_set["title"]);
     $this->tpl->setVariable("ID", $a_set["ref_id"]);
     $this->tpl->setVariable("TXT_LAST_EXPORT_FILE", $lng->txt("export_last_file"));
     $this->tpl->setVariable("TXT_OMIT", $lng->txt("export_omit"));
     $this->tpl->setVariable("TXT_CREATE_NEW_EXPORT_FILE", $lng->txt("export_create"));
     $preset = "CREATE";
     if ($a_set["timestamp"] > 0) {
         $last_export = new ilDateTime($a_set["timestamp"], IL_CAL_UNIX);
         $this->tpl->setVariable("VAL_LAST_EXPORT", ilDatePresentation::formatDate($last_export));
         if (ilDateTime::_equals($last_export, $now, IL_CAL_DAY)) {
             $preset = "LAST_FILE";
         }
     }
     $this->tpl->setVariable("SEL_" . $preset, ' checked="checked" ');
 }
 /**
  * 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');
 }
Esempio n. 19
0
 /**
  * Check whether an date is within a date duration given by start and end
  * @param ilDateTime $dt
  * @param ilDateTime $start
  * @param ilDateTime $end
  * @param type $a_compare_field
  * @param type $a_tz
  */
 public static function _within(ilDateTime $dt, ilDateTime $start, ilDateTime $end, $a_compare_field = '', $a_tz = '')
 {
     return (ilDateTime::_after($dt, $start, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $start, $a_compare_field, $a_tz)) && (ilDateTime::_before($dt, $end, $a_compare_field, $a_tz) or ilDateTime::_equals($dt, $end, $a_compare_field, $a_tz));
 }
 /**
  * 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);
 }
Esempio n. 21
0
 public static function getOpenRoomBooking($a_group_id)
 {
     $now = new ilDateTime(time(), IL_CAL_UNIX);
     $earlier = clone $now;
     $later = clone $now;
     $later->increment(IL_CAL_DAY, 5);
     $booking = self::lookupNextBooking($earlier, $later, $a_group_id);
     if (!$booking['open'] instanceof ilDateTime) {
         return 0;
     }
     if (ilDateTime::_before($booking['open'], $now) and ilDateTime::_after($booking['closed'], $now)) {
         return $booking['id'];
     }
     return 0;
 }
Esempio n. 22
0
 /**
  * get activation
  *
  * @return	boolean		true/false for active or not
  */
 function getActive($a_check_scheduled_activation = false)
 {
     if ($a_check_scheduled_activation && !$this->active) {
         include_once "./Services/Calendar/classes/class.ilDateTime.php";
         $start = new ilDateTime($this->getActivationStart(), IL_CAL_DATETIME);
         $end = new ilDateTime($this->getActivationEnd(), IL_CAL_DATETIME);
         $now = new ilDateTime(time(), IL_CAL_UNIX);
         if (!ilDateTime::_before($now, $start) && !ilDateTime::_after($now, $end)) {
             return true;
         }
     }
     return $this->active;
 }
 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;
 }
 /**
  * Check if value matches
  * @param	mixed	$a_value	Econtent value
  * @param	int		$a_type		Parameter type
  * @return
  */
 protected function matchesValue($a_value, $a_type)
 {
     global $ilLog;
     switch ($a_type) {
         case self::ATTR_ARRAY:
             $values = explode(',', $a_value);
             $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
             $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
             break;
         case self::ATTR_INT:
             $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
             $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
             $values = array($a_value);
             break;
         case self::ATTR_STRING:
             $values = array($a_value);
             break;
     }
     $values = explode(',', $a_value);
     foreach ($values as $value) {
         $value = trim($value);
         switch ($this->getMappingType()) {
             case self::TYPE_FIXED:
                 foreach ($this->getMappingAsArray() as $attribute_value) {
                     $attribute_value = trim($attribute_value);
                     if (strcasecmp($attribute_value, $value) == 0) {
                         return true;
                     }
                 }
                 break;
             case self::TYPE_DURATION:
                 include_once './Services/Calendar/classes/class.ilDateTime.php';
                 $tmp_date = new ilDate($a_value, IL_CAL_UNIX);
                 return ilDateTime::_after($tmp_date, $this->getDateRangeStart()) and ilDateTime::_before($tmp_date, $this->getDateRangeEnd());
         }
     }
     return false;
 }
 private function __calculateAccessEnddate()
 {
     include_once 'Services/Calendar/classes/class.ilDateTime.php';
     $tmp_ts = new ilDateTime($this->getAccessStartdate(), IL_CAL_DATETIME);
     $start_date = $tmp_ts->getUnixTime();
     $duration = $this->getDuration();
     $startDateYear = date("Y", $start_date);
     $startDateMonth = date("m", $start_date);
     $startDateDay = date("d", $start_date);
     $startDateHour = date("H", $start_date);
     $startDateMinute = date("i", $start_date);
     $startDateSecond = date("s", $start_date);
     $access_enddate = date("Y-m-d H:i:s", mktime($startDateHour, $startDateMinute, $startDateSecond, $startDateMonth + $duration, $startDateDay, $startDateYear));
     $this->setAccessEnddate($access_enddate);
 }
Esempio n. 26
0
 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);
     }
 }
Esempio n. 27
0
 /**
  * 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);
 }
Esempio n. 28
0
 /**
  * Get subitems of container
  * @param bool $a_admin_panel_enabled[optional]
  * @param bool $a_include_side_block[optional]
  * @return array 
  */
 public function getSubItems($a_admin_panel_enabled = false, $a_include_side_block = false)
 {
     global $ilUser;
     // Caching
     if (is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block])) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // Results are stored in $this->items
     parent::getSubItems($a_admin_panel_enabled, $a_include_side_block);
     $limit_sess = false;
     if (!$a_admin_panel_enabled && !$a_include_side_block && $this->items['sess'] && is_array($this->items['sess']) && $this->isSessionLimitEnabled() && $this->getViewMode() == ilContainer::VIEW_SESSIONS) {
         $limit_sess = true;
     }
     if (!$limit_sess) {
         return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
     }
     // do session limit
     // @todo move to gui class
     if (isset($_GET['crs_prev_sess'])) {
         $ilUser->writePref('crs_sess_show_prev_' . $this->getId(), (string) (int) $_GET['crs_prev_sess']);
     }
     if (isset($_GET['crs_next_sess'])) {
         $ilUser->writePref('crs_sess_show_next_' . $this->getId(), (string) (int) $_GET['crs_next_sess']);
     }
     $sessions = ilUtil::sortArray($this->items['sess'], 'start', 'ASC', true, false);
     $today = new ilDate(date('Ymd', time()), IL_CAL_DATE);
     $previous = $current = $next = array();
     foreach ($sessions as $key => $item) {
         $start = new ilDateTime($item['start'], IL_CAL_UNIX);
         $end = new ilDateTime($item['end'], IL_CAL_UNIX);
         if (ilDateTime::_within($today, $start, $end, IL_CAL_DAY)) {
             $current[] = $item;
         } elseif (ilDateTime::_before($start, $today, IL_CAL_DAY)) {
             $previous[] = $item;
         } elseif (ilDateTime::_after($start, $today, IL_CAL_DAY)) {
             $next[] = $item;
         }
     }
     $num_previous_remove = max(count($previous) - $this->getNumberOfPreviousSessions(), 0);
     while ($num_previous_remove--) {
         if (!$ilUser->getPref('crs_sess_show_prev_' . $this->getId())) {
             array_shift($previous);
         }
         $this->items['sess_link']['prev']['value'] = 1;
     }
     $num_next_remove = max(count($next) - $this->getNumberOfNextSessions(), 0);
     while ($num_next_remove--) {
         if (!$ilUser->getPref('crs_sess_show_next_' . $this->getId())) {
             array_pop($next);
         }
         // @fixme
         $this->items['sess_link']['next']['value'] = 1;
     }
     $sessions = array_merge($previous, $current, $next);
     $this->items['sess'] = $sessions;
     // #15389 - see ilContainer::getSubItems()
     include_once 'Services/Container/classes/class.ilContainerSorting.php';
     $sort = ilContainerSorting::_getInstance($this->getId());
     $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block] = $sort->sortItems($this->items);
     return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
 }
 /**
  * 
  * @param array $usr_ids
  * @param type $type
  */
 public function assignUsersToGroup(array $usr_ids)
 {
     global $ilCtrl;
     $group_id = (int) $_REQUEST['grp_id'];
     $tomorrow = new ilDateTime(time(), IL_CAL_UNIX);
     $tomorrow->increment(IL_CAL_DAY, 1);
     // Get all future consultation hours
     include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
     include_once './Services/Booking/classes/class.ilBookingEntry.php';
     $apps = ilConsultationHourAppointments::getAppointmentIdsByGroup($this->user_id, $group_id, $tomorrow);
     $users = $usr_ids;
     $assigned_users = array();
     foreach ($apps as $app) {
         $booking = ilBookingEntry::getInstanceByCalendarEntryId($app);
         foreach ($users as $user) {
             if ($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings()) {
                 break;
             }
             if (!ilBookingEntry::lookupBookingsOfUser($apps, $user)) {
                 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
                 ilConsultationHourUtils::bookAppointment($user, $app);
                 $assigned_users[] = $user;
             }
         }
     }
     $this->sendInfoAboutUnassignedUsers(array_diff($users, $assigned_users));
     $ilCtrl->redirect($this, 'bookingList');
 }
Esempio n. 30
0
 /**
  * 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;
 }