14require_once 
"./Services/Object/classes/class.ilObject.php";
 
   16define(
'USER_FOLDER_ID', 7);
 
   31    public function __construct($a_id, $a_call_by_reference = 
true)
 
   44    public function delete()
 
   50        if (!parent::delete()) {
 
   71                $filename = $date . 
"__" . $inst_id . 
"__xls_usrf";
 
   74                $filename = $date . 
"__" . $inst_id . 
"__csv_usrf.csv";
 
   77                $filename = $date . 
"__" . $inst_id . 
"__xml_usrf.xml";
 
  111        if (!@is_dir($dir) or
 
  112            !is_writeable($dir)) {
 
  123        while ($entry = $dir->read()) {
 
  124            if ($entry != 
"." and
 
  126                preg_match(
"/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,4}\$/", $entry, $matches)) {
 
  127                $filearray[
"filename"] = $entry;
 
  129                array_push($file, $filearray);
 
  145        $value = str_replace(
"&", 
"&", $value);
 
  146        $value = str_replace(
"<", 
"<", $value);
 
  147        $value = str_replace(
">", 
">", $value);
 
  153        include_once 
'./Services/User/classes/class.ilUserDefinedData.php';
 
  154        include_once 
'./Services/User/classes/class.ilObjUser.php';
 
  168        if (is_array(
$data)) {
 
  169            include_once 
'./Services/User/classes/class.ilUserXMLWriter.php';
 
  172            $xmlWriter->setObjects(
$data);
 
  173            $xmlWriter->setSettings($settings);
 
  174            $xmlWriter->setAttachRoles(
true);
 
  176            if ($xmlWriter->start()) {
 
  177                fwrite($file, $xmlWriter->getXML());
 
  188        include_once 
'./Services/User/classes/class.ilUserDefinedFields.php';
 
  191        $udf_ex_fields = array();
 
  192        foreach ($udf_obj->getDefinitions() as $definition) {
 
  193            if ($definition[
"export"] != 
false) {
 
  194                $udf_ex_fields[] = array(
"name" => $definition[
"field_name"],
 
  195                    "id" => $definition[
"field_id"]);
 
  199        return $udf_ex_fields;
 
  206        $headerrow = array();
 
  208        foreach ($settings as $value) { 
 
  209            array_push($headerrow, $this->lng->txt($value));
 
  211        foreach ($udf_ex_fields as 
$f) {        
 
  212            array_push($headerrow, 
$f[
"name"]);
 
  218        fwrite($file, join($separator, $formattedrow) . 
"\n");
 
  219        foreach (
$data as $row) {
 
  221            foreach ($settings as $header) {    
 
  223                if (is_array($row[$header])) {
 
  224                    $row[$header] = implode(
", ", $row[$header]);
 
  227                array_push($csvrow, $row[$header]);
 
  231            reset($udf_ex_fields);
 
  232            if (count($udf_ex_fields) > 0) {
 
  233                include_once(
"./Services/User/classes/class.ilUserDefinedData.php");
 
  235                foreach ($udf_ex_fields as 
$f) {        
 
  236                    array_push($csvrow, $udf->get(
"f_" . 
$f[
"id"]));
 
  241            fwrite($file, join($separator, $formattedrow) . 
"\n");
 
  248        include_once 
"./Services/Excel/classes/class.ilExcel.php";
 
  250        $worksheet->addSheet($this->lng->txt(
"users"));
 
  258        foreach ($settings as $value) { 
 
  259            if ($value == 
'ext_account') {
 
  260                $value = 
'user_ext_account';
 
  262            $worksheet->setCell($row, $col, $this->lng->txt($value));
 
  265        foreach ($udf_ex_fields as 
$f) {        
 
  266            $worksheet->setCell($row, $col, 
$f[
"name"]);
 
  269        $worksheet->setBold(
"A1:" . $worksheet->getColumnCoord($col - 1) . 
"1");
 
  271        $this->lng->loadLanguageModule(
"meta");
 
  277            foreach ($settings as $fieldname) {
 
  278                $value = $rowdata[$fieldname];
 
  279                switch ($fieldname) {
 
  281                        $worksheet->setCell($row, $col, $this->lng->txt(
"meta_l_" . $value));
 
  283                    case "time_limit_from":
 
  284                    case "time_limit_until":
 
  288                        $worksheet->setCell($row, $col, $value);
 
  298                        $worksheet->setCell($row, $col, $value);
 
  301                    case "interests_general":
 
  302                    case "interests_help_offered":
 
  303                    case "interests_help_looking":
 
  304                        if (is_array($value) && 
sizeof($value)) {
 
  305                            $value = implode(
", ", $value);
 
  313                        $worksheet->setCell($row, $col, $value);
 
  320            reset($udf_ex_fields);
 
  321            if (count($udf_ex_fields) > 0) {
 
  322                include_once(
"./Services/User/classes/class.ilUserDefinedData.php");
 
  324                foreach ($udf_ex_fields as 
$f) {        
 
  325                    $worksheet->setCell($row, $col, $udf->get(
"f_" . 
$f[
"id"]));
 
  345        $db_settings = array();
 
  347        include_once(
"./Services/User/classes/class.ilUserProfile.php");
 
  349        $up->skipField(
"roles");
 
  350        $profile_fields = $up->getStandardFields();
 
  355        $query = 
"SELECT * FROM settings WHERE " .
 
  356            $ilDB->like(
"keyword", 
"text", 
'%usr_settings_export_%');
 
  359            if ($row[
"value"] == 
"1") {
 
  360                if (preg_match(
"/usr_settings_export_(.*)/", $row[
"keyword"], $setting)) {
 
  361                    array_push($db_settings, $setting[1]);
 
  365        $export_settings = array();
 
  366        foreach ($profile_fields as $key => $value) {
 
  367            if (in_array($key, $db_settings)) {
 
  368                if (strcmp($key, 
"password") == 0) {
 
  372                    array_push($export_settings, $key);
 
  376        array_push($export_settings, 
"usr_id");
 
  377        array_push($export_settings, 
"login");
 
  378        array_push($export_settings, 
"last_login");
 
  379        array_push($export_settings, 
"last_update");
 
  380        array_push($export_settings, 
"create_date");
 
  381        array_push($export_settings, 
"time_limit_owner");
 
  382        array_push($export_settings, 
"time_limit_unlimited");
 
  383        array_push($export_settings, 
"time_limit_from");
 
  384        array_push($export_settings, 
"time_limit_until");
 
  385        array_push($export_settings, 
"time_limit_message");
 
  386        array_push($export_settings, 
"active");
 
  387        array_push($export_settings, 
"approve_date");
 
  388        array_push($export_settings, 
"agree_date");
 
  389        array_push($export_settings, 
"client_ip");
 
  390        array_push($export_settings, 
"auth_mode");
 
  391        array_push($export_settings, 
"ext_account");
 
  392        array_push($export_settings, 
"feedhash");
 
  393        return $export_settings;
 
  404    public function buildExportFile($a_mode = self::FILE_TYPE_EXCEL, $user_data_filter = 
false, $use_temp_dir = 
false)
 
  417        $ilias = 
$DIC[
'ilias'];
 
  437        $query = 
"SELECT * FROM usr_pref WHERE keyword = " . 
$ilDB->quote(
'language', 
'text');
 
  439        $languages = array();
 
  441            $languages[$row[
'usr_id']] = $row[
'value'];
 
  446        $set = 
$ilDB->query(
"SELECT * FROM usr_data_multi");
 
  447        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  448            if (!is_array($user_data_filter) ||
 
  449                in_array($row[
"usr_id"], $user_data_filter)) {
 
  450                $multi[$row[
"usr_id"]][$row[
"field_id"]][] = $row[
"value"];
 
  455        $query = 
"SELECT usr_data.* FROM usr_data  " .
 
  456            " ORDER BY usr_data.lastname, usr_data.firstname";
 
  459            if (isset($languages[$row[
'usr_id']])) {
 
  460                $row[
'language'] = $languages[$row[
'usr_id']];
 
  462                $row[
'language'] = 
$lng->getDefaultLanguage();
 
  465            if (isset($multi[$row[
"usr_id"]])) {
 
  466                $row = array_merge($row, $multi[$row[
"usr_id"]]);
 
  469            if (is_array($user_data_filter)) {
 
  470                if (in_array($row[
"usr_id"], $user_data_filter)) {
 
  471                    array_push(
$data, $row);
 
  474                array_push(
$data, $row);
 
  506            if (!is_writable($usrf_data_dir)) {
 
  507                $this->
ilias->raiseError(
"Userfolder data directory (" . $usrf_data_dir
 
  508                    . 
") not writeable.", $this->
ilias->error_obj->MESSAGE);
 
  512            $export_dir = $usrf_data_dir . 
"/export";
 
  514            if (!@is_dir($export_dir)) {
 
  515                $this->
ilias->raiseError(
"Creation of Userfolder Export Directory failed.", $this->
ilias->error_obj->MESSAGE);
 
  528        include_once(
"./Services/User/classes/class.ilUserProfile.php");
 
  530        $up->skipField(
"username");
 
  531        $up->skipField(
"roles");
 
  532        $up->skipGroup(
"preferences");
 
  533        $fds = $up->getStandardFields();
 
  534        foreach ($fds as $k => 
$f) {
 
  535            $profile_fields[] = $k;
 
  538        return $profile_fields;
 
  547        if (self::_lookupNewAccountMail($a_lang)) {
 
  549                'subject' => array(
'text',$a_subject),
 
  550                'body' => array(
'clob',$a_body),
 
  551                'sal_g' => array(
'text',$a_sal_g),
 
  552                'sal_f' => array(
'text',$a_sal_f),
 
  553                'sal_m' => array(
'text',$a_sal_m)
 
  558                array(
'lang' => array(
'text',$a_lang), 
'type' => array(
'text',
'nacc'))
 
  562                'subject' => array(
'text',$a_subject),
 
  563                'body' => array(
'clob',$a_body),
 
  564                'sal_g' => array(
'text',$a_sal_g),
 
  565                'sal_f' => array(
'text',$a_sal_f),
 
  566                'sal_m' => array(
'text',$a_sal_m),
 
  567                'lang' => array(
'text',$a_lang),
 
  568                'type' => array(
'text',
'nacc')
 
  570            $ilDB->insert(
'mail_template', $values);
 
  587        include_once 
"Services/User/classes/class.ilFSStorageUserFolder.php";
 
  590        $path = $fs->getAbsolutePath() . 
"/";
 
  596            array(
'att_file' => array(
'text', $a_name)),
 
  597            array(
'lang' => array(
'text',$a_lang), 
'type' => array(
'text',
'nacc'))
 
  611        include_once 
"Services/User/classes/class.ilFSStorageUserFolder.php";
 
  613        $path = $fs->getAbsolutePath() . 
"/";
 
  615        if (file_exists($path . $a_lang)) {
 
  616            unlink($path . $a_lang);
 
  621            array(
'att_file' => array(
'text', 
'')),
 
  622            array(
'lang' => array(
'text',$a_lang), 
'type' => array(
'text',
'nacc'))
 
  636        $set = 
$ilDB->query(
"SELECT * FROM mail_template " .
 
  637            " WHERE type='nacc' AND lang = " . 
$ilDB->quote($a_lang, 
'text'));
 
  663        $query = 
"UPDATE usr_data SET time_limit_owner = " . 
$ilDB->quote($a_new_id, 
"integer") . 
" " .
 
  664            "WHERE time_limit_owner = " . 
$ilDB->quote($a_old_id, 
"integer") . 
" ";
 
An exception for terminatinating execution or to throw for unit testing.
const USER_FOLDER_ID
Class ilObjUserFolder.
@classDescription Date and time handling
static _deleteAccountMailAttachment($a_lang)
Delete account mail attachment.
createExportDirectory()
creates data directory for export files (data_dir/usrf_data/export, depending on data directory that ...
buildExportFile($a_mode=self::FILE_TYPE_EXCEL, $user_data_filter=false, $use_temp_dir=false)
build xml export file
getExportFilename($a_mode=self::FILE_TYPE_EXCEL)
getUserDefinedExportFields()
Get all exportable user defined fields.
const ORG_OP_EDIT_USER_ACCOUNTS
createExcelExport(&$settings, &$data, $filename)
__construct($a_id, $a_call_by_reference=true)
Constructor @access public.
static _updateAccountMailAttachment($a_lang, $a_tmp_name, $a_name)
Update account mail attachment.
createCSVExport(&$settings, &$data, $filename)
createXMLExport(&$settings, &$data, $filename)
static _updateUserFolderAssignment($a_old_id, $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts.
static getExportSettings()
getExport Settings
static & getProfileFields()
Get profile fields (DEPRECATED, use ilUserProfile() instead)
static _writeNewAccountMail($a_lang, $a_subject, $a_sal_g, $a_sal_f, $a_sal_m, $a_body)
static _lookupNewAccountMail($a_lang)
getExportFiles()
Get a list of the already exported files in the export directory.
getExportDirectory()
Get the location of the export directory for the user accounts.
Class ilObject Basic functions for all objects.
static _getInstance()
Get instance.
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static & processCSVRow(&$row, $quoteAll=false, $separator=";", $outUTF8=false, $compatibleWithMSExcel=true)
Convertes an array for CSV usage.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
foreach($_POST as $key=> $value) $res