Пример #1
0
 static function OutputPositionsEditorUpdate($table)
 {
     echo "<hr>REQUEST";
     debug::rrr();
     $stdout = $rightColumn = "";
     $column["left"] = $column["right"] = "";
     $showform = 0;
     // must initiate to FALSE
     $inset_id = NULL;
     $error = $founderror = $lookup = $usedFieldValues = $record = array();
     $usedTableRecords = $tableFields = $foreignFieldValues = array();
     $reqFields = $existingFieldValues = $skipFields = array();
     if (!in_array($table, array("position", "applicant", "hired", "method", "field", "type", "group"))) {
         return "";
     }
     functions::gpc_declare_input("position_id", 0, false);
     functions::gpc_declare_input("new", 0, true);
     functions::gpc_declare_input("update", 0, true);
     functions::gpc_declare_input("edit", 0, true);
     functions::gpc_declare_input("delete", 0, true);
     if ($GLOBALS["position_id"]) {
         $showform = 1;
         functions::gpc_declare_input("table", "position", false);
         //    functions::gpc_declare_input("hired_id",0,false);
         //    functions::gpc_declare_input("position","",false);
         //    functions::gpc_declare_input("description","",false);
         //    functions::gpc_declare_input("sortorder",NULL,false);
         //    functions::gpc_declare_input("group_id",0,false);
         self::initiatePositionsClass();
         // --> $GLOBALS["positionsClass"]
         // -- Create $usedFieldValues
         foreach ($GLOBALS["positionsClass"]->getCampaigns() as $recs) {
             foreach ($recs as $fieldname => $value) {
                 //TODO: adapt to 'position' table
                 $usedFieldValues[$fieldname][] = $value;
             }
         }
         // -- Create $usedFieldValues
         $usedTableRecords = $GLOBALS["positionsClass"]->getCampaigns("", "", $GLOBALS["position_id"]);
         // -- Create $tableFields
         $tableFields["position"] = $GLOBALS["positionsClass"]->getFieldList("position");
         $tableFields["hired"] = $GLOBALS["positionsClass"]->getFieldList("hired");
         if (!empty($tableFields)) {
             foreach ($tableFields as $tbl => $array) {
                 foreach ($array as $fieldname) {
                     echo "<br>*{$fieldname}";
                     if ($tbl != "hired") {
                         functions::gpc_declare_input($fieldname, "", false);
                     }
                 }
             }
         }
         /*
         	  // -- Create $foreignFieldValues
         	  switch ($table) {
         		case "type":
         		  $foreignFieldValues = $GLOBALS["positionsClass"]->getUniqueFieldValues("position","type_id");
         		  break;
         		case "field":
         		  $foreignFieldValues = $GLOBALS["positionsClass"]->getUniqueFieldValues("hired","field_id");
         		  break;
         		case "group":
         		  $foreignFieldValues = $GLOBALS["positionsClass"]->getUniqueFieldValues("type","group_id");
         		  break;
         	  } // end switch
         */
         // -- Create $lookup
         if (!empty($tableFields)) {
             foreach ($tableFields as $tbl => $array) {
                 foreach ($array as $fieldname) {
                     $descfield = in_array($fieldname, array("position_id")) ? "title" : "description";
                     if (preg_match("#^(.*)_id\$#", $fieldname, $res) && $fieldname != $table . "_id" && !empty($res[1])) {
                         foreach ($GLOBALS["positionsClass"]->getLookupTable($res[1]) as $array) {
                             if (!empty($array[$descfield])) {
                                 $lookup[$tbl][$fieldname][$array[$res[1] . "_id"]] = $array[$descfield];
                             }
                         }
                     }
                 }
             }
         }
         // -- Create $hiddenFields
         $hiddenFields = array("position_id");
         // ----------------------------------------------
         $tbl = "hired";
         $reqFields = array("firstname", "lastname");
         $existingFieldValues = $usedTableRecords[$tbl];
         $skipFields = array($tbl . "_id");
         $tbl = "hired";
         $form["tableName"] = $tbl;
         $form["allFields"] = $GLOBALS["positionsClass"]->getFieldList($tbl);
         // $tableFields[$tbl];
         $form["requiredFields"] = array("firstname", "lastname");
         $form["skipFields"] = array($tbl . "_id");
         $form["defaultValues"] = $GLOBALS["positionsClass"]->getLookupTable($tbl);
         // $usedTableRecords[$tbl];
         $form["type"]["select"] = array("field_id");
         $form["type"]["hidden"] = array("position_id");
         echo "<hr>inputFields[{$tbl}]<br>";
         $inputFields[$tbl] = array();
         if (isset($form["allFields"])) {
             foreach ($form["allFields"] as $fieldname) {
                 $default = isset($form["defaultValues"][$fieldname]) ? $form["defaultValues"][$fieldname] : "";
                 functions::gpc_declare_input($fieldname, $default, false);
                 $inputFields[$tbl][$fieldname]["value"] = $GLOBALS[$fieldname];
                 /*
                           $inputFields[$tbl][$fieldname]["value"] = "";
                           if (!empty($GLOBALS[$fieldname])) {
                             $inputFields[$tbl][$fieldname]["value"] = $GLOBALS[$fieldname];
                           } elseif (isset($existingFieldValues[$fieldname])) {
                             $inputFields[$tbl][$fieldname]["value"] = $existingFieldValues[$fieldname];
                           }
                 */
                 echo "<br>%%% " . $fieldname . "='" . $inputFields[$tbl][$fieldname]["value"] . "'; GLOBALS=" . (isset($GLOBALS[$fieldname]) ? $GLOBALS[$fieldname] : "") . "; REQUEST=" . (isset($_REQUEST[$fieldname]) ? $_REQUEST[$fieldname] : "");
                 if (in_array($fieldname, $form["type"]["hidden"])) {
                     $inputFields[$tbl][$fieldname]["type"] = "hidden";
                     $inputFields[$tbl][$fieldname]["fixedvalue"] = $usedTableRecords["regend"] . " [" . $usedTableRecords["title"] . "]";
                 } elseif (in_array($fieldname, $form["type"]["select"])) {
                     $inputFields[$tbl][$fieldname]["type"] = "select";
                     if (isset($lookup[$tbl][$fieldname])) {
                         $inputFields[$tbl][$fieldname]["list"] = $lookup[$tbl][$fieldname];
                     }
                 } else {
                     // text fields, leave as default case without explicit listing of field names
                     $inputFields[$tbl][$fieldname]["type"] = "text";
                 }
                 $inputFields[$tbl][$fieldname]["skip"] = in_array($fieldname, $skipFields) ? 1 : 0;
                 $inputFields[$tbl][$fieldname]["error"] = 0;
                 $inputFields[$tbl][$fieldname]["required"] = in_array($fieldname, $reqFields) ? 1 : 0;
             }
         }
         // ----------------------------------------------
         // ----------------------------------------------
         $tbl = "position";
         $reqFields = array("title", "regend", "method_id", "type_id");
         $existingFieldValues = $usedTableRecords;
         $skipFields = array($tbl . "_id");
         echo "<hr>inputFields[{$tbl}]<br>";
         $inputFields[$tbl] = array();
         foreach ($tableFields[$tbl] as $fieldname) {
             if (!in_array($fieldname, $skipFields)) {
                 $inputFields[$tbl][$fieldname]["value"] = "";
                 if (!empty($GLOBALS[$fieldname])) {
                     $inputFields[$tbl][$fieldname]["value"] = $GLOBALS[$fieldname];
                 } elseif (!$GLOBALS["update"] && isset($existingFieldValues[$fieldname])) {
                     $inputFields[$tbl][$fieldname]["value"] = $existingFieldValues[$fieldname];
                 }
                 echo "<br>%%% " . $fieldname . "='" . $inputFields[$tbl][$fieldname]["value"] . "'; GLOBALS=" . (isset($GLOBALS[$fieldname]) ? $GLOBALS[$fieldname] : "") . "; REQUEST=" . (isset($_REQUEST[$fieldname]) ? $_REQUEST[$fieldname] : "");
                 if (in_array($fieldname, array("method_id", "type_id"))) {
                     $inputFields[$tbl][$fieldname]["type"] = "select";
                     if (isset($lookup[$tbl][$fieldname])) {
                         $inputFields[$tbl][$fieldname]["list"] = $lookup[$tbl][$fieldname];
                     }
                     //            $inputFields[$tbl][$fieldname]["fixedvalue"]  = $usedTableRecords["regend"] . " [". $usedTableRecords["title"] . "]";
                 } elseif (in_array($fieldname, array("description"))) {
                     $inputFields[$tbl][$fieldname]["type"] = "textarea";
                 } elseif (in_array($fieldname, array("nohired", "public"))) {
                     $inputFields[$tbl][$fieldname]["type"] = "checkbox";
                     $inputFields[$tbl][$fieldname]["value"] = !empty($inputFields[$tbl][$fieldname]["value"]) ? 1 : 0;
                 } else {
                     // text fields, leave as default case without explicit listing of field names
                     $inputFields[$tbl][$fieldname]["type"] = "text";
                 }
                 $inputFields[$tbl][$fieldname]["error"] = 0;
                 $inputFields[$tbl][$fieldname]["required"] = in_array($fieldname, $reqFields) ? 1 : 0;
             }
         }
         // ----------------------------------------------
         echo "<hr>usedTableRecords";
         debug::rr($usedTableRecords);
         //TODO: echo "<hr>usedFieldValues"; debug::rr($usedFieldValues);
         echo "<hr>foreignFieldValues";
         debug::rr($foreignFieldValues);
         echo "<hr>tableFields";
         debug::rr($tableFields);
         echo "<hr>lookup";
         debug::rr($lookup);
     }
     // -----------------------------------------------------------
     // -- Insert new lookup record
     // -----------------------------------------------------------
     if ($GLOBALS["new"] || $GLOBALS["update"]) {
         $stdout .= ($GLOBALS["update"] ? "UPDATE" : "NEW") . " RECORD";
         // -- Check for errors
         if ($GLOBALS["table"] == "position") {
             foreach (array("title", "regend") as $fieldname) {
                 if (empty($GLOBALS[$fieldname])) {
                     $founderror[$fieldname] = 1;
                     $error[] = "Please enter a " . ucfirst($fieldname) . ".";
                 }
             }
             if (!functions::isDate($GLOBALS["regend"], "Y-m-d")) {
                 $founderror["regend"] = 1;
                 $error[] = "Please enter a Regend in the form 'YYYY-mm-dd'.";
             }
             foreach (array("method_id", "type_id") as $fieldname) {
                 if (isset($GLOBALS[$fieldname]) && $GLOBALS[$fieldname] < 0) {
                     $founderror[$fieldname] = 1;
                     $error[] = "Please select a " . ucfirst(str_replace("_id", "", $fieldname)) . ".";
                 }
             }
             /*
                   if (!empty($GLOBALS["sortorder"])
                       && (!is_numeric($GLOBALS["sortorder"]) || ((int) $GLOBALS["sortorder"] != $GLOBALS["sortorder"]) )
                   ) {
                     $founderror["sortorder"] = 1;
                     $error[] =
                       "The sortorder must be an integer.";
                   }
             */
             foreach ($tableFields[$GLOBALS["table"]] as $fieldname) {
                 /*
                         if (in_array($fieldname,array("method","group"))
                             && (preg_match("#\W#",$value))
                         ) {
                           $founderror[$fieldname] = 1;
                           $error[] =
                             "The field '".$fieldname."' must only contain ASCII 7 alphanumeric characters.";
                         }
                 */
                 /*
                         if ($GLOBALS["new"]
                             && !empty($value)
                             && (strpos($fieldname,"_id")===FALSE)
                             && isset($usedFieldValues[$fieldname])
                             && in_array($value,$usedFieldValues[$fieldname])
                         ) {
                           $founderror[$fieldname] = 1;
                           $error[] =
                             "There is already a record with '".$fieldname."'='".$value."'.";
                         }
                 */
             }
         } elseif ($GLOBALS["table"] == "hired") {
         }
         echo "<hr>founderror";
         debug::rr($founderror);
         echo "<br>error";
         debug::rr($error);
         // -- If errors found, display form with error messages and warnings
         if (!empty($error)) {
             $column["left"] .= functions::boxMessage("error", $error);
             $showform = 1;
         }
         if (!empty($warning)) {
             $column["left"] .= functions::boxMessage("warning", $warning);
             $showform = 1;
         }
         // -- Store any error information for output of form
         if ($showform) {
             foreach ($tableFields[$GLOBALS["table"]] as $fieldname) {
                 if ($fieldname != $GLOBALS["table"] . "_id") {
                     $inputFields[$GLOBALS["table"]][$fieldname]["error"] = isset($founderror[$fieldname]) ? (bool) $founderror[$fieldname] : 0;
                 }
             }
         }
         // -- If no errors, update database with submitted data
         if (empty($error) && isset($GLOBALS["table"]) && isset($tableFields[$GLOBALS["table"]])) {
             echo "...value";
             debug::rr($inputFields[$GLOBALS["table"]]);
             foreach ($tableFields[$GLOBALS["table"]] as $fieldname) {
                 if (isset($GLOBALS[$fieldname]) && $fieldname != $table . "_id") {
                     $record[$fieldname] = $inputFields[$GLOBALS["table"]][$fieldname]["value"];
                 } elseif ($GLOBALS["update"] && $fieldname == $table . "_id" && isset($GLOBALS["position_id"])) {
                     $record[$fieldname] = $GLOBALS["position_id"];
                 }
             }
             echo "<br><h2>RECORD</h2>";
             debug::rr($record);
             $res = 0;
             if (!empty($record)) {
                 if ($GLOBALS["new"]) {
                     $res = $GLOBALS["positionsClass"]->insertLookup($GLOBALS["table"], $record);
                     // false or $article_id
                 } elseif ($GLOBALS["update"]) {
                     echo "UUU" . $table;
                     $res = $GLOBALS["positionsClass"]->updateRecord($GLOBALS["table"], $record);
                     // boolean
                 }
             }
             if (!$res) {
                 $column["left"] .= "\r\n" . functions::boxMessage("error", "Could not save the new record to table '" . $table . "'") . "\r\n";
                 $showform = 1;
             } else {
                 if ($GLOBALS["new"]) {
                     $column["left"] .= "\r\n" . functions::boxMessage("confirm", "The new record was successfully saved to table '" . $table . "'.") . "\r\n";
                 } elseif ($GLOBALS["update"]) {
                     $column["left"] .= "\r\n" . functions::boxMessage("confirm", "The record in table '" . $table . "' was successfully updated.") . "\r\n";
                 }
                 $showform = 1;
                 $usedTableRecords = $GLOBALS["positionsClass"]->getCampaigns("", "", $GLOBALS["position_id"]);
                 $GLOBALS["update"] = 0;
             }
         }
         // end if (empty($error))
     }
     // end "new" or "update"
     // -----------------------------------------------------------
     // -- Edit existing record
     // -----------------------------------------------------------
     if ($GLOBALS["update"]) {
     }
     // end "edit"
     // -----------------------------------------------------------
     // -- Delete existing record
     // -----------------------------------------------------------
     if ($GLOBALS["delete"]) {
         $stdout .= "DELETE";
         /*
               // -- Check for errors
         
               if (!empty($GLOBALS["position_id"]) && !empty($GLOBALS["table"])) {
                 switch ($GLOBALS["table"]) {
                   case "type":
                     $duplicate = $GLOBALS["positionsClass"]->getOccurenceOfFieldValue("position","type_id",$GLOBALS["position_id"]);
                     break;
                   case "field":
                     $duplicate = $GLOBALS["positionsClass"]->getOccurenceOfFieldValue("hired","field_id",$GLOBALS["position_id"]);
                     break;
                   case "group":
                     $duplicate = $GLOBALS["positionsClass"]->getOccurenceOfFieldValue("type","group_id",$GLOBALS["position_id"]);
                     break;
                 } // end switch
         
         		if ($duplicate) {
         		  $founderror[$GLOBALS["position_id"]] = 1;
         		  $error[] =
         			"The selected record cannot be removed since it is in use.";
         		}
               }
         
         	  // -- If errors found, display form with error messages and warnings
         
         	  if (!empty($error)) {
         		$rightColumn .= functions::boxMessage("error",$error);
         		$showform = 1;
         	  }
         	  if (!empty($warning)) {
         		$rightColumn .= functions::boxMessage("warning",$warning);
         		$showform = 1;
         	  }
         
               // -- If no errors, update database with submitted data
         
         	  if (empty($error)) {
         
                 $record[$GLOBALS["table"]."_id"] = $GLOBALS["position_id"];
                 $res = $GLOBALS["positionsClass"]->deleteRecord($table,$record); // false or $article_id
         
                 if (!$res) {
                   $rightColumn .=
                     "\r\n" .
                     functions::boxMessage("error","Could not delete the record from table '" . $table . "'") .
                     //PADDED_HR .
                     "\r\n";
                   $showform = 1;
                 } else {
                   $rightColumn .=
                     "\r\n" .
                     functions::boxMessage("confirm","The record was successfully deleted from table '" . $table . "'.") .
                     //PADDED_HR .
                     "\r\n";
                   $showform = 1;
                   $usedTableRecords = $GLOBALS["positionsClass"]->getLookupTable($table);
                   unset($GLOBALS[$fieldname]);
                 }
         
               } // end if (empty($error))
         */
     }
     // end "delete"
     // -----------------------------------------------------------
     // -- Output forms and results
     // -----------------------------------------------------------
     // -- Display dropdown list
     $stdout .= self::outputPositionsDropdown("data");
     if ($showform) {
         // -- Left column -----------------------------------------
         /*
         if ($GLOBALS["edit"]) {
               $column["left"] .= self::outputFormUpdate("hired",$inputFields["hired"],$hiddenFields);
         } else { // if (!$GLOBALS["edit"])
               $column["left"] .= self::outputFormUpdate("position",$inputFields["position"],$hiddenFields);
         } // end if "edit"
         */
         $column["left"] .= !empty($GLOBALS["table"]) && isset($inputFields[$GLOBALS["table"]]) ? self::outputFormUpdate($GLOBALS["table"], $inputFields[$GLOBALS["table"]], $hiddenFields) : "";
         // -- Right column -----------------------------------------
         // Position still open
         // Closed - under evaluation
         // No-one hired
         // Hired were: ...
         // -------------------------------------------------------------
         //TODO:
         $tbl = "hidden";
         $tblRecords["hidden"] = $GLOBALS["positionsClass"]->getLookupTable("hired", array("position_id" => $GLOBALS["position_id"]));
         /*
             $tblRecords[$tbl] = $GLOBALS["positionsClass"]->getLookupTable($tbl);
             //$usedTableRecords
             //foreach ($tblRecords[$tbl] as $recs) {
             //  foreach ($recs as $fieldname => $value) {
             //    $usedFieldValues[$fieldname][] = $value;
             //  }
             //}
         */
         /*
             $tableFields = $GLOBALS["positionsClass"]->getFieldList($table);
         */
         $foreignFieldValues["hidden"] = array();
         /*
             switch ($tbl) {
               case "type":
                 $foreignFieldValues[$tbl] = $GLOBALS["positionsClass"]->getUniqueFieldValues("position","type_id");
                 break;
               case "field":
                 $foreignFieldValues[$tbl] = $GLOBALS["positionsClass"]->getUniqueFieldValues("hired","field_id");
                 break;
               case "group":
                 $foreignFieldValues[$tbl] = $GLOBALS["positionsClass"]->getUniqueFieldValues("type","group_id");
                 break;
             } // end switch
         */
         $hiddenFields["hidden"] = array("hired_id", "position_id", "field_id");
         /*
             $hiddenFields[$tbl][] = $tbl."_id";
         */
         // --------------------
         $records = array();
         if (!empty($tblRecords[$tbl])) {
             foreach ($tblRecords[$tbl] as $arr) {
                 $record = array();
                 foreach ($arr as $fieldname => $value) {
                     if (!in_array($fieldname, $hiddenFields[$tbl])) {
                         $record["_data"][$fieldname] = $value;
                     }
                     $record["_id"] = isset($arr[$tbl . "_id"]) ? $arr[$tbl . "_id"] : -1;
                     $record["_delete"] = in_array($record["_id"], $foreignFieldValues[$tbl]) ? 0 : 1;
                     $qstring = array();
                     foreach ($arr as $fieldname => $value) {
                         $qstring[] = urlencode($fieldname) . "=" . urlencode($value);
                     }
                     if (!empty($qstring)) {
                         $record["_qstring"] = join("&amp;", $qstring);
                     }
                 }
                 $records[] = $record;
             }
         }
         // --------------------
         echo "--- foreignFieldValues";
         debug::rr($foreignFieldValues);
         echo "--- tblFields";
         debug::rr($tblFields);
         echo "--- tblValues";
         debug::rr($tblRecords);
         echo "--- hiddenFields";
         debug::rr($hiddenFields);
         echo "--- records";
         debug::rr($records);
         // -------------------------------------------------------------
         $column["right"] .= self::outputFormTable("hired", $records);
         // -- Joint output -----------------------------------------
         $stdout .= PADDED_HR . "\r\n" . "<div class='col c1of2'>\r\n" . "      <h3 class='bottommargin'>Edit Basic Data</h3>\r\n" . $column["left"] . "</div> <div class='col c2of2 divider'>\r\n" . "      <h3 class='bottommargin'>Edit Persons Hired</h3>\r\n" . $column["right"] . "</div><div style='clear:both'><br></div>\r\n" . "\r\n";
     }
     // end if ($showform)
     // --------------------
     return $stdout;
 }
