• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/User/classes/class.ilObjUserFolder.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00034 require_once "./classes/class.ilObject.php";
00035 
00036 define('USER_FOLDER_ID',7);
00037 
00038 class ilObjUserFolder extends ilObject
00039 {
00046         function ilObjUserFolder($a_id,$a_call_by_reference = true)
00047         {
00048                 $this->type = "usrf";
00049                 $this->ilObject($a_id,$a_call_by_reference);
00050         }
00051 
00052 
00059         function delete()
00060         {
00061                 // DISABLED
00062                 return false;
00063 
00064                 // always call parent delete function first!!
00065                 if (!parent::delete())
00066                 {
00067                         return false;
00068                 }
00069                 // put here userfolder specific stuff
00070 
00071                 // always call parent delete function at the end!!
00072                 return true;
00073         }
00074 
00075 
00076         function getExportFilename($a_mode = "userfolder_export_excel_x86")
00077         {
00078                 $filename = "";
00079                 //$settings = $this->ilias->getAllSettings();
00080                 //$this->inst_id = $settings["inst_id"];
00081                 $inst_id = IL_INST_ID;
00082 
00083                 $date = time();
00084 
00085                 switch($a_mode)
00086                 {
00087                         case "userfolder_export_excel_x86":
00088                                 $filename = $date."__".$inst_id."__xls_usrf.xls";
00089                                 break;
00090                         case "userfolder_export_csv":
00091                                 $filename = $date."__".$inst_id."__csv_usrf.csv";
00092                                 break;
00093                         case "userfolder_export_xml":
00094                                 $filename = $date."__".$inst_id."__xml_usrf.xml";
00095                                 break;
00096                 }
00097                 return $filename;
00098         }
00099 
00100 
00108         function getExportDirectory()
00109         {
00110                 $export_dir = ilUtil::getDataDir()."/usrf_data/export";
00111 
00112                 return $export_dir;
00113         }
00114 
00123         function getExportFiles()
00124         {
00125                 $dir = $this->getExportDirectory();
00126 
00127                 // quit if export dir not available
00128                 if (!@is_dir($dir) or
00129                         !is_writeable($dir))
00130                 {
00131                         return array();
00132                 }
00133 
00134                 // open directory
00135                 $dir = dir($dir);
00136 
00137                 // initialize array
00138                 $file = array();
00139 
00140                 // get files and save the in the array
00141                 while ($entry = $dir->read())
00142                 {
00143                         if ($entry != "." and
00144                                 $entry != ".." and
00145                                 preg_match("/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,3}\$/", $entry, $matches))
00146                         {
00147                                 $filearray["filename"] = $entry;
00148                                 $filearray["filesize"] = filesize($this->getExportDirectory()."/".$entry);
00149                                 array_push($file, $filearray);
00150                         }
00151                 }
00152 
00153                 // close import directory
00154                 $dir->close();
00155 
00156                 // sort files
00157                 sort ($file);
00158                 reset ($file);
00159 
00160                 return $file;
00161         }
00162 
00163         function escapeXML($value)
00164         {
00165                 $value = str_replace("&", "&amp;", $value);
00166                 $value = str_replace("<", "&lt;", $value);
00167                 $value = str_replace(">", "&gt;", $value);
00168                 return $value;
00169         }
00170 
00171         function createXMLExport(&$settings, &$data, $filename)
00172         {
00173                 include_once './Services/User/classes/class.ilUserDefinedData.php';
00174                 include_once './Services/User/classes/class.ilObjUser.php';
00175 
00176                 global $rbacreview;
00177                 global $ilDB;
00178                 global $log;
00179 
00180                 $file = fopen($filename, "w");
00181 
00182                 if (is_array($data))
00183                 {
00184                                 include_once './Services/User/classes/class.ilUserXMLWriter.php';
00185 
00186                                 $xmlWriter = new ilUserXMLWriter();
00187                                 $xmlWriter->setObjects($data);
00188                                 $xmlWriter->setSettings($settings);
00189                                 $xmlWriter->setAttachRoles (true);
00190 
00191                                 if($xmlWriter->start())
00192                                 {
00193                                         fwrite($file, $xmlWriter->getXML());
00194                                 }
00195                 }
00196 
00197 /*
00198                 fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
00199                 fwrite($file, "<!DOCTYPE Users SYSTEM \"".ILIAS_HTTP_PATH."/xml/ilias_user_3_8.dtd\">\n");
00200                 fwrite($file, "<Users>");
00201                 foreach ($data as $row)
00202                 {
00203                         //$log->write(date("[y-m-d H:i:s] ")."User data export: processing user " . $row["login"]);
00204                         foreach ($row as $key => $value)
00205                         {
00206                                 $row[$key] = $this->escapeXML($value);
00207                         }
00208                         $userline = "";
00209                         // TODO: Define combobox for "Action" ???
00210                         if (strlen($row["language"]) == 0) $row["language"] = "en";
00211                         $userline .= "<User Id=\"il_".IL_INST_ID."_usr_".$row["usr_id"]."\" Language=\"".$row["language"]."\" Action=\"Insert\">";
00212                         if (array_search("login", $settings) !== FALSE)
00213                         {
00214                                 $userline .= "<Login>".$row["login"]."</Login>";
00215                         }
00216                         // Alternative way to get the roles of a user?
00217                         $query = sprintf("SELECT object_data.title, rbac_fa.* FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id",
00218                                 $ilDB->quote($row["usr_id"])
00219                         );
00220                         $rbacresult = $ilDB->query($query);
00221                         while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
00222                         {
00223                                 $type = "";
00224                                 if ($rbacrow["assign"] == "y")
00225                                 {
00226                                         if ($rbacrow["parent"] == ROLE_FOLDER_ID)
00227                                         {
00228                                                 $type = "Global";
00229                                         }
00230                                         else
00231                                         {
00232                                                 $type = "Local";
00233                                         }
00234                                         if (strlen($type))
00235                                         {
00236                                                 $userline .= "<Role Id=\"il_".IL_INST_ID."_role_".$rbacrow["rol_id"]."\" Type=\"".$type."\">".$rbacrow["title"]."</Role>";
00237                                         }
00238                                 }
00239                         }
00240                         //$log->write(date("[y-m-d H:i:s] ")."User data export: get all roles");
00241                         /* the export of roles is to expensive. on a system with 6000 users the following
00242                            section needs 37 seconds
00243 
00244                         $roles = $rbacreview->getRolesByFilter(1, $row["usr_id"]);
00245                         $ass_roles = $rbacreview->assignedRoles($row["usr_id"]);
00246                         foreach ($roles as $role)
00247                         {
00248                                 if (array_search($role["obj_id"], $ass_roles) !== FALSE)
00249                                 {
00250                                         $type = "";
00251                                         switch ($role["role_type"])
00252                                         {
00253                                                 case "global":
00254                                                         $type = "Global";
00255                                                         break;
00256                                                 case "local":
00257                                                         $type = "Local";
00258                                                         break;
00259                                         }
00260                                         if (strlen($type))
00261                                         {
00262                                                 $userline .= "<Role Id=\"".$role["obj_id"]."\" Type=\"".$type."\">".$role["title"]."</Role>";
00263                                         }
00264                                 }
00265                         }
00266                         */
00267 /*                      //$log->write(date("[y-m-d H:i:s] ")."User data export: got all roles");
00268                         $i2passwd = FALSE;
00269                         if (array_search("i2passwd", $settings) !== FALSE)
00270                         {
00271                                 if (strlen($row["i2passwd"])) $i2passwd = TRUE;
00272                                 if ($i2passwd) $userline .= "<Password Type=\"ILIAS2\">".$row["i2passwd"]."</Password>";
00273                         }
00274                         if ((!$i2passwd) && (array_search("passwd", $settings) !== FALSE))
00275                         {
00276                                 if (strlen($row["passwd"])) $userline .= "<Password Type=\"ILIAS3\">".$row["passwd"]."</Password>";
00277                         }
00278                         if (array_search("firstname", $settings) !== FALSE)
00279                         {
00280                                 if (strlen($row["firstname"])) $userline .= "<Firstname>".$row["firstname"]."</Firstname>";
00281                         }
00282                         if (array_search("lastname", $settings) !== FALSE)
00283                         {
00284                                 if (strlen($row["lastname"])) $userline .= "<Lastname>".$row["lastname"]."</Lastname>";
00285                         }
00286                         if (array_search("title", $settings) !== FALSE)
00287                         {
00288                                 if (strlen($row["title"])) $userline .= "<Title>".$row["title"]."</Title>";
00289                         }
00290                         if (array_search("upload", $settings) !== FALSE)
00291                         {
00292                                 // personal picture
00293                                 $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($row["usr_id"] . ""));
00294                                 $r = $ilDB->query($q);
00295                                 if ($r->numRows() == 1)
00296                                 {
00297                                         $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00298                                         $personal_picture = $personal_picture_data["value"];
00299                                         $webspace_dir = ilUtil::getWebspaceDir();
00300                                         $image_file = $webspace_dir."/usr_images/".$personal_picture;
00301                                         if (@is_file($image_file))
00302                                         {
00303                                                 $fh = fopen($image_file, "rb");
00304                                                 if ($fh)
00305                                                 {
00306                                                         $image_data = fread($fh, filesize($image_file));
00307                                                         fclose($fh);
00308                                                         $base64 = base64_encode($image_data);
00309                                                         $imagetype = "image/jpeg";
00310                                                         if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
00311                                                         {
00312                                                                 $imagetype = "image/".$matches[1];
00313                                                         }
00314                                                         $userline .= "<PersonalPicture imagetype=\"$imagetype\" encoding=\"Base64\">$base64</PersonalPicture>";
00315                                                 }
00316                                         }
00317                                 }
00318                         }
00319                         if (array_search("gender", $settings) !== FALSE)
00320                         {
00321                                 if (strlen($row["gender"])) $userline .= "<Gender>".$row["gender"]."</Gender>";
00322                         }
00323                         if (array_search("email", $settings) !== FALSE)
00324                         {
00325                                 if (strlen($row["email"])) $userline .= "<Email>".$row["email"]."</Email>";
00326                         }
00327                         if (array_search("institution", $settings) !== FALSE)
00328                         {
00329                                 if (strlen($row["institution"])) $userline .= "<Institution>".$row["institution"]."</Institution>";
00330                         }
00331                         if (array_search("street", $settings) !== FALSE)
00332                         {
00333                                 if (strlen($row["street"])) $userline .= "<Street>".$row["street"]."</Street>";
00334                         }
00335                         if (array_search("city", $settings) !== FALSE)
00336                         {
00337                                 if (strlen($row["city"])) $userline .= "<City>".$row["city"]."</City>";
00338                         }
00339                         if (array_search("zipcode", $settings) !== FALSE)
00340                         {
00341                                 if (strlen($row["zipcode"])) $userline .= "<PostalCode>".$row["zipcode"]."</PostalCode>";
00342                         }
00343                         if (array_search("country", $settings) !== FALSE)
00344                         {
00345                                 if (strlen($row["country"])) $userline .= "<Country>".$row["country"]."</Country>";
00346                         }
00347                         if (array_search("phone_office", $settings) !== FALSE)
00348                         {
00349                                 if (strlen($row["phone_office"])) $userline .= "<PhoneOffice>".$row["phone_office"]."</PhoneOffice>";
00350                         }
00351                         if (array_search("phone_home", $settings) !== FALSE)
00352                         {
00353                                 if (strlen($row["phone_home"])) $userline .= "<PhoneHome>".$row["phone_home"]."</PhoneHome>";
00354                         }
00355                         if (array_search("phone_mobile", $settings) !== FALSE)
00356                         {
00357                                 if (strlen($row["phone_mobile"])) $userline .= "<PhoneMobile>".$row["phone_mobile"]."</PhoneMobile>";
00358                         }
00359                         if (array_search("fax", $settings) !== FALSE)
00360                         {
00361                                 if (strlen($row["fax"])) $userline .= "<Fax>".$row["fax"]."</Fax>";
00362                         }
00363                         if (strlen($row["hobby"])) if (array_search("hobby", $settings) !== FALSE)
00364                         {
00365                                 $userline .= "<Hobby>".$row["hobby"]."</Hobby>";
00366                         }
00367                         if (array_search("department", $settings) !== FALSE)
00368                         {
00369                                 if (strlen($row["department"])) $userline .= "<Department>".$row["department"]."</Department>";
00370                         }
00371                         if (array_search("referral_comment", $settings) !== FALSE)
00372                         {
00373                                 if (strlen($row["referral_comment"])) $userline .= "<Comment>".$row["referral_comment"]."</Comment>";
00374                         }
00375                         if (array_search("matriculation", $settings) !== FALSE)
00376                         {
00377                                 if (strlen($row["matriculation"])) $userline .= "<Matriculation>".$row["matriculation"]."</Matriculation>";
00378                         }
00379                         if (array_search("active", $settings) !== FALSE)
00380                         {
00381                                 if ($row["active"])
00382                                 {
00383                                         $userline .= "<Active>true</Active>";
00384                                 }
00385                                 else
00386                                 {
00387                                         $userline .= "<Active>false</Active>";
00388                                 }
00389                         }
00390                         if (array_search("client_ip", $settings) !== FALSE)
00391                         {
00392                                 if (strlen($row["client_ip"])) $userline .= "<ClientIP>".$row["client_ip"]."</ClientIP>";
00393                         }
00394                         if (array_search("time_limit_owner", $settings) !== FALSE)
00395                         {
00396                                 if (strlen($row["time_limit_owner"])) $userline .= "<TimeLimitOwner>".$row["time_limit_owner"]."</TimeLimitOwner>";
00397                         }
00398                         if (array_search("time_limit_unlimited", $settings) !== FALSE)
00399                         {
00400                                 if (strlen($row["time_limit_unlimited"])) $userline .= "<TimeLimitUnlimited>".$row["time_limit_unlimited"]."</TimeLimitUnlimited>";
00401                         }
00402                         if (array_search("time_limit_from", $settings) !== FALSE)
00403                         {
00404                                 if (strlen($row["time_limit_from"])) $userline .= "<TimeLimitFrom>".$row["time_limit_from"]."</TimeLimitFrom>";
00405                         }
00406                         if (array_search("time_limit_until", $settings) !== FALSE)
00407                         {
00408                                 if (strlen($row["time_limit_until"])) $userline .= "<TimeLimitUntil>".$row["time_limit_until"]."</TimeLimitUntil>";
00409                         }
00410                         if (array_search("time_limit_message", $settings) !== FALSE)
00411                         {
00412                                 if (strlen($row["time_limit_message"])) $userline .= "<TimeLimitMessage>".$row["time_limit_message"]."</TimeLimitMessage>";
00413                         }
00414                         if (array_search("approve_date", $settings) !== FALSE)
00415                         {
00416                                 if (strlen($row["approve_date"])) $userline .= "<ApproveDate>".$row["approve_date"]."</ApproveDate>";
00417                         }
00418                         if (array_search("agree_date", $settings) !== FALSE)
00419                         {
00420                                 if (strlen($row["agree_date"])) $userline .= "<AgreeDate>".$row["agree_date"]."</AgreeDate>";
00421                         }
00422                         if ((int) $row["ilinc_id"] !=0) {
00423                                         if (array_search("ilinc_id", $settings) !== FALSE)
00424                                         {
00425                                                 if (strlen($row["ilinc_id"])) $userline .= "<iLincID>".$row["ilinc_id"]."</iLincID>";
00426                                         }
00427                                         if (array_search("ilinc_login", $settings) !== FALSE)
00428                                         {
00429                                                 if (strlen($row["ilinc_login"])) $userline .= "<iLincLogin>".$row["ilinc_login"]."</iLincLogin>";
00430                                         }
00431                                         if (array_search("ilinc_passwd", $settings) !== FALSE)
00432                                         {
00433                                                 if (strlen($row["ilinc_passwd"])) $userline .= "<iLincPasswd>".$row["ilinc_passwd"]."</iLincPasswd>";
00434                                         }
00435                         }
00436                         if (array_search("auth_mode", $settings) !== FALSE)
00437                         {
00438                                 if (strlen($row["auth_mode"])) $userline .= "<AuthMode type=\"".$row["auth_mode"]."\"></AuthMode>";
00439                         }
00440                         if (array_search("skin_style", $settings) !== FALSE)
00441                         {
00442                                 $userline .=
00443                                         "<Look Skin=\"" . ilObjUser::_lookupPref($row["usr_id"], "skin") . "\" " .
00444                                         "Style=\"" . ilObjUser::_lookupPref($row["usr_id"], "style") . "\"></Look>";
00445                         }
00446 
00447                         if (array_search("last_update", $settings) !== FALSE)
00448                         {
00449                                 if (strlen($row["last_update"])) $userline .= "<LastUpdate>".$row["last_update"]."</LastUpdate>";
00450                         }
00451 
00452                         if (array_search("last_login", $settings) !== FALSE)
00453                         {
00454                                 if (strlen($row["last_login"])) $userline .= "<LastLogin>".$row["last_login"]."</LastLogin>";
00455                         }
00456 
00457                         // Append User defined field data
00458                         $udf_data = new ilUserDefinedData($row['usr_id']);
00459                         $userline .= $udf_data->toXML();
00460 
00461                         $userline .= "</User>";
00462                         fwrite($file, $userline);
00463                 }
00464                 fwrite($file, "</Users>");
00465                 fclose($file);*/
00466         }
00467 
00468         function createCSVExport(&$settings, &$data, $filename)
00469         {
00470                 $headerrow = array();
00471                 foreach ($settings as $value)
00472                 {
00473                         array_push($headerrow, $this->lng->txt($value));
00474                 }
00475                 $separator = ";";
00476                 $file = fopen($filename, "w");
00477                 $formattedrow =& ilUtil::processCSVRow($headerrow, TRUE, $separator);
00478                 fwrite($file, join ($separator, $formattedrow) ."");
00479                 foreach ($data as $row)
00480                 {
00481                         $csvrow = array();
00482                         foreach ($settings as $header)
00483                         {
00484                                 array_push($csvrow, $row[$header]);
00485                         }
00486                         $formattedrow =& ilUtil::processCSVRow($csvrow, TRUE, $separator);
00487                         fwrite($file, join ($separator, $formattedrow) ."\n");
00488                 }
00489                 fclose($file);
00490         }
00491 
00492         function createExcelExport(&$settings, &$data, $filename, $a_mode)
00493         {
00494                 include_once "./classes/class.ilExcelUtils.php";
00495                 include_once "./classes/class.ilExcelWriterAdapter.php";
00496                 $adapter = new ilExcelWriterAdapter($filename, FALSE);
00497                 $workbook = $adapter->getWorkbook();
00498                 // Creating a worksheet
00499                 $format_bold =& $workbook->addFormat();
00500                 $format_bold->setBold();
00501                 $format_percent =& $workbook->addFormat();
00502                 $format_percent->setNumFormat("0.00%");
00503                 $format_datetime =& $workbook->addFormat();
00504                 $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
00505                 $format_title =& $workbook->addFormat();
00506                 $format_title->setBold();
00507                 $format_title->setColor('black');
00508                 $format_title->setPattern(1);
00509                 $format_title->setFgColor('silver');
00510                 $worksheet =& $workbook->addWorksheet();
00511                 $row = 0;
00512                 $col = 0;
00513 
00514                 foreach ($settings as $value)
00515                 {
00516                         $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title);
00517                         $col++;
00518                 }
00519 
00520 
00521                 foreach ($data as $index => $rowdata)
00522                 {
00523                         $row++;
00524                         $col = 0;
00525                         foreach ($settings as $fieldname)
00526                         {
00527 //                      foreach ($rowdata as $rowindex => $value)
00528 //                      {
00529                                 $value = $rowdata[$fieldname];
00530                                 switch ($fieldname)
00531                                 {
00532                                         case "language":
00533                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("lang_".$value), $a_mode));
00534                                                 break;
00535                                         case "time_limit_from":
00536                                         case "time_limit_until":
00537                                                 $date = strftime("%Y-%m-%d %H:%M:%S", $value);
00538                                                 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
00539                                                 {
00540                                                         $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00541                                                 }
00542                                                 break;
00543                                         case "last_login":
00544                                         case "last_update":
00545                                         case "create_date":
00546                                         case "approve_date":
00547                                         case "agree_date":
00548                                                 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value, $matches))
00549                                                 {
00550                                                         $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00551                                                 }
00552                                                 break;
00553                                         default:
00554                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode));
00555                                                 break;
00556                                 }
00557                                 $col++;
00558                         }
00559                 }
00560                 $workbook->close();
00561         }
00562 
00568         static function getExportSettings()
00569         {
00570                 global $ilDB;
00571 
00572                 $db_settings = array();
00573                 $profile_fields =& ilObjUserFolder::getProfileFields();
00574                 $query = "SELECT * FROM `settings` WHERE keyword LIKE '%usr_settings_export_%' AND value = '1'";
00575                 $result = $ilDB->query($query);
00576                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00577                 {
00578                         if (preg_match("/usr_settings_export_(.*)/", $row["keyword"], $setting))
00579                         {
00580                                 array_push($db_settings, $setting[1]);
00581                         }
00582                 }
00583                 $export_settings = array();
00584                 foreach ($profile_fields as $key => $value)
00585                 {
00586                         if (in_array($value, $db_settings))
00587                         {
00588                                 if (strcmp($value, "password") == 0)
00589                                 {
00590                                         array_push($export_settings, "passwd");
00591                                 }
00592                                 else
00593                                 {
00594                                         array_push($export_settings, $value);
00595                                 }
00596                         }
00597                 }
00598                 array_push($export_settings, "login");
00599                 array_push($export_settings, "last_login");
00600                 array_push($export_settings, "last_update");
00601                 array_push($export_settings, "create_date");
00602                 array_push($export_settings, "i2passwd");
00603                 array_push($export_settings, "time_limit_owner");
00604                 array_push($export_settings, "time_limit_unlimited");
00605                 array_push($export_settings, "time_limit_from");
00606                 array_push($export_settings, "time_limit_until");
00607                 array_push($export_settings, "time_limit_message");
00608                 array_push($export_settings, "active");
00609                 array_push($export_settings, "approve_date");
00610                 array_push($export_settings, "agree_date");
00611                 array_push($export_settings, "ilinc_id");
00612                 array_push($export_settings, "ilinc_login");
00613                 array_push($export_settings, "ilinc_passwd");
00614                 array_push($export_settings, "client_ip");
00615                 array_push($export_settings, "auth_mode");
00616                 array_push($export_settings, "ext_account");
00617                 return $export_settings;
00618         }
00619 
00623         function buildExportFile($a_mode = "userfolder_export_excel_x86", $user_data_filter = FALSE)
00624         {
00625                 global $ilBench;
00626                 global $log;
00627                 global $ilDB;
00628                 global $ilias;
00629 
00630                 //get Log File
00631                 $expDir = $this->getExportDirectory();
00632                 //$expLog = &$log;
00633                 //$expLog->delete();
00634                 //$expLog->setLogFormat("");
00635                 //$expLog->write(date("[y-m-d H:i:s] ")."Start export of user data");
00636 
00637                 // create export directory if needed
00638                 $this->createExportDirectory();
00639 
00640                 //get data
00641                 //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
00642                 $settings =& $this->getExportSettings();
00643                 $data = array();
00644                 $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data, usr_pref WHERE usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language' ORDER BY usr_data.lastname, usr_data.firstname";
00645                 $result = $ilDB->query($query);
00646                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00647                 {
00648                         if (is_array($user_data_filter))
00649                         {
00650                                 if (in_array($row["usr_id"], $user_data_filter)) array_push($data, $row);
00651                         }
00652                         else
00653                         {
00654                                 array_push($data, $row);
00655                         }
00656                 }
00657                 //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
00658 
00659                 $fullname = $expDir."/".$this->getExportFilename($a_mode);
00660                 switch ($a_mode)
00661                 {
00662                         case "userfolder_export_excel_x86":
00663                                 $this->createExcelExport($settings, $data, $fullname, "latin1");
00664                                 break;
00665                         case "userfolder_export_csv":
00666                                 $this->createCSVExport($settings, $data, $fullname);
00667                                 break;
00668                         case "userfolder_export_xml":
00669                                 $this->createXMLExport($settings, $data, $fullname);
00670                                 break;
00671                 }
00672                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished export of user data");
00673 
00674                 return $fullname;
00675         }
00676 
00677 
00683         function createExportDirectory()
00684         {
00685                 if (!@is_dir($this->getExportDirectory()))
00686                 {
00687                         $usrf_data_dir = ilUtil::getDataDir()."/usrf_data";
00688                         ilUtil::makeDir($usrf_data_dir);
00689                         if(!is_writable($usrf_data_dir))
00690                         {
00691                                 $this->ilias->raiseError("Userfolder data directory (".$usrf_data_dir
00692                                         .") not writeable.",$this->ilias->error_obj->MESSAGE);
00693                         }
00694 
00695                         // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00696                         $export_dir = $usrf_data_dir."/export";
00697                         ilUtil::makeDir($export_dir);
00698                         if(!@is_dir($export_dir))
00699                         {
00700                                 $this->ilias->raiseError("Creation of Userfolder Export Directory failed.",$this->ilias->error_obj->MESSAGE);
00701                         }
00702                 }
00703         }
00704 
00710         static function &getProfileFields()
00711         {
00712                 $profile_fields = array(
00713                         "gender",
00714                         "firstname",
00715                         "lastname",
00716                         "title",                        
00717                         "password",
00718                         "institution",
00719                         "department",
00720                         "street",
00721                         "zipcode",
00722                         "city",
00723                         "country",
00724                         "phone_office",
00725                         "phone_home",
00726                         "phone_mobile",
00727                         "fax",
00728                         "email",
00729                         "hobby",
00730                         "referral_comment",
00731                         "matriculation",
00732                         "upload",
00733                         "language",
00734                         "skin_style",
00735                         "hits_per_page",
00736                         "show_users_online",
00737                         "instant_messengers",
00738                         "hide_own_online_status" 
00739                 );
00740                 return $profile_fields;
00741         }
00742 
00743         function _writeNewAccountMail($a_lang, $a_subject, $a_sal_g, $a_sal_f, $a_sal_m, $a_body)
00744         {
00745                 global $ilDB;
00746 
00747                 $ilDB->query("REPLACE INTO usr_new_account_mail ".
00748                         "(lang, subject, body, sal_g, sal_f, sal_m) VALUES ".
00749                         "(".$ilDB->quote($a_lang).",".$ilDB->quote($a_subject).",".$ilDB->quote($a_body).
00750                         ",".$ilDB->quote($a_sal_g).",".$ilDB->quote($a_sal_f).",".$ilDB->quote($a_sal_m).")");
00751         }
00752 
00753         function _lookupNewAccountMail($a_lang)
00754         {
00755                 global $ilDB;
00756 
00757                 $set = $ilDB->query("SELECT * FROM usr_new_account_mail ".
00758                         " WHERE lang = ".$ilDB->quote($a_lang));
00759 
00760                 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00761                 {
00762                         return $rec;
00763                 }
00764                 return array();
00765         }
00766         
00778         public static function _updateUserFolderAssignment($a_old_id,$a_new_id)
00779         {
00780                 global $ilDB;
00781                 
00782                 $query = "UPDATE usr_data SET time_limit_owner = ".$ilDB->quote($a_new_id)." ".
00783                         "WHERE time_limit_owner = ".$ilDB->quote($a_old_id)." ";
00784                 $ilDB->query($query);
00785                 
00786                 return true;
00787         }
00788         
00789 
00790 } // END class.ilObjUserFolder
00791 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1