<?
/*****************************************************************************
* create_result.php : Processes create.php form
*****************************************************************************
* $Id: create_result.php,v 1.4 2000/08/11 15:16:43 massiot Exp $
*****************************************************************************
* ZBase - a gateway between the database and the WWW
* Copyright (c) 1999 The ZBase team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
require("srv_html.inc");
srv_init();
srv_header(srv_str("html", "create_result_title"));
/* Use a form object to retrieve the properties of the tables we work on. */
$form = new form;
/* Use a result object to show the results. */
$RESULT_OBJ = new result;
$RESULT_OBJ->rlt_begin();
$form_attr = $form->form_getattr();
if ($form_attr["parallelize"]) {
/* The queries can be performed simultaneously (no query will modify
* something another query needs). */
/* First step : Retrieve/Verify */
$nb = $form->form_getnb();
for ($i = 0; $i < $nb; $i++) {
$attributes = $form->form_getobj();
srv_include($attributes["name"]);
$roots[$i] = new $attributes["name"];
/* such an object cannot be "omitted" */
$roots[$i]->create_retrieve($form, $attributes["raw"]);
if ($ZB_ERROR)
break;
/* Verify the object */
$roots[$i]->create_setup();
$RESULT_OBJ->rlt_addroot($roots[$i]->result_id);
$roots[$i]->create_verify();
if ($ZB_ERROR)
break;
/* Build the dependances */
$roots[$i]->create_maketree();
if ($ZB_ERROR)
break;
}
if (!$ZB_ERROR) {
/* Second step : Phase 1 */
for ($i = 0; $i < $nb; $i++) {
$roots[$i]->create_phase1();
if ($ZB_ERROR)
break;
}
if (!$ZB_ERROR) {
/* Third step : Phase 2 */
for ($i = 0; $i < $nb; $i++) {
$roots[$i]->create_phase2();
if ($ZB_ERROR)
break;
}
if (!$ZB_ERROR) {
/* Fourth step : Commit */
for ($i = $nb - 1; $i >= 0; $i--) {
$roots[$i]->create_commit();
if ($ZB_ERROR)
break;
}
} /* Fourth step */
} /* Third step */
if ($ZB_ERROR) {
/* Rollback everything */
for ($i = $nb - 1; $i >= 0; $i--) {
$roots[$i]->create_rollback();
}
}
} /* Second step */
} else {
$nb = $form->form_getnb();
for ($i = 0; $i < $nb; $i++) {
$attributes = $form->form_getobj();
srv_include($attributes["name"]);
$roots[$i] = new $attributes["name"];
/* such an object cannot be "omitted" */
$roots[$i]->create_retrieve($form, $attributes["raw"]);
if ($ZB_ERROR)
break;
/* Create the object */
$roots[$i]->create_setup();
$RESULT_OBJ->rlt_addroot($roots[$i]->result_id);
$roots[$i]->create_verify();
if ($ZB_ERROR)
break;
$roots[$i]->create_maketree();
if ($ZB_ERROR)
break;
$roots[$i]->create_phase1();
if ($ZB_ERROR)
break;
$roots[$i]->create_phase2();
if ($ZB_ERROR)
break;
}
if (!$ZB_ERROR) {
/* Validate all modifications */
for ($i = $nb - 1; $i >= 0; $i--) {
$roots[$i]->create_commit();
if ($ZB_ERROR)
break;
}
}
if ($ZB_ERROR) {
/* Cancel all modifications */
for ($i = $nb - 1; $i >= 0; $i--) {
if ($roots[$i])
$roots[$i]->create_rollback();
}
}
}
$RESULT_OBJ->rlt_end();
if ($SESSION_OBJ && ($link = srv_retrieve("search_page")))
echo "<center><a href=\"".$link."\">"
.htmlentities(srv_str("html", "previous_search"))
."</a></center>";
if (!$ZB_ERROR) {
$roots[0]->create_afterresult();
}
srv_close();
?>