Пример #2
0
 private static function drawArticleEditorNew()
 {
     $stdout = "";
     $showform = 1;
     $error = $warning = $founderror = array();
     $article_id = $GLOBALS["aid"];
     $GLOBALS["aid"] = 0;
     // -----------------------------------------------------------
     functions::gpc_declare_input("headline", "", false);
     functions::gpc_declare_input("body", "", false, array(), false, false);
     functions::gpc_declare_input("date", "", false);
     functions::gpc_declare_input("author", NEWS_NOAUTHOR, false);
     functions::gpc_declare_input("section", 0, false);
     functions::gpc_declare_input("country", array(), false);
     functions::gpc_declare_input("category", array(), false);
     functions::gpc_declare_input("articlestatus", 0, false);
     // -----------------------------------------------------------
     if (empty($GLOBALS["headline"])) {
         $founderror["headline"] = 1;
         $error[] = "Please write a non-empty headline.";
     }
     if (empty($GLOBALS["body"])) {
         $founderror["body"] = 1;
         $error[] = "Please enter a non-empty article body.";
     }
     if (!functions::isDate($GLOBALS["date"], "Y-m-d")) {
         $founderror["date"] = 1;
         $error[] = "There is something strange with the date " . "'<strong><em>" . $GLOBALS["date"] . "</em></strong>'.";
     }
     if ($GLOBALS["author"] == NEWS_NOAUTHOR) {
         $founderror["author"] = 1;
         $warning[] = "No author selected. (<em>Optional field</em>.)";
     }
     if (empty($GLOBALS["section"])) {
         $founderror["section"] = 1;
         $warning[] = "No section selected. (<em>Optional field; Can be selected later, or re-edit this article now</em>.)";
     } elseif (!is_numeric($GLOBALS["section"])) {
         $founderror["section"] = 1;
         $error[] = "There is something strange with a section.";
     } elseif (is_array($GLOBALS["section"])) {
         $mess = "";
         foreach ($GLOBALS["section"] as $key => $val) {
             if (!is_numeric($val)) {
                 $founderror["section"] = 1;
                 $mess = "There is something strange with a section.";
             }
         }
         if (!empty($mess)) {
             $error[] = $mess;
         }
     }
     if (is_array($GLOBALS["country"])) {
         $mess = "";
         foreach ($GLOBALS["country"] as $key => $val) {
             if (!in_array($val, array("DK", "FI", "IS", "NO", "SE"))) {
                 $founderror["country"] = 1;
                 $mess = "There is something strange with a country.";
             }
         }
         if (!empty($mess)) {
             $error[] = $mess;
         }
     }
     if (empty($GLOBALS["category"])) {
         $founderror["category"] = 1;
         $warning[] = "No category selected. (<em>Optional field</em>.)";
     } else {
         $mess = "";
         foreach ($GLOBALS["category"] as $key => $val) {
             if (!is_numeric($val)) {
                 $founderror["category"] = 1;
                 $mess = "There is something strange with a category.";
             }
         }
         if (!empty($mess)) {
             $error[] = $mess;
         }
     }
     // -----------------------------------------------------------
     // -- If errors found, display form with error messages and warnings
     if (!empty($error)) {
         $stdout .= functions::boxMessage("error", $error);
         $showform = 1;
     }
     if (!empty($warning)) {
         $stdout .= functions::boxMessage("warning", $warning);
         $showform = 1;
     }
     if (!empty($error) || !empty($error)) {
         $stdout .= PADDED_HR;
     }
     // -- If no errors, update database with submitted data
     if (empty($error)) {
         self::initiateNewsClass();
         $record = array("article_id" => $article_id, "headline" => $GLOBALS["headline"], "body" => $GLOBALS["body"], "date" => $GLOBALS["date"], "author" => $GLOBALS["author"], "section" => $GLOBALS["section"], "country" => $GLOBALS["country"], "category" => $GLOBALS["category"], "articlestatus" => $GLOBALS["articlestatus"]);
         $res = $record["article_id"] ? $GLOBALS["newsClass"]->updateArticle($record) : $GLOBALS["newsClass"]->insertArticle($record);
         // false or $article_id
         if (!$res) {
             $stdout .= "\r\n" . functions::boxMessage("error", "Could not save the new article &quot;" . $GLOBALS["headline"] . "&quot;</strong>.") . PADDED_HR . "\r\n";
             $showform = 1;
         } else {
             $text1 = $article_id ? "" : "new";
             $text2 = $article_id ? "updated" : "saved";
             $stdout .= "\r\n" . functions::boxMessage("confirm", "The " . $text1 . " article &quot;<strong>" . $GLOBALS["headline"] . "</strong>&quot; was successfully " . $text2 . ".") . "<p class='largefont'>&#171; <a href='" . str_replace("/single", "", $_SERVER["PHP_SELF"]) . "'>" . "Back to Article List</a></p>\r\n" . PADDED_HR . "\r\n";
             if (!$article_id && is_numeric($res) && $res > 0) {
                 $article_id = $res;
             }
             // --> $dataArticle[article_id] = article_record
             $dataArticle = $GLOBALS["newsClass"]->getArticle(NEWS_ANYUNPUBLISHED, $article_id);
             if (is_array($dataArticle) && !empty($dataArticle)) {
                 $stdout .= "<div class='newslist col left2of3'>\r\n" . "  <fieldset style='width:105%;border:1px solid #ccc'>\r\n" . "    <legend>Article #" . $article_id . "</legend>\r\n" . news::drawArticle($dataArticle, 0, 0, "", 1) . "  </fieldset>\r\n" . "  <p style='margin-bottom:0'>" . "<a href='" . str_replace("/index.php", "", $_SERVER["PHP_SELF"]) . "/index.php?aid=" . $article_id . "' " . "class='fakenewsbutton'" . ">EDIT THIS ARTICLE AGAIN</a></p>\r\n" . "\r\n" . "</div>\r\n";
             }
             $showform = 0;
         }
     }
     // end if ($error)
     // -----------------------------------------------------------
     return array($stdout, $founderror, $showform);
 }