csvimport.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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. $sUserString = CMDBChange::GetCurrentUserName().' (CSV)';
  281. CMDBObject::SetTrackInfo($sUserString);
  282. $oMyChange = CMDBObject::GetCurrentChange();
  283. }
  284. $oBulk = new BulkChange(
  285. $sClassName,
  286. $aData,
  287. $aAttributes,
  288. $aExtKeys,
  289. array_keys($aSearchKeys),
  290. empty($sSynchroScope) ? null : $sSynchroScope,
  291. $aSynchroUpdate
  292. );
  293. $oBulk->SetReportHtml();
  294. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  295. $aRes = $oBulk->Process($oMyChange);
  296. $sHtml = '<table id="bulk_preview" style="border-collapse: collapse;">';
  297. $sHtml .= '<tr><th style="padding:2px;border-right: 2px #fff solid;">Line</th>';
  298. $sHtml .= '<th style="padding:2px;border-right: 2px #fff solid;">Status</th>';
  299. $sHtml .= '<th style="padding:2px;border-right: 2px #fff solid;">Object</th>';
  300. foreach($aFieldsMapping as $iNumber => $sAttCode)
  301. {
  302. if (!empty($sAttCode) && ($sAttCode != ':none:') && ($sAttCode != 'finalclass'))
  303. {
  304. $sHtml .= "<th style=\"padding:2px;border-right: 2px #fff solid;\">".BulkChange::GetFriendlyAttCodeName($sClassName, $sAttCode)."</th>";
  305. }
  306. }
  307. $sHtml .= '<th>Message</th>';
  308. $sHtml .= '</tr>';
  309. $iErrors = 0;
  310. $iCreated = 0;
  311. $iModified = 0;
  312. $iUnchanged = 0;
  313. foreach($aRes as $iLine => $aResRow)
  314. {
  315. $oStatus = $aResRow['__STATUS__'];
  316. $sUrl = '';
  317. $sMessage = '';
  318. $sCSSRowClass = '';
  319. $sCSSMessageClass = 'cell_ok';
  320. switch(get_class($oStatus))
  321. {
  322. case 'RowStatus_NoChange':
  323. $iUnchanged++;
  324. $sFinalClass = $aResRow['finalclass'];
  325. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  326. $sUrl = $oObj->GetHyperlink();
  327. $sStatus = '<img src="../images/unchanged.png" title="Unchanged">';
  328. $sCSSRowClass = 'row_unchanged';
  329. break;
  330. case 'RowStatus_Modify':
  331. $iModified++;
  332. $sFinalClass = $aResRow['finalclass'];
  333. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  334. $sUrl = $oObj->GetHyperlink();
  335. $sStatus = '<img src="../images/modified.png" title="Modified">';
  336. $sCSSRowClass = 'row_modified';
  337. break;
  338. case 'RowStatus_Disappeared':
  339. $iModified++;
  340. $sFinalClass = $aResRow['finalclass'];
  341. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  342. $sUrl = $oObj->GetHyperlink();
  343. $sStatus = '<img src="../images/delete.png" title="Missing">';
  344. $sCSSRowClass = 'row_modified';
  345. if ($bSimulate)
  346. {
  347. $sMessage = 'Missing object: will be updated';
  348. }
  349. else
  350. {
  351. $sMessage = 'Missing object: updated';
  352. }
  353. break;
  354. case 'RowStatus_NewObj':
  355. $iCreated++;
  356. $sFinalClass = $aResRow['finalclass'];
  357. $sStatus = '<img src="../images/added.png" title="Created">';
  358. $sCSSRowClass = 'row_added';
  359. if ($bSimulate)
  360. {
  361. $sMessage = 'Object will be created';
  362. }
  363. else
  364. {
  365. $sFinalClass = $aResRow['finalclass'];
  366. $oObj = MetaModel::GetObject($sFinalClass, $aResRow['id']->GetPureValue());
  367. $sUrl = $oObj->GetHyperlink();
  368. $sMessage = 'Object created';
  369. }
  370. break;
  371. case 'RowStatus_Issue':
  372. $iErrors++;
  373. $sMessage .= $oPage->GetP($oStatus->GetDescription());
  374. $sStatus = '<img src="../images/error.png" title="Error">';
  375. $sCSSMessageClass = 'cell_error';
  376. $sCSSRowClass = 'row_error';
  377. if (array_key_exists($iLine, $aData))
  378. {
  379. $aRow = $aData[$iLine];
  380. $aResult[] = $sTextQualifier.implode($sTextQualifier.$sSeparator.$sTextQualifier,$aRow).$sTextQualifier; // Remove the first line and store it in case of error
  381. }
  382. break;
  383. }
  384. $sHtml .= '<tr class="'.$sCSSRowClass.'">';
  385. $sHtml .= "<td style=\"background-color:#f1f1f1;border-right:2px #fff solid;\">".sprintf("%0{$sMaxLen}d", 1+$iLine+$iRealSkippedLines)."</td>";
  386. $sHtml .= "<td style=\"text-align:center;background-color:#f1f1f1;border-right:2px #fff solid;\">$sStatus</td>";
  387. $sHtml .= "<td style=\"text-align:center;background-color:#f1f1f1;\">$sUrl</td>";
  388. foreach($aFieldsMapping as $iNumber => $sAttCode)
  389. {
  390. if (!empty($sAttCode) && ($sAttCode != ':none:') && ($sAttCode != 'finalclass'))
  391. {
  392. $oCellStatus = $aResRow[$iNumber -1];
  393. $sCellMessage = '';
  394. if (isset($aExternalKeysByColumn[$iNumber -1]))
  395. {
  396. $sExtKeyName = $aExternalKeysByColumn[$iNumber -1];
  397. $oExtKeyCellStatus = $aResRow[$sExtKeyName];
  398. switch(get_class($oExtKeyCellStatus))
  399. {
  400. case 'CellStatus_Issue':
  401. case 'CellStatus_SearchIssue':
  402. case 'CellStatus_NullIssue':
  403. $sCellMessage .= $oPage->GetP($oExtKeyCellStatus->GetDescription());
  404. break;
  405. case 'CellStatus_Ambiguous':
  406. $sCellMessage .= $oPage->GetP($oExtKeyCellStatus->GetDescription());
  407. break;
  408. default:
  409. // Do nothing
  410. }
  411. }
  412. $sHtmlValue = $oCellStatus->GetDisplayableValue();
  413. switch(get_class($oCellStatus))
  414. {
  415. case 'CellStatus_Issue':
  416. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  417. $sHtml .= '<td class="cell_error" style="border-right:1px #eee solid;">ERROR: '.$sHtmlValue.$sCellMessage.'</td>';
  418. break;
  419. case 'CellStatus_SearchIssue':
  420. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  421. $sHtml .= '<td class="cell_error">ERROR: '.$sHtmlValue.$sCellMessage.'</td>';
  422. break;
  423. case 'CellStatus_Ambiguous':
  424. $sCellMessage .= $oPage->GetP($oCellStatus->GetDescription());
  425. $sHtml .= '<td class="cell_error" style="border-right:1px #eee solid;">AMBIGUOUS: '.$sHtmlValue.$sCellMessage.'</td>';
  426. break;
  427. case 'CellStatus_Modify':
  428. $sHtml .= '<td class="cell_modified" style="border-right:1px #eee solid;"><b>'.$sHtmlValue.'</b></td>';
  429. break;
  430. default:
  431. $sHtml .= '<td class="cell_ok" style="border-right:1px #eee solid;">'.$sHtmlValue.$sCellMessage.'</td>';
  432. }
  433. }
  434. }
  435. $sHtml .= "<td class=\"$sCSSMessageClass\" style=\"background-color:#f1f1f1;\">$sMessage</td>";
  436. $sHtml .= '</tr>';
  437. }
  438. $iUnchanged = count($aRes) - $iErrors - $iModified - $iCreated;
  439. $sHtml .= '</table>';
  440. $oPage->add('<div class="wizContainer" style="width:auto;display:inline-block;">');
  441. $oPage->add('<form enctype="multipart/form-data" id="wizForm" method="post">');
  442. $oPage->add('<input type="hidden" name="step" value="'.($iCurrentStep+1).'"/>');
  443. $oPage->add('<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>');
  444. $oPage->add('<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>');
  445. $oPage->add('<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>');
  446. $oPage->add('<input type="hidden" name="box_skiplines" value="'.(($iSkippedLines > 0) ? 1 : 0).'"/>');
  447. $oPage->add('<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>');
  448. $oPage->add('<input type="hidden" name="csvdata" value="'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'"/>');
  449. $oPage->add('<input type="hidden" name="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  450. $oPage->add('<input type="hidden" name="class_name" value="'.$sClassName.'"/>');
  451. $oPage->add('<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>');
  452. $oPage->add('<input type="hidden" name="encoding" value="'.$sEncoding.'"/>');
  453. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>');
  454. if (!empty($sSynchroScope))
  455. {
  456. foreach($aSynchroUpdate as $sKey => $value)
  457. {
  458. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  459. }
  460. }
  461. foreach($aFieldsMapping as $iNumber => $sAttCode)
  462. {
  463. $oPage->add('<input type="hidden" name="field['.$iNumber.']" value="'.$sAttCode.'"/>');
  464. }
  465. foreach($aSearchFields as $index => $sDummy)
  466. {
  467. $oPage->add('<input type="hidden" name="search_field['.$index.']" value="1"/>');
  468. }
  469. $aDisplayFilters = array();
  470. if ($bSimulate)
  471. {
  472. $aDisplayFilters['unchanged'] = Dict::S('UI:CSVImport:ObjectsWillStayUnchanged');
  473. $aDisplayFilters['modified'] = Dict::S('UI:CSVImport:ObjectsWillBeModified');
  474. $aDisplayFilters['added'] = Dict::S('UI:CSVImport:ObjectsWillBeAdded');
  475. $aDisplayFilters['errors'] = Dict::S('UI:CSVImport:ObjectsWillHaveErrors');
  476. }
  477. else
  478. {
  479. $aDisplayFilters['unchanged'] = Dict::S('UI:CSVImport:ObjectsRemainedUnchanged');
  480. $aDisplayFilters['modified'] = Dict::S('UI:CSVImport:ObjectsWereModified');
  481. $aDisplayFilters['added'] = Dict::S('UI:CSVImport:ObjectsWereAdded');
  482. $aDisplayFilters['errors'] = Dict::S('UI:CSVImport:ObjectsHadErrors');
  483. }
  484. $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;');
  485. $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;');
  486. $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;');
  487. $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>');
  488. $oPage->add('<div class="white" style="display:inline-block">');
  489. $oPage->add($sHtml);
  490. $oPage->add('</div> <!-- end of preview -->');
  491. $oPage->add('<p>');
  492. if($bSimulate)
  493. {
  494. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Restart').'" onClick="CSVRestart()"/>&nbsp;&nbsp;');
  495. }
  496. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="CSVGoBack()"/>&nbsp;&nbsp;');
  497. $bShouldConfirm = false;
  498. if ($bSimulate)
  499. {
  500. // if there are *too many* changes, we should ask the user for a confirmation
  501. if (count($aRes) >= MetaModel::GetConfig()->Get('csv_import_min_object_confirmation'))
  502. {
  503. $fErrorsPercentage = (100.0*$iErrors)/count($aRes);
  504. if ($fErrorsPercentage >= MetaModel::GetConfig()->Get('csv_import_errors_percentage'))
  505. {
  506. $sMessage = sprintf("%.0f %% of the loaded objects have errors and will be ignored.", $fErrorsPercentage);
  507. $bShouldConfirm = true;
  508. }
  509. $fCreatedPercentage = (100.0*$iCreated)/count($aRes);
  510. if ($fCreatedPercentage >= MetaModel::GetConfig()->Get('csv_import_creations_percentage'))
  511. {
  512. $sMessage = sprintf("%.0f %% of the loaded objects will be created.", $fCreatedPercentage);
  513. $bShouldConfirm = true;
  514. }
  515. $fModifiedPercentage = (100.0*$iModified)/count($aRes);
  516. if ($fModifiedPercentage >= MetaModel::GetConfig()->Get('csv_import_modifications_percentage'))
  517. {
  518. $sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fModifiedPercentage);
  519. $bShouldConfirm = true;
  520. }
  521. }
  522. $iCount = count($aRes);
  523. //$oPage->add('<input type="submit" value="'.Dict::S('UI:Button:DoImport').'" onClick="$(\'#wizForm\').block();"/></p>');
  524. $sConfirm = $bShouldConfirm ? 'true' : 'false';
  525. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:DoImport')."\" onClick=\"return DoSubmit($sConfirm);\"/></p>");
  526. }
  527. else
  528. {
  529. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:Done').'"/></p>');
  530. }
  531. $oPage->add('</form>');
  532. $oPage->add('</div> <!-- end of wizForm -->');
  533. if ($bShouldConfirm)
  534. {
  535. $oPage->add('<div id="dlg_confirmation" title="Please confirm the operation">');
  536. $oPage->add('<p style="text-align:center"><b>'.$sMessage.'</b></p>');
  537. $oPage->add('<p style="text-align:center">Are you sure you want to do this ?</p>');
  538. $oPage->add('<div id="confirmation_chart"></div>');
  539. $oPage->add('</div> <!-- end of dlg_confirmation -->');
  540. $oPage->add_ready_script(
  541. <<<EOF
  542. $('#dlg_confirmation').dialog(
  543. {
  544. height: 'auto',
  545. width: 500,
  546. modal:true,
  547. autoOpen: false,
  548. buttons:
  549. {
  550. 'Yes': RunImport,
  551. 'No': CancelImport
  552. }
  553. });
  554. swfobject.embedSWF( "../images/open-flash-chart.swf",
  555. "confirmation_chart",
  556. "100%", "300","9.0.0",
  557. "expressInstall.swf",
  558. {},
  559. {'wmode': 'transparent'}
  560. );
  561. EOF
  562. );
  563. }
  564. $oPage->add_script(
  565. <<< EOF
  566. function CSVGoBack()
  567. {
  568. $('input[name=step]').val($iCurrentStep-1);
  569. $('#wizForm').submit();
  570. }
  571. function CSVRestart()
  572. {
  573. $('input[name=step]').val(1);
  574. $('#wizForm').submit();
  575. }
  576. function ToggleRows(sCSSClass)
  577. {
  578. $('.'+sCSSClass).toggle();
  579. }
  580. function DoSubmit(bConfirm)
  581. {
  582. if (bConfirm) //Ask for a confirmation
  583. {
  584. $('#dlg_confirmation').dialog('open');
  585. }
  586. else
  587. {
  588. // Submit the form
  589. $('#wizForm').block();
  590. $('#wizForm').submit();
  591. }
  592. return false;
  593. }
  594. function CancelImport()
  595. {
  596. $('#dlg_confirmation').dialog('close');
  597. }
  598. function RunImport()
  599. {
  600. $('#dlg_confirmation').dialog('close');
  601. // Submit the form
  602. $('#wizForm').block();
  603. $('#wizForm').submit();
  604. }
  605. function open_flash_chart_data()
  606. {
  607. var iErrors = $iErrors;
  608. var iModified = $iModified;
  609. var iCreated = $iCreated;
  610. var iUnchanged = $iUnchanged;
  611. var fAlpha = 0.9;
  612. var oResult = {
  613. "elements": [
  614. {
  615. "type": "pie",
  616. "tip": "#label# (#percent#)",
  617. "gradient-fill": true,
  618. "font-size": 14,
  619. "colours":[],
  620. "values": [],
  621. "animate":[
  622. {
  623. "type": "fade"
  624. }
  625. ]
  626. }
  627. ],
  628. "x_axis": null,
  629. "font-size": 14,
  630. "bg_colour": "#EEEEEE"
  631. };
  632. if (iErrors > 0)
  633. {
  634. var oErrors =
  635. {
  636. "value": iErrors,
  637. "label": "Errors: "+iErrors,
  638. "alpha": fAlpha,
  639. "label-colour": "#CC3333",
  640. };
  641. oResult.elements[0].values.push(oErrors);
  642. oResult.elements[0].colours.push('#FF6666');
  643. }
  644. if (iModified > 0)
  645. {
  646. var oModified =
  647. {
  648. "value": iModified,
  649. "label": "Modified: "+iModified,
  650. "alpha": fAlpha,
  651. "label-colour": "#3333CC",
  652. };
  653. oResult.elements[0].values.push(oModified);
  654. oResult.elements[0].colours.push('#6666FF');
  655. }
  656. if (iCreated > 0)
  657. {
  658. var oCreated =
  659. {
  660. "value": iCreated,
  661. "label": "Created: "+iCreated,
  662. "alpha": fAlpha,
  663. "label-colour": "#33CC33",
  664. };
  665. oResult.elements[0].values.push(oCreated);
  666. oResult.elements[0].colours.push('#66FF66');
  667. }
  668. if (iUnchanged > 0)
  669. {
  670. var oUnchanged =
  671. {
  672. "value": iUnchanged,
  673. "label": "Unchanged: "+iUnchanged,
  674. "alpha": fAlpha,
  675. "label-colour": "#333333",
  676. };
  677. oResult.elements[0].values.push(oUnchanged);
  678. oResult.elements[0].colours.push('#666666');
  679. }
  680. return JSON.stringify(oResult);
  681. }
  682. EOF
  683. );
  684. if ($iErrors > 0)
  685. {
  686. return $aResult;
  687. }
  688. else
  689. {
  690. return null;
  691. }
  692. }
  693. /**
  694. * Perform the actual load of the CSV data and display the results
  695. * @param WebPage $oPage The web page to display the wizard
  696. * @return void
  697. */
  698. function LoadData(WebPage $oPage)
  699. {
  700. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep5').'</h2>');
  701. $aResult = ProcessCSVData($oPage, false /* simulate = false */);
  702. if (is_array($aResult))
  703. {
  704. $oPage->StartCollapsibleSection(Dict::S('UI:CSVImport:LinesNotImported'), false);
  705. $oPage->p(Dict::S('UI:CSVImport:LinesNotImported+'));
  706. $oPage->add('<textarea rows="30" cols="100">');
  707. $oPage->add(htmlentities(implode("\n", $aResult), ENT_QUOTES, 'UTF-8'));
  708. $oPage->add('</textarea>');
  709. $oPage->EndCollapsibleSection();
  710. }
  711. }
  712. /**
  713. * Simulate the load of the CSV data and display the results
  714. * @param WebPage $oPage The web page to display the wizard
  715. * @return void
  716. */
  717. function Preview(WebPage $oPage)
  718. {
  719. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep4').'</h2>');
  720. ProcessCSVData($oPage, true /* simulate */);
  721. }
  722. /**
  723. * Select the mapping between the CSV column and the fields of the objects
  724. * @param WebPage $oPage The web page to display the wizard
  725. * @return void
  726. */
  727. function SelectMapping(WebPage $oPage)
  728. {
  729. $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
  730. $sCSVDataTruncated = utils::ReadParam('csvdata_truncated', '', false, 'raw_data');
  731. $sSeparator = utils::ReadParam('separator', ',', false, 'raw_data');
  732. if ($sSeparator == 'tab') $sSeparator = "\t";
  733. if ($sSeparator == 'other')
  734. {
  735. $sSeparator = utils::ReadParam('other_separator', ',', false, 'raw_data');
  736. }
  737. $sTextQualifier = utils::ReadParam('text_qualifier', '"', false, 'raw_data');
  738. if ($sTextQualifier == 'other')
  739. {
  740. $sTextQualifier = utils::ReadParam('other_qualifier', '"', false, 'raw_data');
  741. }
  742. $bHeaderLine = (utils::ReadParam('header_line', '0') == 1);
  743. $iSkippedLines = 0;
  744. if (utils::ReadParam('box_skiplines', '0') == 1)
  745. {
  746. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '0');
  747. }
  748. $sClassName = utils::ReadParam('class_name', '', false, 'class');
  749. $bAdvanced = utils::ReadParam('advanced', 0);
  750. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  751. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  752. if (!empty($sSynchroScope))
  753. {
  754. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  755. $sClassName = $oSearch->GetClass(); // If a synchronization scope is set, then the class is fixed !
  756. $oSet = new DBObjectSet($oSearch);
  757. $iCount = $oSet->Count();
  758. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  759. $sClassesSelect = "<select id=\"select_class_name\" name=\"class_name\"><option value=\"$sClassName\" selected>".MetaModel::GetName($sClassName)."</option>";
  760. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  761. }
  762. else
  763. {
  764. $sClassesSelect = GetClassesSelect('class_name', $sClassName, 300, UR_ACTION_BULK_MODIFY);
  765. }
  766. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep3').'</h2>');
  767. $oPage->add('<div class="wizContainer">');
  768. $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').' ');
  769. $oPage->add($sClassesSelect);
  770. $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>');
  771. $oPage->add('<div style="padding:1em;display:none" id="advanced_help" style="display:none">'.Dict::S('UI:CSVImport:AdvancedMode+').'</div>');
  772. $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>');
  773. $oPage->add('<input type="hidden" name="step" value="4"/>');
  774. $oPage->add('<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>');
  775. $oPage->add('<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>');
  776. $oPage->add('<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>');
  777. $oPage->add('<input type="hidden" name="box_skiplines" value="'.(($iSkippedLines > 0) ? 1 : 0).'"/>');
  778. $oPage->add('<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>');
  779. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  780. $oPage->add('<input type="hidden" name="csvdata" value="'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'"/>');
  781. $oPage->add('<input type="hidden" name="encoding" value="'.$sEncoding.'">');
  782. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'">');
  783. if (!empty($sSynchroScope))
  784. {
  785. foreach($aSynchroUpdate as $sKey => $value)
  786. {
  787. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  788. }
  789. }
  790. $oPage->add('<p><input type="button" value="'.Dict::S('UI:Button:Restart').'" onClick="CSVRestart()"/>&nbsp;&nbsp;');
  791. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="CSVGoBack()"/>&nbsp;&nbsp;');
  792. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:SimulateImport').'"/></p>');
  793. $oPage->add('</form>');
  794. $oPage->add('</div>');
  795. $sAlertIncompleteMapping = Dict::S('UI:CSVImport:AlertIncompleteMapping');
  796. $sAlertNoSearchCriteria = Dict::S('UI:CSVImport:AlertNoSearchCriteria');
  797. $oPage->add_ready_script(
  798. <<<EOF
  799. $('#select_class_name').change( DoMapping );
  800. EOF
  801. );
  802. if ($sClassName != '')
  803. {
  804. $oPage->add_ready_script("DoMapping();"); // There is already a class selected, run the mapping
  805. }
  806. $oPage->add_script(
  807. <<<EOF
  808. var aDefaultKeys = new Array();
  809. function CSVGoBack()
  810. {
  811. $('input[name=step]').val(2);
  812. $('#wizForm').removeAttr('onsubmit'); // No need to perform validation checks when going back
  813. $('#wizForm').submit();
  814. }
  815. function CSVRestart()
  816. {
  817. $('input[name=step]').val(1);
  818. $('#wizForm').removeAttr('onsubmit'); // No need to perform validation checks when going back
  819. $('#wizForm').submit();
  820. }
  821. var ajax_request = null;
  822. function DoMapping()
  823. {
  824. var class_name = $('select[name=class_name]').val();
  825. var advanced = $('input[name=advanced]:checked').val();
  826. if (advanced != 1)
  827. {
  828. $('#advanced_help').hide();
  829. }
  830. else
  831. {
  832. $('#advanced_help').show();
  833. }
  834. if (class_name != '')
  835. {
  836. var separator = $('input[name=separator]').val();
  837. var text_qualifier = $('input[name=text_qualifier]').val();
  838. var header_line = $('input[name=header_line]').val();
  839. var nb_lines_skipped = $('input[name=nb_skipped_lines]').val();
  840. var csv_data = $('input[name=csvdata]').val();
  841. var encoding = $('input[name=encoding]').val();
  842. if (advanced != 1)
  843. {
  844. advanced = 0;
  845. }
  846. $('#mapping').block();
  847. // Make sure that we cancel any pending request before issuing another
  848. // since responses may arrive in arbitrary order
  849. if (ajax_request != null)
  850. {
  851. ajax_request.abort();
  852. ajax_request = null;
  853. }
  854. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  855. { operation: 'display_mapping_form', enctype: 'multipart/form-data', csvdata: csv_data, separator: separator,
  856. qualifier: text_qualifier, nb_lines_skipped: nb_lines_skipped, header_line: header_line, class_name: class_name,
  857. advanced: advanced, encoding: encoding },
  858. function(data) {
  859. $('#mapping').empty();
  860. $('#mapping').append(data);
  861. $('#mapping').unblock();
  862. }
  863. );
  864. }
  865. }
  866. function CheckValues()
  867. {
  868. bResult = true;
  869. bMappingOk = true;
  870. bSearchOk = false;
  871. $('select[name^=field]').each( function() {
  872. if ($(this).val() == '')
  873. {
  874. $(this).parent().css({'border': '2px #D81515 solid'});
  875. bMappingOk = false;
  876. bResult = false;
  877. }
  878. else
  879. {
  880. $(this).parent().css({'border': '0'});
  881. }
  882. });
  883. // At least one search field must be checked
  884. $('input[name^=search]:checked').each( function() {
  885. bSearchOk = true;
  886. });
  887. if (!bMappingOk)
  888. {
  889. alert("$sAlertIncompleteMapping");
  890. }
  891. if (!bSearchOk)
  892. {
  893. bResult = false;
  894. alert("$sAlertNoSearchCriteria");
  895. }
  896. if (bResult)
  897. {
  898. $('#mapping').block();
  899. // Re-enable all search_xxx checkboxes so that their value gets posted
  900. $('input[name^=search]').each(function() {
  901. $(this).attr('disabled', false);
  902. });
  903. }
  904. return bResult;
  905. }
  906. function DoCheckMapping()
  907. {
  908. // Check if there is a field mapped to 'id'
  909. // In which case, it's the only possible search key
  910. var idSelected = 0;
  911. var nbSearchKeys = $('input[name^=search]:checked').length;
  912. var nbMappings = $('select[name^=field]').length;
  913. for(index=1; index <= nbMappings; index++)
  914. {
  915. var selectedValue = $('#mapping_'+index).val();
  916. if (selectedValue == 'id')
  917. {
  918. idSelected = index;
  919. }
  920. }
  921. for (index=1; index <= nbMappings; index++)
  922. {
  923. sMappingValue = $('#mapping_'+index).val();
  924. if ((sMappingValue == '') || (sMappingValue == ':none:'))
  925. {
  926. // Non-mapped field, uncheck and disabled
  927. $('#search_'+index).attr('checked', false);
  928. $('#search_'+index).attr('disabled', true);
  929. }
  930. else if (index == idSelected)
  931. {
  932. // The 'id' field was mapped, it's the only possible reconciliation key
  933. $('#search_'+index).attr('checked', true);
  934. $('#search_'+index).attr('disabled', true);
  935. }
  936. else
  937. {
  938. if (idSelected > 0)
  939. {
  940. // The 'id' field was mapped, it's the only possible reconciliation key
  941. $('#search_'+index).attr('checked', false);
  942. $('#search_'+index).attr('disabled', true);
  943. }
  944. else
  945. {
  946. $('#search_'+index).attr('disabled', false);
  947. if (nbSearchKeys == 0)
  948. {
  949. // No search key was selected, select the default ones
  950. for(j =0; j < aDefaultKeys.length; j++)
  951. {
  952. if (sMappingValue == aDefaultKeys[j])
  953. {
  954. $('#search_'+index).attr('checked', true);
  955. }
  956. }
  957. }
  958. }
  959. }
  960. }
  961. }
  962. EOF
  963. );
  964. }
  965. /**
  966. * Select the options of the CSV load and check for CSV parsing errors
  967. * @param WebPage $oPage The current web page
  968. * @return void
  969. */
  970. function SelectOptions(WebPage $oPage)
  971. {
  972. $sOperation = utils::ReadParam('operation', 'csv_data');
  973. $sCSVData = '';
  974. switch($sOperation)
  975. {
  976. case 'file_upload':
  977. $oDocument = utils::ReadPostedDocument('csvdata');
  978. if (!$oDocument->IsEmpty())
  979. {
  980. $sCSVData = $oDocument->GetData();
  981. }
  982. break;
  983. default:
  984. $sCSVData = utils::ReadPostedParam('csvdata', '', 'raw_data');
  985. }
  986. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  987. // Compute a subset of the data set, now that we know the charset
  988. if ($sEncoding == 'UTF-8')
  989. {
  990. $sUTF8Data = iconv('UTF-8', 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  991. }
  992. else
  993. {
  994. $sUTF8Data = iconv($sEncoding, 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  995. }
  996. $aGuesses = GuessParameters($sUTF8Data); // Try to predict the parameters, based on the input data
  997. $sSeparator = utils::ReadParam('separator', '', false, 'raw_data');
  998. if ($sSeparator == '') // May be set to an empty value by the previous page
  999. {
  1000. $sSeparator = $aGuesses['separator'];
  1001. }
  1002. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '');
  1003. $bBoxSkipLines = utils::ReadParam('box_skiplines', 0);
  1004. if ($sSeparator == 'tab') $sSeparator = "\t";
  1005. $sOtherSeparator = in_array($sSeparator, array(',', ';', "\t")) ? '' : $sSeparator;
  1006. $sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data');
  1007. if ($sTextQualifier == '') // May be set to an empty value by the previous page
  1008. {
  1009. $sTextQualifier = $aGuesses['qualifier'];
  1010. }
  1011. $sOtherTextQualifier = in_array($sTextQualifier, array('"', "'")) ? '' : $sTextQualifier;
  1012. $bHeaderLine = utils::ReadParam('header_line', 0);
  1013. $sClassName = utils::ReadParam('class_name', '', false, 'class');
  1014. $bAdvanced = utils::ReadParam('advanced', 0);
  1015. // Create a truncated version of the data used for the fast preview
  1016. // Take about 20 lines of data... knowing that some lines may contain carriage returns
  1017. $iMaxLen = strlen($sUTF8Data);
  1018. if ($iMaxLen > 0)
  1019. {
  1020. $iMaxLines = 20;
  1021. $iCurPos = true;
  1022. while ( ($iCurPos > 0) && ($iMaxLines > 0))
  1023. {
  1024. $pos = strpos($sUTF8Data, "\n", $iCurPos);
  1025. if ($pos !== false)
  1026. {
  1027. $iCurPos = 1+$pos;
  1028. }
  1029. else
  1030. {
  1031. $iCurPos = strlen($sUTF8Data);
  1032. $iMaxLines = 1;
  1033. }
  1034. $iMaxLines--;
  1035. }
  1036. $sCSVDataTruncated = substr($sUTF8Data, 0, $iCurPos);
  1037. }
  1038. else
  1039. {
  1040. $sCSVDataTruncated = '';
  1041. }
  1042. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  1043. if (!empty($sSynchroScope))
  1044. {
  1045. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  1046. $sClassName = $oSearch->GetClass();
  1047. $oSet = new DBObjectSet($oSearch);
  1048. $iCount = $oSet->Count();
  1049. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  1050. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  1051. }
  1052. $oPage->add('<h2>'.Dict::S('UI:Title:CSVImportStep2').'</h2>');
  1053. $oPage->add('<div class="wizContainer">');
  1054. $oPage->add('<table><tr><td style="vertical-align:top;padding-right:50px;">');
  1055. $oPage->add('<form enctype="multipart/form-data" id="wizForm" method="post" id="csv_options">');
  1056. $oPage->add('<h3>'.Dict::S('UI:CSVImport:SeparatorCharacter').'</h3>');
  1057. $oPage->add('<p><input type="radio" name="separator" value="," onClick="DoPreview()"'.IsChecked($sSeparator, ',').'/> '.Dict::S('UI:CSVImport:SeparatorComma+').'<br/>');
  1058. $oPage->add('<input type="radio" name="separator" value=";" onClick="DoPreview()"'.IsChecked($sSeparator, ';').'/> '.Dict::S('UI:CSVImport:SeparatorSemicolon+').'<br/>');
  1059. $oPage->add('<input type="radio" name="separator" value="tab" onClick="DoPreview()"'.IsChecked($sSeparator, "\t").'/> '.Dict::S('UI:CSVImport:SeparatorTab+').'<br/>');
  1060. $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()"/>');
  1061. $oPage->add('</p>');
  1062. $oPage->add('</td><td style="vertical-align:top;padding-right:50px;">');
  1063. $oPage->add('<h3>'.Dict::S('UI:CSVImport:TextQualifierCharacter').'</h3>');
  1064. $oPage->add('<p><input type="radio" name="text_qualifier" value="&#34;" onClick="DoPreview()"'.IsChecked($sTextQualifier, '"').'/> '.Dict::S('UI:CSVImport:QualifierDoubleQuote+').'<br/>');
  1065. $oPage->add('<input type="radio" name="text_qualifier" value="&#39;" onClick="DoPreview()"'.IsChecked($sTextQualifier, "'").'/> '.Dict::S('UI:CSVImport:QualifierSimpleQuote+').'<br/>');
  1066. $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()"/>');
  1067. $oPage->add('</p>');
  1068. $oPage->add('</td><td style="vertical-align:top;">');
  1069. $oPage->add('<h3>'.Dict::S('UI:CSVImport:CommentsAndHeader').'</h3>');
  1070. $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>');
  1071. $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>');
  1072. $oPage->add('</td></tr></table>');
  1073. $oPage->add('<input type="hidden" name="csvdata_truncated" id="csvdata_truncated" value="'.htmlentities($sCSVDataTruncated, ENT_QUOTES, 'UTF-8').'"/>');
  1074. $oPage->add('<input type="hidden" name="csvdata" id="csvdata" value="'.htmlentities($sUTF8Data, ENT_QUOTES, 'UTF-8').'"/>');
  1075. $oPage->add('<input type="hidden" name="class_name" value="'.$sClassName.'"/>');
  1076. $oPage->add('<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>');
  1077. $oPage->add('<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>');
  1078. $oPage->add('<input type="hidden" name="step" value="3"/>');
  1079. if (!empty($sSynchroScope))
  1080. {
  1081. foreach($aSynchroUpdate as $sKey => $value)
  1082. {
  1083. $oPage->add('<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>');
  1084. }
  1085. }
  1086. $oPage->add('<div id="preview">');
  1087. $oPage->add('<p style="text-align:center">'.Dict::S('UI:CSVImport:CSVDataPreview').'</p>');
  1088. $oPage->add('</div>');
  1089. $oPage->add('<input type="button" value="'.Dict::S('UI:Button:Back').'" onClick="GoBack()"/>');
  1090. $oPage->add('<input type="submit" value="'.Dict::S('UI:Button:Next').'"/>');
  1091. $oPage->add('</form>');
  1092. $oPage->add('</div>');
  1093. $oPage->add_script(
  1094. <<<EOF
  1095. function GoBack()
  1096. {
  1097. $('input[name=step]').val(1);
  1098. $('#wizForm').submit();
  1099. }
  1100. var ajax_request = null;
  1101. function DoPreview()
  1102. {
  1103. var separator = $('input[name=separator]:checked').val();
  1104. if (separator == 'other')
  1105. {
  1106. separator = $('#other_separator').val();
  1107. }
  1108. var text_qualifier = $('input[name=text_qualifier]:checked').val();
  1109. if (text_qualifier == 'other')
  1110. {
  1111. text_qualifier = $('#other_qualifier').val();
  1112. }
  1113. var nb_lines_skipped = 0;
  1114. if ($('#box_skiplines:checked').val() != null)
  1115. {
  1116. nb_lines_skipped = $('#nb_skipped_lines').val();
  1117. }
  1118. var header_line = 0;
  1119. if ($('#box_header:checked').val() != null)
  1120. {
  1121. header_line = 1;
  1122. }
  1123. var encoding = $('input[name=encoding]').val();
  1124. $('#preview').block();
  1125. // Make sure that we cancel any pending request before issuing another
  1126. // since responses may arrive in arbitrary order
  1127. if (ajax_request != null)
  1128. {
  1129. ajax_request.abort();
  1130. ajax_request = null;
  1131. }
  1132. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  1133. { 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 },
  1134. function(data) {
  1135. $('#preview').empty();
  1136. $('#preview').append(data);
  1137. $('#preview').unblock();
  1138. }
  1139. );
  1140. }
  1141. EOF
  1142. );
  1143. $oPage->add_ready_script('DoPreview();');
  1144. }
  1145. /**
  1146. * Prompt for the data to be loaded (either via a file or a copy/paste)
  1147. * @param WebPage $oPage The current web page
  1148. * @return void
  1149. */
  1150. function Welcome(iTopWebPage $oPage)
  1151. {
  1152. // Encodings supported:
  1153. // ICONV_CODE => Display Name
  1154. // Each iconv installation supports different encodings
  1155. // Some reasonably common and useful encodnings are listed here
  1156. $aPossibleEncodings = array(
  1157. 'UTF-8' => 'Unicode (UTF-8)',
  1158. 'ISO-8859-1' => 'Western (ISO-8859-1)',
  1159. 'WINDOWS-1251' => 'Cyrilic (Windows 1251)',
  1160. 'WINDOWS-1252' => 'Western (Windows 1252)',
  1161. 'ISO-8859-15' => 'Western (ISO-8859-15)',
  1162. );
  1163. // Some more encodings can be specified in the config file
  1164. $aExtraCharsets = MetaModel::GetConfig()->GetCSVImportCharsets();
  1165. $aPossibleEncodings = array_merge($aPossibleEncodings, $aExtraCharsets);
  1166. asort($aPossibleEncodings);
  1167. $sSynchroScope = utils::ReadParam('synchro_scope', '', false, 'raw_data');
  1168. if (!empty($sSynchroScope))
  1169. {
  1170. $oSearch = DBObjectSearch::FromOQL($sSynchroScope);
  1171. $sClassName = $oSearch->GetClass();
  1172. $oSet = new DBObjectSet($oSearch);
  1173. $iCount = $oSet->Count();
  1174. DisplaySynchroBanner($oPage, $sClassName, $iCount);
  1175. $aSynchroUpdate = utils::ReadParam('synchro_update', array());
  1176. }
  1177. else
  1178. {
  1179. $aSynchroUpdate = null;
  1180. }
  1181. $oPage->add("<div><p><h1>".Dict::S('UI:Title:BulkImport+')."</h1></p></div>\n");
  1182. $oPage->AddTabContainer('tabs1');
  1183. $sSeparator = utils::ReadParam('separator', '', false, 'raw_data');
  1184. $sTextQualifier = utils::ReadParam('text_qualifier', '', false, 'raw_data');
  1185. $bHeaderLine = utils::ReadParam('header_line', true);
  1186. $iSkippedLines = utils::ReadParam('nb_skipped_lines', '');
  1187. $sClassName = utils::ReadParam('class_name', '');
  1188. $bAdvanced = utils::ReadParam('advanced', 0);
  1189. $sEncoding = utils::ReadParam('encoding', 'UTF-8');
  1190. $sFileLoadHtml = '<div><form enctype="multipart/form-data" method="post"><p>'.Dict::S('UI:CSVImport:SelectFile').'</p>'.
  1191. '<p><input type="file" name="csvdata"/></p>';
  1192. $sFileLoadHtml .= '<p>'.Dict::S('UI:CSVImport:Encoding').': ';
  1193. $sFileLoadHtml .= '<select name="encoding" style="font-family:Arial,Helvetica,Sans-serif"/>'; // IE 8 has some troubles if the font is different
  1194. foreach($aPossibleEncodings as $sIconvCode => $sDisplayName )
  1195. {
  1196. $sSelected = '';
  1197. if ($sEncoding == $sIconvCode)
  1198. {
  1199. $sSelected = ' selected';
  1200. }
  1201. $sFileLoadHtml .= '<option value="'.$sIconvCode.'"'.$sSelected.'>'.$sDisplayName.'</option>';
  1202. }
  1203. $sFileLoadHtml .= '</select></p>';
  1204. $sFileLoadHtml .= '<p><input type="submit" value="'.Dict::S('UI:Button:Next').'"/></p>'.
  1205. '<input type="hidden" name="step" value="2"/>'.
  1206. '<input type="hidden" name="operation" value="file_upload"/>'.
  1207. '<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>'.
  1208. '<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>'.
  1209. '<input type="hidden" name="class_name" value="'.$sClassName.'"/>'.
  1210. '<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>'.
  1211. '<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>';
  1212. if (!empty($sSynchroScope))
  1213. {
  1214. foreach($aSynchroUpdate as $sKey => $value)
  1215. {
  1216. $sFileLoadHtml .= '<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>';
  1217. }
  1218. }
  1219. $sFileLoadHtml .= '</form></div>';
  1220. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:LoadFromFile'), $sFileLoadHtml);
  1221. $sCSVData = utils::ReadParam('csvdata', '', false, 'raw_data');
  1222. $sPasteDataHtml = '<div><form enctype="multipart/form-data" method="post"><p>'.Dict::S('UI:CSVImport:PasteData').'</p>'.
  1223. '<p><textarea cols="100" rows="30" name="csvdata">'.htmlentities($sCSVData, ENT_QUOTES, 'UTF-8').'</textarea></p>';
  1224. $sPasteDataHtml .= '<p>'.Dict::S('UI:CSVImport:Encoding').': ';
  1225. $sPasteDataHtml .= '<select name="encoding" style="font-family:Arial,Helvetica,Sans-serif"/>'; // IE8 has some troubles if the font is different
  1226. foreach($aPossibleEncodings as $sIconvCode => $sDisplayName )
  1227. {
  1228. $sSelected = '';
  1229. if ($sEncoding == $sIconvCode)
  1230. {
  1231. $sSelected = ' selected';
  1232. }
  1233. $sPasteDataHtml .= '<option value="'.$sIconvCode.'"'.$sSelected.'>'.$sDisplayName.'</option>';
  1234. }
  1235. $sPasteDataHtml .= '</select></p>'.
  1236. '<p><input type="submit" value="'.Dict::S('UI:Button:Next').'"/></p>'.
  1237. '<input type="hidden" name="step" value="2"/>'.
  1238. '<input type="hidden" name="operation" value="csv_data"/>'.
  1239. '<input type="hidden" name="separator" value="'.htmlentities($sSeparator, ENT_QUOTES, 'UTF-8').'"/>'.
  1240. '<input type="hidden" name="text_qualifier" value="'.htmlentities($sTextQualifier, ENT_QUOTES, 'UTF-8').'"/>'.
  1241. '<input type="hidden" name="header_line" value="'.$bHeaderLine.'"/>'.
  1242. '<input type="hidden" name="nb_skipped_lines" value="'.$iSkippedLines.'"/>'.
  1243. '<input type="hidden" name="class_name" value="'.$sClassName.'"/>'.
  1244. '<input type="hidden" name="advanced" value="'.$bAdvanced.'"/>'.
  1245. '<input type="hidden" name="synchro_scope" value="'.$sSynchroScope.'"/>';
  1246. if (!empty($sSynchroScope))
  1247. {
  1248. foreach($aSynchroUpdate as $sKey => $value)
  1249. {
  1250. $sPasteDataHtml .= '<input type="hidden" name="synchro_update['.$sKey.']" value="'.$value.'"/>';
  1251. }
  1252. }
  1253. $sPasteDataHtml .= '</form></div>';
  1254. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:CopyPaste'), $sPasteDataHtml);
  1255. if (!empty($sCSVData))
  1256. {
  1257. // When there are some data, activate the 'copy & paste' tab by default
  1258. $oPage->SelectTab('tabs1', Dict::S('UI:CSVImport:Tab:CopyPaste'));
  1259. }
  1260. $sTemplateHtml = '<div><p>'.Dict::S('UI:CSVImport:PickClassForTemplate').' ';
  1261. $sTemplateHtml .= GetClassesSelect('template_class', '', 300, UR_ACTION_BULK_MODIFY);
  1262. $sTemplateHtml .= '</div>';
  1263. $sTemplateHtml .= '<div id="template" style="text-align:center">';
  1264. $sTemplateHtml .= '</div>';
  1265. $oPage->AddToTab('tabs1', Dict::S('UI:CSVImport:Tab:Templates'), $sTemplateHtml);
  1266. $oPage->add_script(
  1267. <<<EOF
  1268. var ajax_request = null;
  1269. function DisplayTemplate(sClassName) {
  1270. $('#template').block();
  1271. // Make sure that we cancel any pending request before issuing another
  1272. // since responses may arrive in arbitrary order
  1273. if (ajax_request != null)
  1274. {
  1275. ajax_request.abort();
  1276. ajax_request = null;
  1277. }
  1278. ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.csvimport.php',
  1279. { operation: 'get_csv_template', class_name: sClassName },
  1280. function(data) {
  1281. $('#template').empty();
  1282. $('#template').append(data);
  1283. $('#template').unblock();
  1284. }
  1285. );
  1286. }
  1287. EOF
  1288. );
  1289. $oPage->add_ready_script(
  1290. <<<EOF
  1291. $('#select_template_class').change( function() {
  1292. DisplayTemplate(this.value);
  1293. });
  1294. EOF
  1295. );
  1296. $oPage->SetCurrentTabContainer('tabs1');
  1297. $oPage->SetCurrentTab(Dict::S('UI:History:BulkImports'));
  1298. BulkChange::DisplayImportHistory($oPage);
  1299. }
  1300. switch($iStep)
  1301. {
  1302. case 10:
  1303. $iChange = (int)utils::ReadParam('changeid', 0);
  1304. BulkChange::DisplayImportHistoryDetails($oPage, $iChange);
  1305. break;
  1306. case 5:
  1307. LoadData($oPage);
  1308. break;
  1309. case 4:
  1310. Preview($oPage);
  1311. break;
  1312. case 3:
  1313. SelectMapping($oPage);
  1314. break;
  1315. case 2:
  1316. SelectOptions($oPage);
  1317. break;
  1318. case 1:
  1319. case 6: // Loop back here when we are done
  1320. default:
  1321. Welcome($oPage);
  1322. }
  1323. $oPage->output();
  1324. }
  1325. catch(CoreException $e)
  1326. {
  1327. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1328. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1329. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1330. $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
  1331. $oP->output();
  1332. if (MetaModel::IsLogEnabledIssue())
  1333. {
  1334. if (MetaModel::IsValidClass('EventIssue'))
  1335. {
  1336. $oLog = new EventIssue();
  1337. $oLog->Set('message', $e->getMessage());
  1338. $oLog->Set('userinfo', '');
  1339. $oLog->Set('issue', $e->GetIssue());
  1340. $oLog->Set('impact', 'Page could not be displayed');
  1341. $oLog->Set('callstack', $e->getTrace());
  1342. $oLog->Set('data', $e->getContextData());
  1343. $oLog->DBInsertNoReload();
  1344. }
  1345. IssueLog::Error($e->getMessage());
  1346. }
  1347. // For debugging only
  1348. //throw $e;
  1349. }
  1350. catch(Exception $e)
  1351. {
  1352. require_once(APPROOT.'/setup/setuppage.class.inc.php');
  1353. $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
  1354. $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
  1355. $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
  1356. $oP->output();
  1357. if (MetaModel::IsLogEnabledIssue())
  1358. {
  1359. if (MetaModel::IsValidClass('EventIssue'))
  1360. {
  1361. $oLog = new EventIssue();
  1362. $oLog->Set('message', $e->getMessage());
  1363. $oLog->Set('userinfo', '');
  1364. $oLog->Set('issue', 'PHP Exception');
  1365. $oLog->Set('impact', 'Page could not be displayed');
  1366. $oLog->Set('callstack', $e->getTrace());
  1367. $oLog->Set('data', array());
  1368. $oLog->DBInsertNoReload();
  1369. }
  1370. IssueLog::Error($e->getMessage());
  1371. }
  1372. }
  1373. ?>