/**
  * export released
  *
  * @access protected
  * @return
  */
 protected function exportReleased()
 {
     global $ilObjDataCache;
     include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
     $exported = ilECSExport::getExportedIds();
     $ilObjDataCache->preloadObjectCache($exported);
     include_once 'Services/Utilities/classes/class.ilCSVWriter.php';
     $writer = new ilCSVWriter();
     $writer->addColumn($this->lng->txt('title'));
     $writer->addColumn($this->lng->txt('description'));
     $writer->addColumn($this->lng->txt('ecs_field_courseID'));
     $writer->addColumn($this->lng->txt('ecs_field_term'));
     $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
     $writer->addColumn($this->lng->txt('ecs_field_courseType'));
     $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
     $writer->addColumn($this->lng->txt('ecs_field_credits'));
     $writer->addColumn($this->lng->txt('ecs_field_room'));
     $writer->addColumn($this->lng->txt('ecs_field_cycle'));
     $writer->addColumn($this->lng->txt('ecs_field_begin'));
     $writer->addColumn($this->lng->txt('ecs_field_end'));
     $writer->addColumn($this->lng->txt('last_update'));
     include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
     $settings = ilECSDataMappingSettings::_getInstance();
     foreach ($exported as $obj_id) {
         include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php';
         $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
         $writer->addRow();
         $writer->addColumn(ilObject::_lookupTitle($obj_id));
         $writer->addColumn(ilObject::_lookupDescription($obj_id));
         $field = $settings->getMappingByECSName('courseID');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('term');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('lecturer');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('courseType');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('semester_hours');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('credits');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('room');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('cycle');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName('begin');
         $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field], true) : '');
         $field = $settings->getMappingByECSName('end');
         $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field], true) : '');
         $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
     }
     ilUtil::deliverData($writer->getCSVString(), date("Y_m_d") . "_ecs_export.csv", "text/csv");
 }
 protected function exportCSV(array $a_data, $a_scale)
 {
     global $lng, $ilClientIniFile, $ilUser;
     ilDatePresentation::setUseRelativeDates(false);
     include_once './Services/Link/classes/class.ilLink.php';
     include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
     $csv = new ilCSVWriter();
     $csv->setSeparator(";");
     $now = time();
     // meta
     $meta = array($lng->txt("trac_name_of_installation") => $ilClientIniFile->readVariable('client', 'name'), $lng->txt("trac_report_date") => ilDatePresentation::formatDate(new ilDateTime($now, IL_CAL_UNIX), IL_CAL_DATETIME), $lng->txt("trac_report_owner") => $ilUser->getFullName());
     foreach ($a_data as $idx => $item) {
         switch ($idx) {
             case "title":
                 $meta[$lng->txt("title")] = $item;
                 break;
             case "active":
                 // nothing to do
                 break;
             case "closed_details":
                 foreach ($item as $detail) {
                     $meta[$a_data["closed"][0] . " - " . $detail[0]] = $detail[1];
                 }
                 break;
             default:
                 $meta[$item[0]] = $item[1];
                 break;
         }
     }
     foreach ($meta as $caption => $value) {
         $csv->addColumn(strip_tags($caption));
         $csv->addColumn(strip_tags($value));
         $csv->addRow();
     }
     $csv->addRow();
     // aggregate data
     $aggr_data = $this->adaptDataToScale($a_scale, $a_data["active"], 700);
     unset($a_data);
     // header
     $first = $aggr_data;
     $first = array_keys(array_shift($first));
     foreach ($first as $column) {
         // split weekday and time slot again
         if ($a_scale == self::SCALE_PERIODIC_WEEK && $column == "slot_begin") {
             $csv->addColumn("weekday");
             $csv->addColumn("time");
         } else {
             $csv->addColumn(strip_tags($column));
         }
     }
     $csv->addRow();
     // data
     foreach ($aggr_data as $row) {
         foreach ($row as $column => $value) {
             if (is_array($value)) {
                 $value = implode(', ', $value);
             }
             switch ($column) {
                 case "slot_begin":
                     // split weekday and time slot again
                     if ($a_scale == self::SCALE_PERIODIC_WEEK) {
                         $csv->addColumn(ilCalendarUtil::_numericDayToString(substr($value, 0, 1)));
                         $value = substr($value, 1, 2) . ":" . substr($value, 3, 2);
                         break;
                     }
                     // fallthrough
                 // fallthrough
                 case "slot_end":
                     $value = date("d.m.Y H:i", $value);
                     break;
             }
             $csv->addColumn(strip_tags($value));
         }
         $csv->addRow();
     }
     // send
     $filename .= "session_statistics_" . date("Ymd", $now) . ".csv";
     header("Content-type: text/comma-separated-values");
     header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
     header("Pragma: public");
     echo $csv->getCSVString();
     exit;
 }
 /**
  * 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');
 }
 public function exportCodes()
 {
     $codes = $this->coupon_obj->getCodesByCouponId($_GET["coupon_id"]);
     if (is_array($codes)) {
         include_once './Services/Utilities/classes/class.ilCSVWriter.php';
         $csv = new ilCSVWriter();
         $csv->setDelimiter("");
         foreach ($codes as $data) {
             if ($data["pcc_code"]) {
                 $csv->addColumn($data["pcc_code"]);
                 $csv->addRow();
             }
         }
         ilUtil::deliverData($csv->getCSVString(), "code_export_" . date("Ymdhis") . ".csv");
     }
     $this->showCodes();
     return true;
 }