38 $this->_aSystem = $aSystem;
49 if (isset(
$GLOBALS[
'chWsbClasses'][
'ChWsbExport!'.$sObject]))
50 return $GLOBALS[
'chWsbClasses'][
'ChWsbExport!'.$sObject];
58 if (!($sClass = $aObject[
'class_name']))
61 if (!
empty($aObject[
'class_file']))
62 require_once(CH_DIRECTORY_PATH_ROOT . $aObject[
'class_file']);
66 $o =
new $sClass($aObject);
68 return (
$GLOBALS[
'chWsbClasses'][
'ChWsbExport!'.$sObject] =
$o);
75 if (!isset(
$GLOBALS[
'ch_dol_export_systems']))
77 return $GLOBALS[
'ch_dol_export_systems'];
87 return "Profile($iProfileId) doesn't exist";
92 if (!(
$o = self::getObjectInstance($sSystem)))
97 $aExports[$sSystem] = $a;
102 return 'Export zip file creation failed';
105 if (!self::sendEmailNotification(
$aProfile, $sFileName))
106 return "Send notification email to user($iProfileId) failed";
114 $aTemplate = $oEmailTemplate->getTemplate(
't_ExportReady',
$aProfile[
'ID']);
115 $aTemplateVars = array (
116 'FileUrl' => CH_WSB_URL_CACHE_PUBLIC . $sFilename,
123 if (!class_exists(
'ZipArchive'))
127 $sFilePath = CH_DIRECTORY_PATH_CACHE_PUBLIC . $sFileName;
129 $oZip =
new ZipArchive();
130 if ($oZip->open($sFilePath, ZipArchive::CREATE)!==
TRUE)
135 $sSqlDump =
"-- Cheetah user data export\n";
136 $sSqlDump .=
"-- Profile ID: $iProfileId\n";
138 $sSqlDump .=
"-- Cheetah Version: " .
$GLOBALS[
'site'][
'ver'] .
'.' .
$GLOBALS[
'site'][
'build'] .
"\n";
139 foreach ($aExports
as $sSystem => $a) {
141 if (!
empty($a[
'sql']))
142 $sSqlDump .=
"\n\n-- " . $sSystem .
"\n\n" . $a[
'sql'];
145 if (!
empty($a[
'files']))
146 chdir(CH_DIRECTORY_PATH_ROOT);
152 $oZip->addFromString(
'/dump.sql', $sSqlDump);
182 foreach ($this->_aTablesWithFiles
as $sTableName =>
$aFields)
195 foreach ($this->_aTables
as $sTableName => $mixedCond)
202 $mixedCond = $this->_aTables[$sTableName];
204 $oStmt = $this->_oQuery->res($sQuery);
211 $oStmt = $this->_oQuery->res($sQuery);
217 if (is_string($mixedCond)) {
218 $sWhere = str_replace(
'{profile_id}',
$iProfileId, $mixedCond);
219 $sQuery =
"SELECT * FROM `$sTableName` WHERE $sWhere";
221 elseif (is_array($mixedCond) && isset($mixedCond[
'query'])) {
222 $sQuery = str_replace(
'{profile_id}',
$iProfileId, $mixedCond[
'query']);
229 return $this->_sFilesBaseDir . (is_string($sPrefix) ? $sPrefix :
'') . $sFileName .
$sExt;
234 if (!$oStmt->rowCount())
238 while ($r = $oStmt->fetch(PDO::FETCH_ASSOC)) {
239 if(is_a(
$aFields,
'ChWsbExportFiles'))
242 foreach (
$aFields as $sField => $aPrefix2Ext) {
243 foreach ($aPrefix2Ext
as $sPrefix =>
$sExt) {
244 $sPath = $this->
_getFilePath($sTableName, $sField, $r[$sField], $sPrefix,
$sExt);
245 if (file_exists($sPath))
256 if (!$oStmt->rowCount())
259 $s .=
"INSERT INTO `{$sTableName}` VALUES\n";
260 while ($r = $oStmt->fetch(PDO::FETCH_NUM)) {
262 for ($j = 0; $j < count($r); $j++ ) {
266 $s .= $this->_oQuery->escape($r[$j],
true) .
", ";
271 $s = trim(
$s,
",\n");
283 $this->_sBaseDir = $sBaseDir;