csvimport.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * CSV Import Page
  18. * Wizard to import CSV (or TSV) data into the database
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. try
  26. {
  27. ini_set('memory_limit', '256M');
  28. require_once('../approot.inc.php');
  29. require_once(APPROOT.'/application/application.inc.php');
  30. require_once(APPROOT.'/application/itopwebpage.class.inc.php');
  31. require_once(APPROOT.'/application/startup.inc.php');
  32. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  33. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  34. $iStep = utils::ReadParam('step', 1);
  35. $oPage = new iTopWebPage(Dict::S('UI:Title:BulkImport'));
  36. /**
  37. * Helper function to build a select from the list of valid classes for a given action
  38. * @param string $sName The name of the select in the HTML form
  39. * @param string $sDefaulfValue The defaut value (i.e the value selected by default)
  40. * @param integer $iWidthPx The width (in pixels) of the drop-down list
  41. * @param integer $iActionCode The ActionCode (from UserRights) to check for authorization for the classes
  42. * @return string The HTML fragment corresponding to the select tag
  43. */
  44. function GetClassesSelect($sName, $sDefaultValue, $iWidthPx, $iActionCode = null)
  45. {
  46. $sHtml = "<select id=\"select_$sName\" name=\"$sName\">";
  47. $sHtml .= "<option tyle=\"width: ".$iWidthPx."px;\" title=\"Select the class you want to load\" value=\"\">".Dict::S('UI:CSVImport:ClassesSelectOne')."</option>\n";
  48. $aValidClasses = array();
  49. $aClassCategories = array('bizmodel');
  50. if (UserRights::IsAdministrator())
  51. {
  52. $aClassCategories = array('bizmodel', 'application', 'addon/authentication');
  53. }
  54. foreach($aClassCategories as $sClassCategory)
  55. {
  56. foreach(MetaModel::GetClasses($sClassCategory) as $sClassName)
  57. {
  58. if ( (is_null($iActionCode) || UserRights::IsActionAllowed($sClassName, $iActionCode)) &&
  59. (!MetaModel::IsAbstract($sClassName)) )
  60. {
  61. $sSelected = ($sClassName == $sDefaultValue) ? " selected" : "";
  62. $sDescription = MetaModel::GetClassDescription($sClassName);
  63. $sDisplayName = MetaModel::GetName($sClassName);
  64. $aValidClasses[$sDisplayName] = "<option style=\"width: ".$iWidthPx."px;\" title=\"$sDescription\" value=\"$sClassName\"$sSelected>$sDisplayName</option>";
  65. }
  66. }
  67. }
  68. ksort($aValidClasses);
  69. $sHtml .= implode("\n", $aValidClasses);
  70. $sHtml .= "</select>";
  71. return $sHtml;
  72. }
  73. /**
  74. * Helper to 'check' an input in an HTML form if the current value equals the value given
  75. * @param mixed $sCurrentValue The current value to be chacked against the value of the input
  76. * @param mixed $sProposedValue The value of the input
  77. * @param bool $bInverseCondition Set to true to perform the reversed comparison
  78. * @return string Either ' checked' or an empty string
  79. */
  80. function IsChecked($sCurrentValue, $sProposedValue, $bInverseCondition = false)
  81. {
  82. $bCondition = ($sCurrentValue == $sProposedValue);
  83. return ($bCondition xor $bInverseCondition) ? ' checked' : '';
  84. }
  85. /**
  86. * Returns the number of occurences of each char from the set in the specified string
  87. * @param string $sString The input data
  88. * @param array $aSet The set of characters to count
  89. * @return hash 'char' => nb of occurences
  90. */
  91. function CountCharsFromSet($sString, $aSet)
  92. {
  93. $aResult = array();
  94. $aCount = count_chars($sString);
  95. foreach($aSet as $sChar)
  96. {
  97. $aResult[$sChar] = isset($aCount[ord($sChar)]) ? $aCount[ord($sChar)] : 0;
  98. }
  99. return $aResult;
  100. }
  101. /**
  102. * Return the most frequent (and regularly occuring) character among the given set, in the specified lines
  103. * @param array $aCSVData The input data, one entry per line
  104. * @param array $aPossibleSeparators The list of characters to count
  105. * @return string The most frequent character from the set
  106. */
  107. function GuessFromFrequency($aCSVData, $aPossibleSeparators)
  108. {
  109. $iLine = 0;
  110. $iMaxLine = 20; // Process max 20 lines to guess the parameters
  111. foreach($aPossibleSeparators as $sSep)
  112. {
  113. $aGuesses[$sSep]['total'] = $aGuesses[$sSep]['max'] = 0;
  114. $aGuesses[$sSep]['min'] = 999;
  115. }
  116. $aStats = array();
  117. while(($iLine < count($aCSVData)) && ($iLine < $iMaxLine) )
  118. {
  119. if (strlen($aCSVData[$iLine]) > 0)
  120. {
  121. $aStats[$iLine] = CountCharsFromSet($aCSVData[$iLine], $aPossibleSeparators);
  122. }
  123. $iLine++;
  124. }
  125. $iLine = 1;
  126. foreach($aStats as $aLineStats)
  127. {
  128. foreach($aPossibleSeparators as $sSep)
  129. {
  130. $aGuesses[$sSep]['total'] += $aLineStats[$sSep];
  131. if ($aLineStats[$sSep] > $aGuesses[$sSep]['max']) $aGuesses[$sSep]['max'] = $aLineStats[$sSep];
  132. if ($aLineStats[$sSep] < $aGuesses[$sSep]['min']) $aGuesses[$sSep]['min'] = $aLineStats[$sSep];
  133. }
  134. $iLine++;
  135. }
  136. $aScores = array();
  137. foreach($aGuesses as $sSep => $aData)
  138. {
  139. $aScores[$sSep] = $aData['total'] + $aData['max'] - $aData['min'];
  140. }
  141. arsort($aScores, SORT_NUMERIC); // Sort the array, higher scores first
  142. $aKeys = array_keys($aScores);
  143. $sSeparator = $aKeys[0]; // Take the first key, the one with the best score
  144. return $sSeparator;
  145. }
  146. /**
  147. * Try to predict the CSV parameters based on the input data
  148. * @param string $sCSVData The input data
  149. * @return hash 'separator' => the_guessed_separator, 'qualifier' => the_guessed_text_qualifier
  150. */
  151. function GuessParameters($sCSVData)
  152. {
  153. $aData = explode("\n", $sCSVData);
  154. $sSeparator = GuessFromFrequency($aData, array("\t", ',', ';', '|')); // Guess the most frequent (and regular) character on each line
  155. $sQualifier = GuessFromFrequency($aData, array('"', "'")); // Guess the most frequent (and regular) character on each line
  156. return array('separator' => $sSeparator, 'qualifier' => $sQualifier);
  157. }
  158. /**
  159. * Display a banner for the special "synchro" mode
  160. * @param WebPage $oP The Page for the output
  161. * @param string $sClass The class of objects to synchronize
  162. * @param integer $iCount The number of objects to synchronize
  163. * @return none
  164. */
  165. function DisplaySynchroBanner(WebPage $oP, $sClass, $iCount)
  166. {
  167. $oP->add("<div class=\"notification\"><p><h1>".MetaModel::GetClassIcon($sClass)."&nbsp;".Dict::Format('UI:Title:BulkSynchro_nbItem_ofClass_class', $iCount, MetaModel::GetName($sClass))."</h1></p></div>\n");
  168. }
  169. /**
  170. * Process the CSV data, for real or as a simulation
  171. * @param WebPage $oPage The page used to display the wizard
  172. * @param bool $bSimulate Whether or not to simulate the data load
  173. * @return array The CSV lines in error that were rejected from the load (with the header line - if any) or null
  174. */
  175. function ProcessCSVData(WebPage $oPage, $bSimulate = true)
  176. {
  177. $aResult = array();
  178. $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
  179. $sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data');
  180. $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
  181. $sTextQualifier = utils::ReadParam('text_qualifier', '"', false, 'raw_data');
  182. $bHeaderLine = (utils::ReadParam('header_line', '0') == 1);
  183. $iRealSkippedLines = $iSkippedLines = utils::ReadParam('nb_skipped_lines', '0');
  184. $sClassName = utils::ReadParam('class_name', '', false, 'class');
  185. $aFieldsMapping = utils::ReadParam('field', array(), false, 'raw_data');
  186. $aSearchFields = utils::ReadParam('search_field', array(), false, 'field_name');
  187. $iCurrentStep = $bSimulate ? 4 : 5;
  188. $bAdvanced = utils::ReadParam('advanced', 0);
  189. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  190. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  191. if (!empty($sSynchroScope))
  192. {
  193. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  194. $sClassName = $oSearch->GetClass(); // If a synchronization scope is set, then the class is fixed !
  195. $oSet = new DBObjectSet($oSearch);
  196. $iCount = $oSet->Count();
  197. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  198. $sClassesSelect = "<select id=\"select_class_name\" name=\"class_name\"><option value=\"$sClassName\" selected>".MetaModel::GetName($sClassName)."</option>";
  199. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  200. }
  201. else
  202. {
  203. $sSynchroScope = '';
  204. $aSynchroUpdate = null;
  205. }
  206. // Parse the data set
  207. $oCSVParser = new CSVParser($sCSVData, $sSeparator, $sTextQualifier);
  208. $aData = $oCSVParser->ToArray($iSkippedLines);
  209. if ($bHeaderLine)
  210. {
  211. $aResult[] = $sTextQualifier.implode($sTextQualifier.$sSeparator.$sTextQualifier, array_shift($aData)).$sTextQualifier; // Remove the first line and store it in case of error
  212. $iRealSkippedLines++;
  213. }
  214. // Format for the line numbers
  215. $sMaxLen = (strlen(''.count($aData)) < 3) ? 3 : strlen(''.count($aData)); // Pad line numbers to the appropriate number of chars, but at least 3
  216. // Compute the list of search/reconciliation criteria
  217. $aSearchKeys = array();
  218. foreach($aSearchFields as $index => $sDummy)
  219. {
  220. $sSearchField = $aFieldsMapping[$index];
  221. $aMatches = array();
  222. if (preg_match('/(.+)->(.+)/', $sSearchField, $aMatches) > 0)
  223. {
  224. $sSearchField = $aMatches[1];
  225. $aSearchKeys[$aMatches[1]] = '';
  226. }
  227. else
  228. {
  229. $aSearchKeys[$sSearchField] = '';
  230. }
  231. if (!MetaModel::IsValidFilterCode($sClassName, $sSearchField))
  232. {
  233. // Remove invalid or unmapped search fields
  234. $aSearchFields[$index] = null;
  235. unset($aSearchKeys[$sSearchField]);
  236. }
  237. }
  238. // Compute the list of fields and external keys to process
  239. $aExtKeys = array();
  240. $aAttributes = array();
  241. $aExternalKeysByColumn = array();
  242. foreach($aFieldsMapping as $iNumber => $sAttCode)
  243. {
  244. $iIndex = $iNumber-1;
  245. if (!empty($sAttCode) && ($sAttCode != ':none:') && ($sAttCode != 'finalclass'))
  246. {
  247. if (preg_match('/(.+)->(.+)/', $sAttCode, $aMatches) > 0)
  248. {
  249. $sAttribute = $aMatches[1];
  250. $sField = $aMatches[2];
  251. $aExtKeys[$sAttribute][$sField] = $iIndex;
  252. $aExternalKeysByColumn[$iIndex] = $sAttribute;
  253. }
  254. else
  255. {
  256. if ($sAttCode == 'id')
  257. {
  258. $aAttributes['id'] = $iIndex;
  259. }
  260. else
  261. {
  262. $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
  263. if ($oAttDef->IsExternalKey())
  264. {
  265. $aExtKeys[$sAttCode]['id'] = $iIndex;
  266. $aExternalKeysByColumn[$iIndex] = $sAttCode;
  267. }
  268. else
  269. {
  270. $aAttributes[$sAttCode] = $iIndex;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. $oMyChange = null;
  277. if (!$bSimulate)
  278. {
  279. // We're doing it for real, let's create a change
  280. $oMyChange = MetaModel::NewObject("CMDBChange");
  281. $oMyChange->Set("date", time());
  282. $sUserString = CMDBChange::GetCurrentUserName();
  283. $sUserString .= ' (CSV)';
  284. $oMyChange->Set("userinfo", $sUserString);
  285. $iChangeId = $oMyChange->DBInsert();
  286. }
  287. $oBulk = new BulkChange(
  288. $sClassName,
  289. $aData,
  290. $aAttributes,
  291. $aExtKeys,
  292. array_keys($aSearchKeys),
  293. empty($sSynchroScope) ? null : $sSynchroScope,
  294. $aSynchroUpdate
  295. );
  296. $oBulk->SetReportHtml();
  297. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  298. $aRes = $oBulk->Process($oMyChange);
  299. $sHtml = '<table id="bulk_preview" style="border-collapse: collapse;">';
  300. $sHtml .= '<tr><th style="padding:2px;border-right: 2px #fff solid;">Line</th>';
  301. $sHtml .= '<th style="padding:2px;border-right: 2px #fff solid;">Status</th>';
  302. $sHtml .= '<th style="padding:2px;border-right: 2px #fff solid;">Object</th>';
  303. foreach($aFieldsMapping as $iNumber => $sAttCode)
  304. {
  305. if (!empty($sAttCode) && ($sAttCode != ':none:') && ($sAttCode != 'finalclass'))
  306. {
  307. $sHtml .= "<th style=\"padding:2px;border-right: 2px #fff solid;\">".BulkChange::GetFriendlyAttCodeName($sClassName, $sAttCode)."</th>";
  308. }
  309. }
  310. $sHtml .= '<th>Message</th>';
  311. $sHtml .= '</tr>';
  312. $iErrors = 0;
  313. $iCreated = 0;
  314. $iModified = 0;
  315. $iUnchanged = 0;
  316. foreach($aRes as $iLine => $aResRow)
  317. {
  318. $oStatus = $aResRow['__STATUS__'];
  319. $sUrl = '';
  320. $sMessage = '';
  321. $sCSSRowClass = '';
  322. $sCSSMessageClass = 'cell_ok';
  323. switch(get_class($oStatus))
  324. {
  325. case 'RowStatus_NoChange':
  326. $iUnchanged++;
  327. $sFinalClass = $aResRow['finalclass'];
  328. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  329. $sUrl = $oObj->GetHyperlink();
  330. $sStatus = '<img src="../images/unchanged.png" title="Unchanged">';
  331. $sCSSRowClass = 'row_unchanged';
  332. break;
  333. case 'RowStatus_Modify':
  334. $iModified++;
  335. $sFinalClass = $aResRow['finalclass'];
  336. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  337. $sUrl = $oObj->GetHyperlink();
  338. $sStatus = '<img src="../images/modified.png" title="Modified">';
  339. $sCSSRowClass = 'row_modified';
  340. break;
  341. case 'RowStatus_Disappeared':
  342. $iModified++;
  343. $sFinalClass = $aResRow['finalclass'];
  344. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  345. $sUrl = $oObj->GetHyperlink();
  346. $sStatus = '<img src="../images/delete.png" title="Missing">';
  347. $sCSSRowClass = 'row_modified';
  348. if ($bSimulate)
  349. {
  350. $sMessage = 'Missing object: will be updated';
  351. }
  352. else
  353. {
  354. $sMessage = 'Missing object: updated';
  355. }
  356. break;
  357. case 'RowStatus_NewObj':
  358. $iCreated++;
  359. $sFinalClass = $aResRow['finalclass'];
  360. $sStatus = '<img src="../images/added.png" title="Created">';
  361. $sCSSRowClass = 'row_added';
  362. if ($bSimulate)
  363. {
  364. $sMessage = 'Object will be created';
  365. }
  366. else
  367. {
  368. $sFinalClass = $aResRow['finalclass'];
  369. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  370. $sUrl = $oObj->GetHyperlink();
  371. $sMessage = 'Object created';
  372. }
  373. break;
  374. case 'RowStatus_Issue':
  375. $iErrors++;
  376. $sMessage .= $oPage->GetP($oStatus->GetDescription());
  377. $sStatus = '<img src="../images/error.png" title="Error">';
  378. $sCSSMessageClass = 'cell_error';
  379. $sCSSRowClass = 'row_error';
  380. if (array_key_exists($iLine, $aData))
  381. {
  382. $aRow = $aData[$iLine];
  383. $aResult[] = $sTextQualifier.implode($sTextQualifier.$sSeparator.$sTextQualifier,$aRow).$sTextQualifier; // Remove the first line and store it in case of error
  384. }
  385. break;
  386. }
  387. $sHtml .= '<tr class="'.$sCSSRowClass.'">';
  388. $sHtml .= "<td style=\"background-color:#f1f1f1;border-right:2px #fff solid;\">".sprintf("%0{$sMaxLen}d", 1+$iLine+$iRealSkippedLines)."</td>";
  389. $sHtml .= "<td style=\"text-align:center;background-color:#f1f1f1;border-right:2px #fff solid;\">$sStatus</td>";
  390. $sHtml .= "<td style=\"text-align:center;background-color:#f1f1f1;\">$sUrl</td>";
  391. foreach($aFieldsMapping as $iNumber => $sAttCode)
  392. {
  393. if (!empty($sAttCode) && ($sAttCode != ':none:') && ($sAttCode != 'finalclass'))
  394. {
  395. $oCellStatus = $aResRow[$iNumber -1];
  396. $sCellMessage = '';
  397. if (isset($aExternalKeysByColumn[$iNumber -1]))
  398. {
  399. $sExtKeyName = $aExternalKeysByColumn[$iNumber -1];
  400. $oExtKeyCellStatus = $aResRow[$sExtKeyName];
  401. switch(get_class($oExtKeyCellStatus))
  402. {
  403. case 'CellStatus_Issue':
  404. case 'CellStatus_SearchIssue':
  405. case 'CellStatus_NullIssue':
  406. $sCellMessage .= $oPage->GetP($oExtKeyCellStatus->GetDescription());
  407. break;
  408. case 'CellStatus_Ambiguous':
  409. $sCellMessage .= $oPage->GetP($oExtKeyCellStatus->GetDescription());
  410. break;
  411. default:
  412. // Do nothing
  413. }
  414. }
  415. $sHtmlValue = $oCellStatus->GetDisplayableValue();
  416. switch(get_class($oCellStatus))
  417. {
  418. case 'CellStatus_Issue':
  419. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  420. $sHtml .= '<td class="cell_error" style="border-right:1px #eee solid;">ERROR: '.$sHtmlValue.$sCellMessage.'</td>';
  421. break;
  422. case 'CellStatus_SearchIssue':
  423. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  424. $sHtml .= '<td class="cell_error">ERROR: '.$sHtmlValue.$sCellMessage.'</td>';
  425. break;
  426. case 'CellStatus_Ambiguous':
  427. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  428. $sHtml .= '<td class="cell_error" style="border-right:1px #eee solid;">AMBIGUOUS: '.$sHtmlValue.$sCellMessage.'</td>';
  429. break;
  430. case 'CellStatus_Modify':
  431. $sHtml .= '<td class="cell_modified" style="border-right:1px #eee solid;"><b>'.$sHtmlValue.'</b></td>';
  432. break;
  433. default:
  434. $sHtml .= '<td class="cell_ok" style="border-right:1px #eee solid;">'.$sHtmlValue.$sCellMessage.'</td>';
  435. }
  436. }
  437. }
  438. $sHtml .= "<td class=\"$sCSSMessageClass\" style=\"background-color:#f1f1f1;\">$sMessage</td>";
  439. $sHtml .= '</tr>';
  440. }
  441. $iUnchanged = count($aRes) - $iErrors - $iModified - $iCreated;
  442. $sHtml .= '</table>';
  443. $oPage->add('<div class="wizContainer" style="width:auto;display:inline-block;">');
  444. $oPage->add('<form enctype="multipart/form-data" id="wizForm" method="post">');
  445. $oPage->add('<input type="hidden" name="step" value="'.($iCurrentStep+1).'"/>');
  446. $oPage->add('<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>');
  447. $oPage->add('<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>');
  448. $oPage->add('<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>');
  449. $oPage->add('<input type="hidden" name="box_skiplines" value="'.(($iSkippedLines > 0) ? 1 : 0).'"/>');
  450. $oPage->add('<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>');
  451. $oPage->add('<input type="hidden" name="csvdata" value="'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'"/>');
  452. $oPage->add('<input type="hidden" name="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  453. $oPage->add('<input type="hidden" name="class_name" value="'.$sClassName.'"/>');
  454. $oPage->add('<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>');
  455. $oPage->add('<input type="hidden" name="encoding" value="'.$sEncoding.'"/>');
  456. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>');
  457. if (!empty($sSynchroScope))
  458. {
  459. foreach($aSynchroUpdate as $sKey => $value)
  460. {
  461. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  462. }
  463. }
  464. foreach($aFieldsMapping as $iNumber => $sAttCode)
  465. {
  466. $oPage->add('<input type="hidden" name="field['.$iNumber.']" value="'.$sAttCode.'"/>');
  467. }
  468. foreach($aSearchFields as $index => $sDummy)
  469. {
  470. $oPage->add('<input type="hidden" name="search_field['.$index.']" value="1"/>');
  471. }
  472. $aDisplayFilters = array();
  473. if ($bSimulate)
  474. {
  475. $aDisplayFilters['unchanged'] = Dict::S('UI:CSVImport:ObjectsWillStayUnchanged');
  476. $aDisplayFilters['modified'] = Dict::S('UI:CSVImport:ObjectsWillBeModified');
  477. $aDisplayFilters['added'] = Dict::S('UI:CSVImport:ObjectsWillBeAdded');
  478. $aDisplayFilters['errors'] = Dict::S('UI:CSVImport:ObjectsWillHaveErrors');
  479. }
  480. else
  481. {
  482. $aDisplayFilters['unchanged'] = Dict::S('UI:CSVImport:ObjectsRemainedUnchanged');
  483. $aDisplayFilters['modified'] = Dict::S('UI:CSVImport:ObjectsWereModified');
  484. $aDisplayFilters['added'] = Dict::S('UI:CSVImport:ObjectsWereAdded');
  485. $aDisplayFilters['errors'] = Dict::S('UI:CSVImport:ObjectsHadErrors');
  486. }
  487. $oPage->add('<p><input type="checkbox" checked id="show_unchanged" onClick="ToggleRows(\'row_unchanged\')"/>&nbsp;<img src="../images/unchanged.png">&nbsp;'.sprintf($aDisplayFilters['unchanged'], $iUnchanged).'&nbsp&nbsp;');
  488. $oPage->add('<input type="checkbox" checked id="show_modified" onClick="ToggleRows(\'row_modified\')"/>&nbsp;<img src="../images/modified.png">&nbsp;'.sprintf($aDisplayFilters['modified'], $iModified).'&nbsp&nbsp;');
  489. $oPage->add('<input type="checkbox" checked id="show_created" onClick="ToggleRows(\'row_added\')"/>&nbsp;<img src="../images/added.png">&nbsp;'.sprintf($aDisplayFilters['added'], $iCreated).'&nbsp&nbsp;');
  490. $oPage->add('<input type="checkbox" checked id="show_errors" onClick="ToggleRows(\'row_error\')"/>&nbsp;<img src="../images/error.png">&nbsp;'.sprintf($aDisplayFilters['errors'], $iErrors).'</p>');
  491. $oPage->add('<div class="white" style="display:inline-block">');
  492. $oPage->add($sHtml);
  493. $oPage->add('</div> <!-- end of preview -->');
  494. $oPage->add('<p>');
  495. if($bSimulate)
  496. {
  497. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Restart').'" onClick="CSVRestart()"/>&nbsp;&nbsp;');
  498. }
  499. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="CSVGoBack()"/>&nbsp;&nbsp;');
  500. $bShouldConfirm = false;
  501. if ($bSimulate)
  502. {
  503. // if there are *too many* changes, we should ask the user for a confirmation
  504. if (count($aRes) >= MetaModel::GetConfig()->Get('csv_import_min_object_confirmation'))
  505. {
  506. $fErrorsPercentage = (100.0*$iErrors)/count($aRes);
  507. if ($fErrorsPercentage >= MetaModel::GetConfig()->Get('csv_import_errors_percentage'))
  508. {
  509. $sMessage = sprintf("%.0f %% of the loaded objects have errors and will be ignored.", $fErrorsPercentage);
  510. $bShouldConfirm = true;
  511. }
  512. $fCreatedPercentage = (100.0*$iCreated)/count($aRes);
  513. if ($fCreatedPercentage >= MetaModel::GetConfig()->Get('csv_import_creations_percentage'))
  514. {
  515. $sMessage = sprintf("%.0f %% of the loaded objects will be created.", $fCreatedPercentage);
  516. $bShouldConfirm = true;
  517. }
  518. $fModifiedPercentage = (100.0*$iModified)/count($aRes);
  519. if ($fModifiedPercentage >= MetaModel::GetConfig()->Get('csv_import_modifications_percentage'))
  520. {
  521. $sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fModifiedPercentage);
  522. $bShouldConfirm = true;
  523. }
  524. }
  525. $iCount = count($aRes);
  526. //$oPage->add('<input type="submit" value="'.Dict::S('UI:Button:DoImport').'" onClick="$(\'#wizForm\').block();"/></p>');
  527. $sConfirm = $bShouldConfirm ? 'true' : 'false';
  528. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:DoImport')."\" onClick=\"return DoSubmit($sConfirm);\"/></p>");
  529. }
  530. else
  531. {
  532. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:Done').'"/></p>');
  533. }
  534. $oPage->add('</form>');
  535. $oPage->add('</div> <!-- end of wizForm -->');
  536. if ($bShouldConfirm)
  537. {
  538. $oPage->add('<div id="dlg_confirmation" title="Please confirm the operation">');
  539. $oPage->add('<p style="text-align:center"><b>'.$sMessage.'</b></p>');
  540. $oPage->add('<p style="text-align:center">Are you sure you want to do this ?</p>');
  541. $oPage->add('<div id="confirmation_chart"></div>');
  542. $oPage->add('</div> <!-- end of dlg_confirmation -->');
  543. $oPage->add_ready_script(
  544. <<<EOF
  545. $('#dlg_confirmation').dialog(
  546. {
  547. height: 'auto',
  548. width: 500,
  549. modal:true,
  550. autoOpen: false,
  551. buttons:
  552. {
  553. 'Yes': RunImport,
  554. 'No': CancelImport
  555. }
  556. });
  557. swfobject.embedSWF( "../images/open-flash-chart.swf",
  558. "confirmation_chart",
  559. "100%", "300","9.0.0",
  560. "expressInstall.swf",
  561. {},
  562. {'wmode': 'transparent'}
  563. );
  564. EOF
  565. );
  566. }
  567. $oPage->add_script(
  568. <<< EOF
  569. function CSVGoBack()
  570. {
  571. $('input[name=step]').val($iCurrentStep-1);
  572. $('#wizForm').submit();
  573. }
  574. function CSVRestart()
  575. {
  576. $('input[name=step]').val(1);
  577. $('#wizForm').submit();
  578. }
  579. function ToggleRows(sCSSClass)
  580. {
  581. $('.'+sCSSClass).toggle();
  582. }
  583. function DoSubmit(bConfirm)
  584. {
  585. if (bConfirm) //Ask for a confirmation
  586. {
  587. $('#dlg_confirmation').dialog('open');
  588. }
  589. else
  590. {
  591. // Submit the form
  592. $('#wizForm').block();
  593. $('#wizForm').submit();
  594. }
  595. return false;
  596. }
  597. function CancelImport()
  598. {
  599. $('#dlg_confirmation').dialog('close');
  600. }
  601. function RunImport()
  602. {
  603. $('#dlg_confirmation').dialog('close');
  604. // Submit the form
  605. $('#wizForm').block();
  606. $('#wizForm').submit();
  607. }
  608. function open_flash_chart_data()
  609. {
  610. var iErrors = $iErrors;
  611. var iModified = $iModified;
  612. var iCreated = $iCreated;
  613. var iUnchanged = $iUnchanged;
  614. var fAlpha = 0.9;
  615. var oResult = {
  616. "elements": [
  617. {
  618. "type": "pie",
  619. "tip": "#label# (#percent#)",
  620. "gradient-fill": true,
  621. "font-size": 14,
  622. "colours":[],
  623. "values": [],
  624. "animate":[
  625. {
  626. "type": "fade"
  627. }
  628. ]
  629. }
  630. ],
  631. "x_axis": null,
  632. "font-size": 14,
  633. "bg_colour": "#EEEEEE"
  634. };
  635. if (iErrors > 0)
  636. {
  637. var oErrors =
  638. {
  639. "value": iErrors,
  640. "label": "Errors: "+iErrors,
  641. "alpha": fAlpha,
  642. "label-colour": "#CC3333",
  643. };
  644. oResult.elements[0].values.push(oErrors);
  645. oResult.elements[0].colours.push('#FF6666');
  646. }
  647. if (iModified > 0)
  648. {
  649. var oModified =
  650. {
  651. "value": iModified,
  652. "label": "Modified: "+iModified,
  653. "alpha": fAlpha,
  654. "label-colour": "#3333CC",
  655. };
  656. oResult.elements[0].values.push(oModified);
  657. oResult.elements[0].colours.push('#6666FF');
  658. }
  659. if (iCreated > 0)
  660. {
  661. var oCreated =
  662. {
  663. "value": iCreated,
  664. "label": "Created: "+iCreated,
  665. "alpha": fAlpha,
  666. "label-colour": "#33CC33",
  667. };
  668. oResult.elements[0].values.push(oCreated);
  669. oResult.elements[0].colours.push('#66FF66');
  670. }
  671. if (iUnchanged > 0)
  672. {
  673. var oUnchanged =
  674. {
  675. "value": iUnchanged,
  676. "label": "Unchanged: "+iUnchanged,
  677. "alpha": fAlpha,
  678. "label-colour": "#333333",
  679. };
  680. oResult.elements[0].values.push(oUnchanged);
  681. oResult.elements[0].colours.push('#666666');
  682. }
  683. return JSON.stringify(oResult);
  684. }
  685. EOF
  686. );
  687. if ($iErrors > 0)
  688. {
  689. return $aResult;
  690. }
  691. else
  692. {
  693. return null;
  694. }
  695. }
  696. /**
  697. * Perform the actual load of the CSV data and display the results
  698. * @param WebPage $oPage The web page to display the wizard
  699. * @return void
  700. */
  701. function LoadData(WebPage $oPage)
  702. {
  703. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep5').'</h2>');
  704. $aResult = ProcessCSVData($oPage, false /* simulate = false */);
  705. if (is_array($aResult))
  706. {
  707. $oPage->StartCollapsibleSection(Dict::S('UI:CSVImport:LinesNotImported'), false);
  708. $oPage->p(Dict::S('UI:CSVImport:LinesNotImported+'));
  709. $oPage->add('<textarea rows="30" cols="100">');
  710. $oPage->add(htmlentities(implode("\n", $aResult), ENT_QUOTES, 'UTF-8'));
  711. $oPage->add('</textarea>');
  712. $oPage->EndCollapsibleSection();
  713. }
  714. }
  715. /**
  716. * Simulate the load of the CSV data and display the results
  717. * @param WebPage $oPage The web page to display the wizard
  718. * @return void
  719. */
  720. function Preview(WebPage $oPage)
  721. {
  722. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep4').'</h2>');
  723. ProcessCSVData($oPage, true /* simulate */);
  724. }
  725. /**
  726. * Select the mapping between the CSV column and the fields of the objects
  727. * @param WebPage $oPage The web page to display the wizard
  728. * @return void
  729. */
  730. function SelectMapping(WebPage $oPage)
  731. {
  732. $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
  733. $sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data');
  734. $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
  735. if ($sSeparator == 'tab') $sSeparator = "\t";
  736. if ($sSeparator == 'other')
  737. {
  738. $sSeparator = utils::ReadParam('other_separator', ',', false, 'raw_data');
  739. }
  740. $sTextQualifier = utils::ReadParam('text_qualifier', '"', false, 'raw_data');
  741. if ($sTextQualifier == 'other')
  742. {
  743. $sTextQualifier = utils::ReadParam('other_qualifier', '"', false, 'raw_data');
  744. }
  745. $bHeaderLine = (utils::ReadParam('header_line', '0') == 1);
  746. $iSkippedLines = 0;
  747. if (utils::ReadParam('box_skiplines', '0') == 1)
  748. {
  749. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '0');
  750. }
  751. $sClassName = utils::ReadParam('class_name', '', false, 'class');
  752. $bAdvanced = utils::ReadParam('advanced', 0);
  753. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  754. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  755. if (!empty($sSynchroScope))
  756. {
  757. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  758. $sClassName = $oSearch->GetClass(); // If a synchronization scope is set, then the class is fixed !
  759. $oSet = new DBObjectSet($oSearch);
  760. $iCount = $oSet->Count();
  761. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  762. $sClassesSelect = "<select id=\"select_class_name\" name=\"class_name\"><option value=\"$sClassName\" selected>".MetaModel::GetName($sClassName)."</option>";
  763. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  764. }
  765. else
  766. {
  767. $sClassesSelect = GetClassesSelect('class_name', $sClassName, 300, UR_ACTION_BULK_MODIFY);
  768. }
  769. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep3').'</h2>');
  770. $oPage->add('<div class="wizContainer">');
  771. $oPage->add('<form enctype="multipart/form-data" id="wizForm" method="post" onSubmit="return CheckValues()"><table style="width:100%" class="transparent"><tr><td>'.Dict::S('UI:CSVImport:SelectClass').' ');
  772. $oPage->add($sClassesSelect);
  773. $oPage->add('</td><td style="text-align:right"><input type="checkbox" name="advanced" value="1" '.IsChecked($bAdvanced, 1).' onClick="DoMapping()">&nbsp;'.Dict::S('UI:CSVImport:AdvancedMode').'</td></tr></table>');
  774. $oPage->add('<div style="padding:1em;display:none" id="advanced_help" style="display:none">'.Dict::S('UI:CSVImport:AdvancedMode+').'</div>');
  775. $oPage->add('<div id="mapping" class="white"><p style="text-align:center;width:100%;font-size:1.5em;padding:1em;">'.Dict::S('UI:CSVImport:SelectAClassFirst').'<br/></p></div>');
  776. $oPage->add('<input type="hidden" name="step" value="4"/>');
  777. $oPage->add('<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>');
  778. $oPage->add('<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>');
  779. $oPage->add('<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>');
  780. $oPage->add('<input type="hidden" name="box_skiplines" value="'.(($iSkippedLines > 0) ? 1 : 0).'"/>');
  781. $oPage->add('<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>');
  782. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  783. $oPage->add('<input type="hidden" name="csvdata" value="'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'"/>');
  784. $oPage->add('<input type="hidden" name="encoding" value="'.$sEncoding.'">');
  785. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'">');
  786. if (!empty($sSynchroScope))
  787. {
  788. foreach($aSynchroUpdate as $sKey => $value)
  789. {
  790. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  791. }
  792. }
  793. $oPage->add('<p><input type="button" value="'.Dict::S('UI:Button:Restart').'" onClick="CSVRestart()"/>&nbsp;&nbsp;');
  794. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="CSVGoBack()"/>&nbsp;&nbsp;');
  795. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:SimulateImport').'"/></p>');
  796. $oPage->add('</form>');
  797. $oPage->add('</div>');
  798. $sAlertIncompleteMapping = Dict::S('UI:CSVImport:AlertIncompleteMapping');
  799. $sAlertNoSearchCriteria = Dict::S('UI:CSVImport:AlertNoSearchCriteria');
  800. $oPage->add_ready_script(
  801. <<<EOF
  802. $('#select_class_name').change( DoMapping );
  803. EOF
  804. );
  805. if ($sClassName != '')
  806. {
  807. $oPage->add_ready_script("DoMapping();"); // There is already a class selected, run the mapping
  808. }
  809. $oPage->add_script(
  810. <<<EOF
  811. var aDefaultKeys = new Array();
  812. function CSVGoBack()
  813. {
  814. $('input[name=step]').val(2);
  815. $('#wizForm').removeAttr('onsubmit'); // No need to perform validation checks when going back
  816. $('#wizForm').submit();
  817. }
  818. function CSVRestart()
  819. {
  820. $('input[name=step]').val(1);
  821. $('#wizForm').removeAttr('onsubmit'); // No need to perform validation checks when going back
  822. $('#wizForm').submit();
  823. }
  824. var ajax_request = null;
  825. function DoMapping()
  826. {
  827. var class_name = $('select[name=class_name]').val();
  828. var advanced = $('input[name=advanced]:checked').val();
  829. if (advanced != 1)
  830. {
  831. $('#advanced_help').hide();
  832. }
  833. else
  834. {
  835. $('#advanced_help').show();
  836. }
  837. if (class_name != '')
  838. {
  839. var separator = $('input[name=separator]').val();
  840. var text_qualifier = $('input[name=text_qualifier]').val();
  841. var header_line = $('input[name=header_line]').val();
  842. var nb_lines_skipped = $('input[name=nb_skipped_lines]').val();
  843. var csv_data = $('input[name=csvdata]').val();
  844. var encoding = $('input[name=encoding]').val();
  845. if (advanced != 1)
  846. {
  847. advanced = 0;
  848. }
  849. $('#mapping').block();
  850. // Make sure that we cancel any pending request before issuing another
  851. // since responses may arrive in arbitrary order
  852. if (ajax_request != null)
  853. {
  854. ajax_request.abort();
  855. ajax_request = null;
  856. }
  857. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  858. { operation: 'display_mapping_form', enctype: 'multipart/form-data', csvdata: csv_data, separator: separator,
  859. qualifier: text_qualifier, nb_lines_skipped: nb_lines_skipped, header_line: header_line, class_name: class_name,
  860. advanced: advanced, encoding: encoding },
  861. function(data) {
  862. $('#mapping').empty();
  863. $('#mapping').append(data);
  864. $('#mapping').unblock();
  865. }
  866. );
  867. }
  868. }
  869. function CheckValues()
  870. {
  871. bResult = true;
  872. bMappingOk = true;
  873. bSearchOk = false;
  874. $('select[name^=field]').each( function() {
  875. if ($(this).val() == '')
  876. {
  877. $(this).parent().css({'border': '2px #D81515 solid'});
  878. bMappingOk = false;
  879. bResult = false;
  880. }
  881. else
  882. {
  883. $(this).parent().css({'border': '0'});
  884. }
  885. });
  886. // At least one search field must be checked
  887. $('input[name^=search]:checked').each( function() {
  888. bSearchOk = true;
  889. });
  890. if (!bMappingOk)
  891. {
  892. alert("$sAlertIncompleteMapping");
  893. }
  894. if (!bSearchOk)
  895. {
  896. bResult = false;
  897. alert("$sAlertNoSearchCriteria");
  898. }
  899. if (bResult)
  900. {
  901. $('#mapping').block();
  902. // Re-enable all search_xxx checkboxes so that their value gets posted
  903. $('input[name^=search]').each(function() {
  904. $(this).attr('disabled', false);
  905. });
  906. }
  907. return bResult;
  908. }
  909. function DoCheckMapping()
  910. {
  911. // Check if there is a field mapped to 'id'
  912. // In which case, it's the only possible search key
  913. var idSelected = 0;
  914. var nbSearchKeys = $('input[name^=search]:checked').length;
  915. var nbMappings = $('select[name^=field]').length;
  916. for(index=1; index <= nbMappings; index++)
  917. {
  918. var selectedValue = $('#mapping_'+index).val();
  919. if (selectedValue == 'id')
  920. {
  921. idSelected = index;
  922. }
  923. }
  924. for (index=1; index <= nbMappings; index++)
  925. {
  926. sMappingValue = $('#mapping_'+index).val();
  927. if ((sMappingValue == '') || (sMappingValue == ':none:'))
  928. {
  929. // Non-mapped field, uncheck and disabled
  930. $('#search_'+index).attr('checked', false);
  931. $('#search_'+index).attr('disabled', true);
  932. }
  933. else if (index == idSelected)
  934. {
  935. // The 'id' field was mapped, it's the only possible reconciliation key
  936. $('#search_'+index).attr('checked', true);
  937. $('#search_'+index).attr('disabled', true);
  938. }
  939. else
  940. {
  941. if (idSelected > 0)
  942. {
  943. // The 'id' field was mapped, it's the only possible reconciliation key
  944. $('#search_'+index).attr('checked', false);
  945. $('#search_'+index).attr('disabled', true);
  946. }
  947. else
  948. {
  949. $('#search_'+index).attr('disabled', false);
  950. if (nbSearchKeys == 0)
  951. {
  952. // No search key was selected, select the default ones
  953. for(j =0; j < aDefaultKeys.length; j++)
  954. {
  955. if (sMappingValue == aDefaultKeys[j])
  956. {
  957. $('#search_'+index).attr('checked', true);
  958. }
  959. }
  960. }
  961. }
  962. }
  963. }
  964. }
  965. EOF
  966. );
  967. }
  968. /**
  969. * Select the options of the CSV load and check for CSV parsing errors
  970. * @param WebPage $oPage The current web page
  971. * @return void
  972. */
  973. function SelectOptions(WebPage $oPage)
  974. {
  975. $sOperation = utils::ReadParam('operation', 'csv_data');
  976. $sCSVData = '';
  977. switch($sOperation)
  978. {
  979. case 'file_upload':
  980. $oDocument = utils::ReadPostedDocument('csvdata');
  981. if (!$oDocument->IsEmpty())
  982. {
  983. $sCSVData = $oDocument->GetData();
  984. }
  985. break;
  986. default:
  987. $sCSVData = utils::ReadPostedParam('csvdata', '', 'raw_data');
  988. }
  989. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  990. // Compute a subset of the data set, now that we know the charset
  991. if ($sEncoding == 'UTF-8')
  992. {
  993. $sUTF8Data = iconv('UTF-8', 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  994. }
  995. else
  996. {
  997. $sUTF8Data = iconv($sEncoding, 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  998. }
  999. $aGuesses = GuessParameters($sUTF8Data); // Try to predict the parameters, based on the input data
  1000. $sSeparator = utils::ReadParam('separator', '', false, 'raw_data');
  1001. if ($sSeparator == '') // May be set to an empty value by the previous page
  1002. {
  1003. $sSeparator = $aGuesses['separator'];
  1004. }
  1005. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '');
  1006. $bBoxSkipLines = utils::ReadParam('box_skiplines', 0);
  1007. if ($sSeparator == 'tab') $sSeparator = "\t";
  1008. $sOtherSeparator = in_array($sSeparator, array(',', ';', "\t")) ? '' : $sSeparator;
  1009. $sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data');
  1010. if ($sTextQualifier == '') // May be set to an empty value by the previous page
  1011. {
  1012. $sTextQualifier = $aGuesses['qualifier'];
  1013. }
  1014. $sOtherTextQualifier = in_array($sTextQualifier, array('"', "'")) ? '' : $sTextQualifier;
  1015. $bHeaderLine = utils::ReadParam('header_line', 0);
  1016. $sClassName = utils::ReadParam('class_name', '', false, 'class');
  1017. $bAdvanced = utils::ReadParam('advanced', 0);
  1018. // Create a truncated version of the data used for the fast preview
  1019. // Take about 20 lines of data... knowing that some lines may contain carriage returns
  1020. $iMaxLen = strlen($sUTF8Data);
  1021. if ($iMaxLen > 0)
  1022. {
  1023. $iMaxLines = 20;
  1024. $iCurPos = true;
  1025. while ( ($iCurPos > 0) && ($iMaxLines > 0))
  1026. {
  1027. $pos = strpos($sUTF8Data, "\n", $iCurPos);
  1028. if ($pos !== false)
  1029. {
  1030. $iCurPos = 1+$pos;
  1031. }
  1032. else
  1033. {
  1034. $iCurPos = strlen($sUTF8Data);
  1035. $iMaxLines = 1;
  1036. }
  1037. $iMaxLines--;
  1038. }
  1039. $sCSVDataTruncated = substr($sUTF8Data, 0, $iCurPos);
  1040. }
  1041. else
  1042. {
  1043. $sCSVDataTruncated = '';
  1044. }
  1045. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  1046. if (!empty($sSynchroScope))
  1047. {
  1048. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  1049. $sClassName = $oSearch->GetClass();
  1050. $oSet = new DBObjectSet($oSearch);
  1051. $iCount = $oSet->Count();
  1052. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  1053. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  1054. }
  1055. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep2').'</h2>');
  1056. $oPage->add('<div class="wizContainer">');
  1057. $oPage->add('<table><tr><td style="vertical-align:top;padding-right:50px;">');
  1058. $oPage->add('<form enctype="multipart/form-data" id="wizForm" method="post" id="csv_options">');
  1059. $oPage->add('<h3>'.Dict::S('UI:CSVImport:SeparatorCharacter').'</h3>');
  1060. $oPage->add('<p><input type="radio" name="separator" value="," onClick="DoPreview()"'.IsChecked($sSeparator, ',').'/> '.Dict::S('UI:CSVImport:SeparatorComma+').'<br/>');
  1061. $oPage->add('<input type="radio" name="separator" value=";" onClick="DoPreview()"'.IsChecked($sSeparator, ';').'/> '.Dict::S('UI:CSVImport:SeparatorSemicolon+').'<br/>');
  1062. $oPage->add('<input type="radio" name="separator" value="tab" onClick="DoPreview()"'.IsChecked($sSeparator, "\t").'/> '.Dict::S('UI:CSVImport:SeparatorTab+').'<br/>');
  1063. $oPage->add('<input type="radio" name="separator" value="other" onClick="DoPreview()"'.IsChecked($sOtherSeparator, '', true).'/> '.Dict::S('UI:CSVImport:SeparatorOther').' <input type="text" size="3" maxlength="1" name="other_separator" id="other_separator" value="'.$sOtherSeparator.'" onClick="DoPreview()"/>');
  1064. $oPage->add('</p>');
  1065. $oPage->add('</td><td style="vertical-align:top;padding-right:50px;">');
  1066. $oPage->add('<h3>'.Dict::S('UI:CSVImport:TextQualifierCharacter').'</h3>');
  1067. $oPage->add('<p><input type="radio" name="text_qualifier" value="&#34;" onClick="DoPreview()"'.IsChecked($sTextQualifier, '"').'/> '.Dict::S('UI:CSVImport:QualifierDoubleQuote+').'<br/>');
  1068. $oPage->add('<input type="radio" name="text_qualifier" value="&#39;" onClick="DoPreview()"'.IsChecked($sTextQualifier, "'").'/> '.Dict::S('UI:CSVImport:QualifierSimpleQuote+').'<br/>');
  1069. $oPage->add('<input type="radio" name="text_qualifier" value="other" onClick="DoPreview()"'.IsChecked($sOtherTextQualifier, '', true).'/> '.Dict::S('UI:CSVImport:QualifierOther').' <input type="text" size="3" maxlength="1" name="other_qualifier" value="'.htmlentities($sOtherTextQualifier, ENT_QUOTES, 'UTF-8').'" onChange="DoPreview()"/>');
  1070. $oPage->add('</p>');
  1071. $oPage->add('</td><td style="vertical-align:top;">');
  1072. $oPage->add('<h3>'.Dict::S('UI:CSVImport:CommentsAndHeader').'</h3>');
  1073. $oPage->add('<p><input type="checkbox" name="header_line" id="box_header" value="1" onClick="DoPreview()"'.IsChecked($bHeaderLine, 1).'/> '.Dict::S('UI:CSVImport:TreatFirstLineAsHeader').'<p>');
  1074. $oPage->add('<p><input type="checkbox" name="box_skiplines" value="1" id="box_skiplines" onClick="DoPreview()"'.IsChecked($bBoxSkipLines, 1).'/> '.Dict::Format('UI:CSVImport:Skip_N_LinesAtTheBeginning', '<input type="text" size=2 name="nb_skipped_lines" id="nb_skipped_lines" onChange="DoPreview()" value="'.$iSkippedLines.'">').'<p>');
  1075. $oPage->add('</td></tr></table>');
  1076. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  1077. $oPage->add('<input type="hidden" name="csvdata" id="csvdata" value="'.htmlentities($sUTF8Data, ENT_QUOTES, 'UTF-8').'"/>');
  1078. $oPage->add('<input type="hidden" name="class_name" value="'.$sClassName.'"/>');
  1079. $oPage->add('<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>');
  1080. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>');
  1081. $oPage->add('<input type="hidden" name="step" value="3"/>');
  1082. if (!empty($sSynchroScope))
  1083. {
  1084. foreach($aSynchroUpdate as $sKey => $value)
  1085. {
  1086. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  1087. }
  1088. }
  1089. $oPage->add('<div id="preview">');
  1090. $oPage->add('<p style="text-align:center">'.Dict::S('UI:CSVImport:CSVDataPreview').'</p>');
  1091. $oPage->add('</div>');
  1092. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="GoBack()"/>');
  1093. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:Next').'"/>');
  1094. $oPage->add('</form>');
  1095. $oPage->add('</div>');
  1096. $oPage->add_script(
  1097. <<<EOF
  1098. function GoBack()
  1099. {
  1100. $('input[name=step]').val(1);
  1101. $('#wizForm').submit();
  1102. }
  1103. var ajax_request = null;
  1104. function DoPreview()
  1105. {
  1106. var separator = $('input[name=separator]:checked').val();
  1107. if (separator == 'other')
  1108. {
  1109. separator = $('#other_separator').val();
  1110. }
  1111. var text_qualifier = $('input[name=text_qualifier]:checked').val();
  1112. if (text_qualifier == 'other')
  1113. {
  1114. text_qualifier = $('#other_qualifier').val();
  1115. }
  1116. var nb_lines_skipped = 0;
  1117. if ($('#box_skiplines:checked').val() != null)
  1118. {
  1119. nb_lines_skipped = $('#nb_skipped_lines').val();
  1120. }
  1121. var header_line = 0;
  1122. if ($('#box_header:checked').val() != null)
  1123. {
  1124. header_line = 1;
  1125. }
  1126. var encoding = $('input[name=encoding]').val();
  1127. $('#preview').block();
  1128. // Make sure that we cancel any pending request before issuing another
  1129. // since responses may arrive in arbitrary order
  1130. if (ajax_request != null)
  1131. {
  1132. ajax_request.abort();
  1133. ajax_request = null;
  1134. }
  1135. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  1136. { operation: 'parser_preview', enctype: 'multipart/form-data', csvdata: $("#csvdata_truncated").val(), separator: separator, qualifier: text_qualifier, nb_lines_skipped: nb_lines_skipped, header_line: header_line, encoding: encoding },
  1137. function(data) {
  1138. $('#preview').empty();
  1139. $('#preview').append(data);
  1140. $('#preview').unblock();
  1141. }
  1142. );
  1143. }
  1144. EOF
  1145. );
  1146. $oPage->add_ready_script('DoPreview();');
  1147. }
  1148. /**
  1149. * Prompt for the data to be loaded (either via a file or a copy/paste)
  1150. * @param WebPage $oPage The current web page
  1151. * @return void
  1152. */
  1153. function Welcome(iTopWebPage $oPage)
  1154. {
  1155. // Encodings supported:
  1156. // ICONV_CODE => Display Name
  1157. // Each iconv installation supports different encodings
  1158. // Some reasonably common and useful encodnings are listed here
  1159. $aPossibleEncodings = array(
  1160. 'UTF-8' => 'Unicode (UTF-8)',
  1161. 'ISO-8859-1' => 'Western (ISO-8859-1)',
  1162. 'WINDOWS-1251' => 'Cyrilic (Windows 1251)',
  1163. 'WINDOWS-1252' => 'Western (Windows 1252)',
  1164. 'ISO-8859-15' => 'Western (ISO-8859-15)',
  1165. );
  1166. // Some more encodings can be specified in the config file
  1167. $aExtraCharsets = MetaModel::GetConfig()->GetCSVImportCharsets();
  1168. $aPossibleEncodings = array_merge($aPossibleEncodings, $aExtraCharsets);
  1169. asort($aPossibleEncodings);
  1170. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  1171. if (!empty($sSynchroScope))
  1172. {
  1173. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  1174. $sClassName = $oSearch->GetClass();
  1175. $oSet = new DBObjectSet($oSearch);
  1176. $iCount = $oSet->Count();
  1177. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  1178. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  1179. }
  1180. else
  1181. {
  1182. $aSynchroUpdate = null;
  1183. }
  1184. $oPage->add("<div><p><h1>".Dict::S('UI:Title:BulkImport+')."</h1></p></div>\n");
  1185. $oPage->AddTabContainer('tabs1');
  1186. $sSeparator = utils::ReadParam('separator', '', false, 'raw_data');
  1187. $sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data');
  1188. $bHeaderLine = utils::ReadParam('header_line', true);
  1189. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '');
  1190. $sClassName = utils::ReadParam('class_name', '');
  1191. $bAdvanced = utils::ReadParam('advanced', 0);
  1192. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  1193. $sFileLoadHtml = '<div><form enctype="multipart/form-data" method="post"><p>'.Dict::S('UI:CSVImport:SelectFile').'</p>'.
  1194. '<p><input type="file" name="csvdata"/></p>';
  1195. $sFileLoadHtml .= '<p>'.Dict::S('UI:CSVImport:Encoding').': ';
  1196. $sFileLoadHtml .= '<select name="encoding" style="font-family:Arial,Helvetica,Sans-serif"/>'; // IE 8 has some troubles if the font is different
  1197. foreach($aPossibleEncodings as $sIconvCode => $sDisplayName )
  1198. {
  1199. $sSelected = '';
  1200. if ($sEncoding == $sIconvCode)
  1201. {
  1202. $sSelected = ' selected';
  1203. }
  1204. $sFileLoadHtml .= '<option value="'.$sIconvCode.'"'.$sSelected.'>'.$sDisplayName.'</option>';
  1205. }
  1206. $sFileLoadHtml .= '</select></p>';
  1207. $sFileLoadHtml .= '<p><input type="submit" value="'.Dict::S('UI:Button:Next').'"/></p>'.
  1208. '<input type="hidden" name="step" value="2"/>'.
  1209. '<input type="hidden" name="operation" value="file_upload"/>'.
  1210. '<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>'.
  1211. '<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>'.
  1212. '<input type="hidden" name="class_name" value="'.$sClassName.'"/>'.
  1213. '<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>'.
  1214. '<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>';
  1215. if (!empty($sSynchroScope))
  1216. {
  1217. foreach($aSynchroUpdate as $sKey => $value)
  1218. {
  1219. $sFileLoadHtml .= '<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>';
  1220. }
  1221. }
  1222. $sFileLoadHtml .= '</form></div>';
  1223. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:LoadFromFile'), $sFileLoadHtml);
  1224. $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
  1225. $sPasteDataHtml = '<div><form enctype="multipart/form-data" method="post"><p>'.Dict::S('UI:CSVImport:PasteData').'</p>'.
  1226. '<p><textarea cols="100" rows="30" name="csvdata">'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'</textarea></p>';
  1227. $sPasteDataHtml .= '<p>'.Dict::S('UI:CSVImport:Encoding').': ';
  1228. $sPasteDataHtml .= '<select name="encoding" style="font-family:Arial,Helvetica,Sans-serif"/>'; // IE8 has some troubles if the font is different
  1229. foreach($aPossibleEncodings as $sIconvCode => $sDisplayName )
  1230. {
  1231. $sSelected = '';
  1232. if ($sEncoding == $sIconvCode)
  1233. {
  1234. $sSelected = ' selected';
  1235. }
  1236. $sPasteDataHtml .= '<option value="'.$sIconvCode.'"'.$sSelected.'>'.$sDisplayName.'</option>';
  1237. }
  1238. $sPasteDataHtml .= '</select></p>'.
  1239. '<p><input type="submit" value="'.Dict::S('UI:Button:Next').'"/></p>'.
  1240. '<input type="hidden" name="step" value="2"/>'.
  1241. '<input type="hidden" name="operation" value="csv_data"/>'.
  1242. '<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>'.
  1243. '<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>'.
  1244. '<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>'.
  1245. '<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>'.
  1246. '<input type="hidden" name="class_name" value="'.$sClassName.'"/>'.
  1247. '<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>'.
  1248. '<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>';
  1249. if (!empty($sSynchroScope))
  1250. {
  1251. foreach($aSynchroUpdate as $sKey => $value)
  1252. {
  1253. $sPasteDataHtml .= '<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>';
  1254. }
  1255. }
  1256. $sPasteDataHtml .= '</form></div>';
  1257. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:CopyPaste'), $sPasteDataHtml);
  1258. if (!empty($sCSVData))
  1259. {
  1260. // When there are some data, activate the 'copy & paste' tab by default
  1261. $oPage->SelectTab('tabs1', Dict::S('UI:CSVImport:Tab:CopyPaste'));
  1262. }
  1263. $sTemplateHtml = '<div><p>'.Dict::S('UI:CSVImport:PickClassForTemplate').' ';
  1264. $sTemplateHtml .= GetClassesSelect('template_class', '', 300, UR_ACTION_BULK_MODIFY);
  1265. $sTemplateHtml .= '</div>';
  1266. $sTemplateHtml .= '<div id="template" style="text-align:center">';
  1267. $sTemplateHtml .= '</div>';
  1268. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:Templates'), $sTemplateHtml);
  1269. $oPage->add_script(
  1270. <<<EOF
  1271. var ajax_request = null;
  1272. function DisplayTemplate(sClassName) {
  1273. $('#template').block();
  1274. // Make sure that we cancel any pending request before issuing another
  1275. // since responses may arrive in arbitrary order
  1276. if (ajax_request != null)
  1277. {
  1278. ajax_request.abort();
  1279. ajax_request = null;
  1280. }
  1281. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  1282. { operation: 'get_csv_template', class_name: sClassName },
  1283. function(data) {
  1284. $('#template').empty();
  1285. $('#template').append(data);
  1286. $('#template').unblock();
  1287. }
  1288. );
  1289. }
  1290. EOF
  1291. );
  1292. $oPage->add_ready_script(
  1293. <<<EOF
  1294. $('#select_template_class').change( function() {
  1295. DisplayTemplate(this.value);
  1296. });
  1297. EOF
  1298. );
  1299. $oPage->SetCurrentTabContainer('tabs1');
  1300. $oPage->SetCurrentTab(Dict::S('UI:History:BulkImports'));
  1301. BulkChange::DisplayImportHistory($oPage);
  1302. }
  1303. switch($iStep)
  1304. {
  1305. case 10:
  1306. $iChange = (int)utils::ReadParam('changeid', 0);
  1307. BulkChange::DisplayImportHistoryDetails($oPage, $iChange);
  1308. break;
  1309. case 5:
  1310. LoadData($oPage);
  1311. break;
  1312. case 4:
  1313. Preview($oPage);
  1314. break;
  1315. case 3:
  1316. SelectMapping($oPage);
  1317. break;
  1318. case 2:
  1319. SelectOptions($oPage);
  1320. break;
  1321. case 1:
  1322. case 6: // Loop back here when we are done
  1323. default:
  1324. Welcome($oPage);
  1325. }
  1326. $oPage->output();
  1327. }
  1328. catch(CoreException $e)
  1329. {
  1330. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1331. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1332. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1333. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1334. $oP->output();
  1335. if (MetaModel::IsLogEnabledIssue())
  1336. {
  1337. if (MetaModel::IsValidClass('EventIssue'))
  1338. {
  1339. $oLog = new EventIssue();
  1340. $oLog->Set('message', $e->getMessage());
  1341. $oLog->Set('userinfo', '');
  1342. $oLog->Set('issue', $e->GetIssue());
  1343. $oLog->Set('impact', 'Page could not be displayed');
  1344. $oLog->Set('callstack', $e->getTrace());
  1345. $oLog->Set('data', $e->getContextData());
  1346. $oLog->DBInsertNoReload();
  1347. }
  1348. IssueLog::Error($e->getMessage());
  1349. }
  1350. // For debugging only
  1351. //throw $e;
  1352. }
  1353. catch(Exception $e)
  1354. {
  1355. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1356. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1357. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1358. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1359. $oP->output();
  1360. if (MetaModel::IsLogEnabledIssue())
  1361. {
  1362. if (MetaModel::IsValidClass('EventIssue'))
  1363. {
  1364. $oLog = new EventIssue();
  1365. $oLog->Set('message', $e->getMessage());
  1366. $oLog->Set('userinfo', '');
  1367. $oLog->Set('issue', 'PHP Exception');
  1368. $oLog->Set('impact', 'Page could not be displayed');
  1369. $oLog->Set('callstack', $e->getTrace());
  1370. $oLog->Set('data', array());
  1371. $oLog->DBInsertNoReload();
  1372. }
  1373. IssueLog::Error($e->getMessage());
  1374. }
  1375. }
  1376. ?>