csvimport.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. require_once('../application/application.inc.php');
  3. require_once('../application/itopwebpage.class.inc.php');
  4. require_once('../application/startup.inc.php');
  5. require_once('../application/loginwebpage.class.inc.php');
  6. login_web_page::DoLogin(); // Check user rights and prompt if needed
  7. $oContext = new UserContext();
  8. $oAppContext = new ApplicationContext();
  9. $iActiveNodeId = utils::ReadParam('menu', -1);
  10. $currentOrganization = utils::ReadParam('org_id', 1);
  11. $oPage = new iTopWebPage("iTop - Bulk import", $currentOrganization);
  12. define ('EXTKEY_SEP', '::::');
  13. define ('EXTKEY_LABELSEP', ' -> ');
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // External key/field naming conventions (sharing the naming space with std attributes
  16. ///////////////////////////////////////////////////////////////////////////////
  17. function IsExtKeyField($sColDesc)
  18. {
  19. return ($iPos = strpos($sColDesc, EXTKEY_SEP));
  20. }
  21. function GetExtKeyFieldCodes($sColDesc)
  22. {
  23. $iPos = strpos($sColDesc, EXTKEY_SEP);
  24. return array(
  25. substr($sColDesc, 0, $iPos),
  26. substr($sColDesc, $iPos + strlen(EXTKEY_SEP))
  27. );
  28. }
  29. function MakeExtFieldLabel($sClass, $sExtKeyAttCode, $sForeignAttCode)
  30. {
  31. $oExtKeyAtt = MetaModel::GetAttributeDef($sClass, $sExtKeyAttCode);
  32. $oForeignAtt = MetaModel::GetAttributeDef($oExtKeyAtt->GetTargetClass(), $sForeignAttCode);
  33. return $oExtKeyAtt->GetLabel().EXTKEY_LABELSEP.$oForeignAtt->GetLabel();
  34. }
  35. function MakeExtFieldSelectValue($sAttCode, $sExtAttCode)
  36. {
  37. return $sAttCode.EXTKEY_SEP.$sExtAttCode;
  38. }
  39. ///////////////////////////////////////////////////////////////////////////////
  40. ///////////////////////////////////////////////////////////////////////////////
  41. function ShowTableForm($oPage, $oCSVParser, $sClass)
  42. {
  43. $aData = $oCSVParser->ToArray(null, 3);
  44. $aColToRow = array();
  45. foreach($aData as $aRow)
  46. {
  47. foreach ($aRow as $sFieldId=>$sValue)
  48. {
  49. $aColToRow[$sFieldId][] = $sValue;
  50. }
  51. }
  52. $aFields = array();
  53. foreach($oCSVParser->ListFields() as $iFieldIndex=>$sFieldName)
  54. {
  55. $sSelField = "<select name=\"fmap[field$iFieldIndex]\">";
  56. $sSelField .= "<option value=\"__none__\">None (ignore)</option>";
  57. $sSELECTED = (strcasecmp($sFieldName, "pkey") == 0) ? " SELECTED" : "";
  58. $sSelField .= "<option value=\"pkey\"$sSELECTED>Private Key</option>";
  59. $sFoundAttCode = ""; // quick and dirty way to remind if a match has been found and suggest a reconciliation key if possible
  60. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAtt)
  61. {
  62. if ($oAtt->IsExternalField()) continue;
  63. $bIsThatField = (strcasecmp($sFieldName, $oAtt->GetLabel()) == 0);
  64. //$sIsReconcKey = (MetaModel::IsValidFilterCode($sClass, $sAttCode)) ? " [key]" : "";
  65. $sIsReconcKey = MetaModel::IsReconcKey($sClass, $sAttCode) ? " [rk!]" : "";
  66. $sFoundAttCode = (MetaModel::IsValidFilterCode($sClass, $sAttCode) && $bIsThatField) ? $sAttCode : $sFoundAttCode;
  67. $sSELECTED = $bIsThatField ? " SELECTED" : "";
  68. if ($oAtt->IsExternalKey())
  69. {
  70. // An external key might be loaded by
  71. // the pkey or a reconciliation key
  72. //
  73. $sSelField .= "<option value=\"$sAttCode\"$sSELECTED><em>".$oAtt->GetLabel()."</em> (pkey)$sIsReconcKey</option>";
  74. $sRemoteClass = $oAtt->GetTargetClass();
  75. foreach(MetaModel::GetReconcKeys($sRemoteClass) as $sExtAttCode)
  76. {
  77. $sValue = MakeExtFieldSelectValue($sAttCode, $sExtAttCode);
  78. // Create two entries:
  79. // - generic syntax (ext key label -> remote field label)
  80. // - if an ext field exists that corresponds to it, allow its label
  81. $sLabel1 = MakeExtFieldLabel($sClass, $sAttCode, $sExtAttCode);
  82. $bFoundTwin = false;
  83. foreach (MetaModel::GetExternalFields($sClass, $sAttCode) as $oExtFieldAtt)
  84. {
  85. if ($oExtFieldAtt->GetExtAttCode() == $sExtAttCode)
  86. {
  87. $sLabel2 = $oExtFieldAtt->GetLabel();
  88. $bIsThatField = (strcasecmp($sFieldName, $sLabel2) == 0);
  89. $sSELECTED = $bIsThatField ? " SELECTED" : "";
  90. $sTITLE = " title=\"equivalent to '".htmlentities($sLabel1)."'\"";
  91. $sSelField .= "<option value=\"$sValue\"$sTITLE $sSELECTED>".htmlentities($sLabel2)."</option>";
  92. $bFoundTwin = true;
  93. break;
  94. }
  95. }
  96. $bIsThatField = (strcasecmp($sFieldName, $sLabel1) == 0);
  97. $sSELECTED = $bIsThatField ? " SELECTED" : "";
  98. $sTITLE = $bFoundTwin ? " title=\"equivalent to '".htmlentities($sLabel2)."'\"" : "";
  99. $sSelField .= "<option value=\"$sValue\"$sTITLE $sSELECTED>".htmlentities($sLabel1)."</option>";
  100. }
  101. }
  102. else
  103. {
  104. $sSelField .= "<option value=\"$sAttCode\"$sSELECTED>".$oAtt->GetLabel()."$sIsReconcKey</option>";
  105. }
  106. }
  107. $sSelField .= "</select>";
  108. $sCHECKED = ($sFieldName == "pkey" || MetaModel::IsReconcKey($sClass, $sFoundAttCode)) ? " CHECKED" : "";
  109. $sSelField .= "&nbsp;<input type=\"checkbox\" name=\"iskey[field$iFieldIndex]\" value=\"yes\" $sCHECKED>";
  110. $aFields["field$iFieldIndex"]["label"] = $sSelField;
  111. $aFields["field$iFieldIndex"]["value"] = $aColToRow[$iFieldIndex];
  112. }
  113. $oPage->details($aFields);
  114. }
  115. function ProcessData($oPage, $sClass, $oCSVParser, $aFieldMap, $aIsReconcKey, CMDBChange $oChange = null)
  116. {
  117. // Note: $oChange can be null, in which case the aim is to check what would be done
  118. // Setup field mapping: sort out between values and other specific columns
  119. //
  120. $iPKeyId = null;
  121. $aReconcilKeys = array();
  122. $aAttList = array();
  123. $aExtKeys = array();
  124. foreach($aFieldMap as $sFieldId=>$sColDesc)
  125. {
  126. $iFieldId = (int) substr($sFieldId, strlen("field"));
  127. if ($sColDesc == "pkey")
  128. {
  129. // Skip !
  130. $iPKeyId = $iFieldId;
  131. }
  132. elseif ($sColDesc == "__none__")
  133. {
  134. // Skip !
  135. }
  136. elseif (IsExtKeyField($sColDesc))
  137. {
  138. list($sExtKeyAttCode, $sExtReconcKeyAttCode) = GetExtKeyFieldCodes($sColDesc);
  139. $aExtKeys[$sExtKeyAttCode][$sExtReconcKeyAttCode] = $iFieldId;
  140. }
  141. elseif (array_key_exists($sFieldId, $aIsReconcKey))
  142. {
  143. $aReconcilKeys[$sColDesc] = $iFieldId;
  144. $aAttList[$sColDesc] = $iFieldId; // A reconciliation key is also a field
  145. }
  146. else
  147. {
  148. // $sColDesc is an attribute code
  149. //
  150. $aAttList[$sColDesc] = $iFieldId;
  151. }
  152. }
  153. // Setup result presentation
  154. //
  155. $aDisplayConfig = array();
  156. $aDisplayConfig["__RECONCILIATION__"] = array("label"=>"Reconciliation", "description"=>"");
  157. $aDisplayConfig["__STATUS__"] = array("label"=>"Status", "description"=>"");
  158. if (isset($iPKeyId))
  159. {
  160. $aDisplayConfig["col$iPKeyId"] = array("label"=>"<strong>pkey</strong>", "description"=>"");
  161. }
  162. foreach($aReconcilKeys as $sAttCode => $iCol)
  163. {
  164. $sLabel = MetaModel::GetAttributeDef($sClass, $sAttCode)->GetLabel();
  165. $aDisplayConfig["col$iCol"] = array("label"=>"$sLabel", "description"=>"");
  166. }
  167. foreach($aExtKeys as $sAttCode=>$aKeyConfig)
  168. {
  169. $oExtKeyAtt = MetaModel::GetAttributeDef($sClass, $sAttCode);
  170. $sLabel = $oExtKeyAtt->GetLabel();
  171. $aDisplayConfig[$sAttCode] = array("label"=>"$sLabel", "description"=>"");
  172. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  173. {
  174. // The foreign attribute is one of our reconciliation key
  175. $sLabel = MakeExtFieldLabel($sClass, $sAttCode, $sForeignAttCode);
  176. $aDisplayConfig["col$iCol"] = array("label"=>"$sLabel", "description"=>"");
  177. }
  178. }
  179. foreach ($aAttList as $sAttCode => $iCol)
  180. {
  181. $sLabel = MetaModel::GetAttributeDef($sClass, $sAttCode)->GetLabel();
  182. $aDisplayConfig["col$iCol"] = array("label"=>"$sLabel", "description"=>"");
  183. }
  184. // Compute the results
  185. //
  186. $aData = $oCSVParser->ToArray();
  187. $oBulk = new BulkChange(
  188. $sClass,
  189. $aData,
  190. $aAttList,
  191. array_keys($aReconcilKeys),
  192. $aExtKeys
  193. );
  194. $aRes = $oBulk->Process($oChange);
  195. $aResultDisp = array(); // to be displayed
  196. foreach($aRes as $iRow => $aRowData)
  197. {
  198. $aRowDisp = array();
  199. $aRowDisp["__RECONCILIATION__"] = $aRowData["__RECONCILIATION__"];
  200. $aRowDisp["__STATUS__"] = $aRowData["__STATUS__"]->GetDescription();
  201. foreach($aRowData as $sKey => $value)
  202. {
  203. if ($sKey == '__RECONCILIATION__') continue;
  204. if ($sKey == '__STATUS__') continue;
  205. switch (get_class($value))
  206. {
  207. case 'CellChangeSpec_Void':
  208. $sClass = '';
  209. break;
  210. case 'CellChangeSpec_Unchanged':
  211. $sClass = '';
  212. break;
  213. case 'CellChangeSpec_Modify':
  214. $sClass = 'csvimport_ok';
  215. break;
  216. case 'CellChangeSpec_Init':
  217. $sClass = 'csvimport_init';
  218. break;
  219. case 'CellChangeSpec_Issue':
  220. $sClass = 'csvimport_error';
  221. break;
  222. }
  223. if (empty($sClass))
  224. {
  225. $aRowDisp[$sKey] = $value->GetDescription();
  226. }
  227. else
  228. {
  229. $aRowDisp[$sKey] = "<div class=\"$sClass\">".$value->GetDescription()."</div>";
  230. }
  231. }
  232. $aResultDisp[$iRow] = $aRowDisp;
  233. }
  234. $oPage->table($aDisplayConfig, $aResultDisp);
  235. }
  236. ///////////////////////////////////////////////////////////////////////////////
  237. // Wizard entry points
  238. ///////////////////////////////////////////////////////////////////////////////
  239. function Do_Welcome($oPage, $sClass)
  240. {
  241. $sWiztep = "1_welcome";
  242. $oPage->p("<h1>Bulk load from CSV data / step 1</h1>");
  243. $sCSVData = utils::ReadPostedParam('csvdata');
  244. $oPage->add("<form method=\"post\" action=\"\">");
  245. $oPage->MakeClassesSelect("class", $sClass, 50);
  246. //$oPage->Add("<input type=\"text\" size=\"40\" name=\"initialsituation\" value=\"\">");
  247. $oPage->add("</br>");
  248. $oPage->add("<textarea rows=\"25\" cols=\"80\" name=\"csvdata\" wrap=\"soft\">$sCSVData</textarea>");
  249. $oPage->add("</br>");
  250. $oPage->add("<input type=\"hidden\" name=\"fromwiztep\" value=\"$sWiztep\">");
  251. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Next\"><br/>\n");
  252. $oPage->add("</form>");
  253. // As a help to the end-user, let's display the list of possible fields
  254. // for a class, that can be copied/pasted into the CSV area.
  255. $sCurrentList = "";
  256. $aHeadersList = array();
  257. foreach(MetaModel::GetClasses('bizmodel') as $sClassName)
  258. {
  259. $aList = MetaModel::GetZListItems($sClassName, 'details');
  260. $aHeader = array();
  261. // $aHeader[] = MetaModel::GetKeyLabel($sClassName);
  262. $aHeader[] = 'pkey'; // Should be what's coded on the line above... but there is a bug
  263. foreach($aList as $sAttCode)
  264. {
  265. $aHeader[] = MetaModel::GetLabel($sClassName, $sAttCode);
  266. }
  267. $sAttributes = implode(",", $aHeader);
  268. $aHeadersList[$sClassName] = $sAttributes;
  269. if($sClassName == $sClass)
  270. {
  271. // this class is currently selected
  272. $sCurrentList = $sAttributes;
  273. }
  274. }
  275. // Store all the values in a variable client-side
  276. $aScript = array();
  277. foreach($aHeadersList as $sClassName => $sAttributes)
  278. {
  279. $aScript[] = "'$sClassName':'$sAttributes'";
  280. }
  281. $oPage->add("<script>
  282. var oAttributes = {".implode(',', $aScript)."};
  283. function DisplayFields(className)
  284. {
  285. $('#fields').val(oAttributes[className]);
  286. }
  287. </script>\n");
  288. $oPage->add_ready_script("$('#select_class').change( function() {DisplayFields(this.value);} );");
  289. $oPage->add("Fields for this object: <textarea readonly id=fields rows=\"3\" cols=\"60\" wrap=\"soft\">$sCurrentList</textarea>");
  290. }
  291. function Do_Format($oPage, $sClass)
  292. {
  293. $oPage->p("<h1>Bulk load from CSV data / step 2</h1>");
  294. $sWiztep = "2_format";
  295. $sCSVData = utils::ReadPostedParam('csvdata');
  296. $oCSVParser = new CSVParser($sCSVData);
  297. $sSep = $oCSVParser->GuessSeparator();
  298. $iSkip = $oCSVParser->GuessSkipLines();
  299. // No data ?
  300. $aData = $oCSVParser->ToArray(null);
  301. $iTarget = count($aData);
  302. if ($iTarget == 0)
  303. {
  304. $oPage->add("Empty data set...");
  305. $oPage->add("<form method=\"post\" action=\"\">");
  306. $oPage->add("<input type=\"hidden\" name=\"csvdata\" value=\"$sCSVData\">");
  307. $oPage->add("<input type=\"hidden\" name=\"fromwiztep\" value=\"$sWiztep\">");
  308. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Back\">");
  309. $oPage->add("</form>");
  310. }
  311. // Guess the format :
  312. $oPage->p("Guessed separator: '<strong>$sSep</strong>' (ASCII=".ord($sSep).")");
  313. $oPage->p("Guessed # of lines to skip: $iSkip");
  314. $oPage->p("Target: $iTarget rows");
  315. $oPage->Add("<form method=\"post\" action=\"\">");
  316. ShowTableForm($oPage, $oCSVParser, $sClass);
  317. $oPage->Add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  318. $oPage->Add("<input type=\"hidden\" name=\"csvdata\" value=\"$sCSVData\">");
  319. $oPage->Add("<input type=\"hidden\" name=\"separator\" value=\"$sSep\">");
  320. $oPage->Add("<input type=\"hidden\" name=\"skiplines\" value=\"$iSkip\">");
  321. $oPage->Add("<input type=\"hidden\" name=\"fromwiztep\" value=\"$sWiztep\">");
  322. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Back\">");
  323. $oPage->Add("<input type=\"submit\" name=\"todo\" value=\"Next\">");
  324. $oPage->Add("</form>");
  325. }
  326. function DoProcessOrVerify($oPage, $sClass, CMDBChange $oChange = null)
  327. {
  328. $sCSVData = utils::ReadPostedParam('csvdata');
  329. $sSep = utils::ReadPostedParam('separator');
  330. $iSkip = utils::ReadPostedParam('skiplines');
  331. $aFieldMap = utils::ReadPostedParam('fmap');
  332. $aIsReconcKey = utils::ReadPostedParam('iskey');
  333. $oCSVParser = new CSVParser($sCSVData);
  334. $oCSVParser->SetSeparator($sSep);
  335. $oCSVParser->SetSkipLines($iSkip);
  336. $aData = $oCSVParser->ToArray(null);
  337. $iTarget = count($aData);
  338. $oPage->p("<h2>Goal summary</h2>");
  339. $oPage->p("Target: $iTarget rows");
  340. $aSampleData = $oCSVParser->ToArray(array_keys($aFieldMap), 5);
  341. $aDisplayConfig = array();
  342. $aExtKeys = array();
  343. foreach ($aFieldMap as $sFieldId=>$sColDesc)
  344. {
  345. if (array_key_exists($sFieldId, $aIsReconcKey))
  346. {
  347. $sReconcKey = " [search]";
  348. }
  349. else
  350. {
  351. $sReconcKey = "";
  352. }
  353. if ($sColDesc == "pkey")
  354. {
  355. $aDisplayConfig[$sFieldId] = array("label"=>"Private key $sReconcKey", "description"=>"blah pkey");
  356. }
  357. elseif ($sColDesc == "__none__")
  358. {
  359. // Skip !
  360. }
  361. else if (MetaModel::IsValidAttCode($sClass, $sColDesc))
  362. {
  363. $sAttCode = $sColDesc;
  364. $sLabel = MetaModel::GetAttributeDef($sClass, $sAttCode)->GetLabel();
  365. $aDisplayConfig[$sFieldId] = array("label"=>"$sLabel$sReconcKey", "description"=>"");
  366. if (MetaModel::IsValidKeyAttCode($sClass, $sAttCode))
  367. {
  368. $aExtKeys[] = $sAttCode;
  369. }
  370. }
  371. elseif (IsExtKeyField($sColDesc))
  372. {
  373. list($sExtKeyAttCode, $sForeignAttCode) = GetExtKeyFieldCodes($sColDesc);
  374. $aDisplayConfig[$sFieldId] = array("label"=>MakeExtFieldLabel($sClass, $sExtKeyAttCode, $sForeignAttCode), "description"=>"");
  375. $aExtKeys[] = $sExtKeyAttCode;
  376. }
  377. else
  378. {
  379. // ???
  380. $aDisplayConfig[$sFieldId] = array("label"=>"-?-?-$sColDesc-?-?-", "description"=>"");
  381. }
  382. }
  383. $oPage->table($aDisplayConfig, $aSampleData);
  384. if ($oChange)
  385. {
  386. $oPage->p("<h2>Processing...</h2>");
  387. }
  388. else
  389. {
  390. $oPage->p("<h2>Column consistency</h2>");
  391. $aMissingKeys = array();
  392. foreach (MetaModel::GetExternalKeys($sClass) as $sExtKeyAttCode => $oExtKey)
  393. {
  394. if (!in_array($sExtKeyAttCode, $aExtKeys) && !$oExtKey->IsNullAllowed())
  395. {
  396. $aMissingKeys[$sExtKeyAttCode] = $oExtKey;
  397. }
  398. }
  399. if (count($aMissingKeys) > 0)
  400. {
  401. $oPage->p("Warning: the objects could not be created, due to some missing mandatory external keys in the field list: ");
  402. $oPage->p("<ul>");
  403. foreach($aMissingKeys as $sAttCode => $oAttDef)
  404. {
  405. $oPage->p("<li>".$oAttDef->GetLabel()."</li>");
  406. }
  407. $oPage->p("</ul>");
  408. }
  409. $oPage->p("<h2>Check...</h2>");
  410. }
  411. ProcessData($oPage, $sClass, $oCSVParser, $aFieldMap, $aIsReconcKey, $oChange);
  412. $oPage->add("<form method=\"post\" action=\"\">");
  413. $oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">");
  414. $oPage->add("<input type=\"hidden\" name=\"csvdata\" value=\"$sCSVData\">");
  415. $oPage->add("<input type=\"hidden\" name=\"separator\" value=\"$sSep\">");
  416. $oPage->add("<input type=\"hidden\" name=\"skiplines\" value=\"$iSkip\">");
  417. $oPage->add_input_hidden("fmap", $aFieldMap);
  418. $oPage->add_input_hidden("iskey", $aIsReconcKey);
  419. return;
  420. }
  421. function Do_Verify($oPage, $sClass)
  422. {
  423. $oPage->p("<h1>Bulk load from CSV data / step 3</h1>");
  424. $sWiztep = "3_verify";
  425. DoProcessOrVerify($oPage, $sClass, null);
  426. // FORM started by DoProcessOrVerify...
  427. $oPage->add("<input type=\"hidden\" name=\"fromwiztep\" value=\"$sWiztep\">");
  428. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Back\">");
  429. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Next\">");
  430. $oPage->add("</form>");
  431. }
  432. function Do_Execute($oPage, $sClass)
  433. {
  434. $oPage->p("<h1>Bulk load from CSV data / step 4</h1>");
  435. $sWiztep = "4_execute";
  436. $oMyChange = MetaModel::NewObject("CMDBChange");
  437. $oMyChange->Set("date", time());
  438. $oMyChange->Set("userinfo", "CSV Import");
  439. $iChangeId = $oMyChange->DBInsert();
  440. DoProcessOrVerify($oPage, $sClass, $oMyChange);
  441. // FORM started by DoProcessOrVerify...
  442. $oPage->add("<input type=\"hidden\" name=\"fromwiztep\" value=\"$sWiztep\">");
  443. $oPage->add("<input type=\"submit\" name=\"todo\" value=\"Back\">");
  444. $oPage->add("</form>");
  445. }
  446. ///////////////////////////////////////////////////////////////////////////////////////////////////
  447. //
  448. // M a i n P r o g r a m
  449. //
  450. ///////////////////////////////////////////////////////////////////////////////////////////////////
  451. $sFromWiztep = utils::ReadPostedParam('fromwiztep', '');
  452. $sClass = utils::ReadPostedParam('class', '');
  453. $sTodo = utils::ReadPostedParam('todo', '');
  454. switch($sFromWiztep)
  455. {
  456. case '':
  457. Do_Welcome($oPage, $sClass);
  458. break;
  459. case '1_welcome':
  460. if ($sTodo == "Next") Do_Format($oPage, $sClass);
  461. else trigger_error("Wrong argument todo='$sTodo'", E_USER_ERROR);
  462. break;
  463. case '2_format':
  464. if ($sTodo == "Next") Do_Verify($oPage, $sClass);
  465. else Do_Welcome($oPage, $sClass);
  466. break;
  467. case '3_verify':
  468. if ($sTodo == "Next") Do_Execute($oPage, $sClass);
  469. else Do_Format($oPage, $sClass);
  470. break;
  471. case '4_execute':
  472. if ($sTodo == "Next") trigger_error("Wrong argument todo='$sTodo'", E_USER_ERROR);
  473. else Do_Verify($oPage, $sClass);
  474. break;
  475. default:
  476. trigger_error("Wrong argument fromwiztep='$sFromWiztep'", E_USER_ERROR);
  477. }
  478. $oPage->output();
  479. ?>