예제 #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
 public static function outputEventDropdown($extrafields = array(), $text = "timetable", $thedate = "", $noMultiple = FALSE)
 {
     $stdout = "";
     $selectEventsForm = $toggleMultipleEventsForm = $dateForm = "";
     $selectSingleEventForm = $selectJointEventsForm = "";
     $propagateConfids = $propagateMode = "";
     $jointEvents = $confidArray = $standardForms = $extraFieldsForms = array();
     functions::gpc_declare_input("mode", "single", false);
     // "single", "joint", "multiple"
     if ($noMultiple) {
         $GLOBALS["mode"] = "single";
     }
     functions::gpc_declare_input("confid", "", false);
     functions::gpc_declare_input("confid2", "", false);
     // still needed?
     if (isset($GLOBALS["confid"]) && is_array($GLOBALS["confid"]) && $GLOBALS["mode"] == "single") {
         $_REQUEST["confid"] = $GLOBALS["confid"] = array(current($GLOBALS["confid"]));
     }
     if (is_array($GLOBALS["confid"])) {
         $GLOBALS["confid"] = array_unique($GLOBALS["confid"]);
     }
     if (!empty($GLOBALS["confid"])) {
         $confidArray = is_array($GLOBALS["confid"]) ? $GLOBALS["confid"] : array($GLOBALS["confid"]);
     }
     if (IS_TESTSERVER) {
         debug::rrr();
     }
     if (IS_TESTSERVER) {
         debug::rr($confidArray);
     }
     // -----------------------------
     // -- Obtain data
     // -----------------------------
     $data = self::getEventByTime();
     foreach ($confidArray as $confid) {
         if ($confid) {
             $arr = self::getJointEvents($confid);
             if (!empty($arr)) {
                 $jointEvents[$confid] = $arr;
             }
         }
     }
     // -----------------------------
     // -- Define common form elements
     // -----------------------------
     $formStart = "          <form " . "action='" . $_SERVER["PHP_SELF"] . "' " . "method='POST' " . "enctype='multipart/form-data' " . "class='only_online'>\r\n";
     $formEnd = "          </form>\r\n";
     foreach ($confidArray as $i => $confid) {
         if ($confid) {
             $propagateConfids .= "            <input type='hidden' name='confid[" . $i . "]' value='" . $confid . "'>\r\n";
         }
     }
     $propagateMode .= "            <input type='hidden' name='mode' value='" . $GLOBALS["mode"] . "'>\r\n";
     // -----------------------------
     // -- Extra input fields
     // -----------------------------
     if (!empty($extrafields)) {
         foreach ($extrafields as $extrafield) {
             if (in_array($extrafield, array("abstracts", "photos"))) {
                 $theform = "            <p>&#187; Change to display this " . $text . "\r\n" . (isset($_REQUEST["with_abstract"]) ? "            <input type='submit' name='null' " . "value='without " . $extrafield . "'>\r\n" : "            <input type='submit' name='with_abstract' " . "value='with " . $extrafield . "'></p>\r\n");
                 // check event::getDateInterval() for 'confid2': still needed?
                 /*
                           foreach ($confidArray as $i => $confid) {
                             $theform .=
                               "            <input type='hidden' name='confid2[".$i."]' value='" .
                               ( (!$_REQUEST["confid"][$i] && isset($_REQUEST["confid2"][$i])) 
                                   ? $GLOBALS["confid2"][$i] 
                                   : $GLOBALS["confid"][$i] ) .
                               "'>\r\n";
                           }
                 */
                 $extraFieldsForms[] = $theform . $propagateConfids . $propagateMode;
             }
         }
     }
     // -----------------------------
     // -- Date input field
     // -----------------------------
     $dateForm = "";
     if ($GLOBALS["confid"] && !empty($thedate)) {
         $dateForm .= "            <p>&#187; List participants only for this date: " . "<input type='text' name='thedate' value='" . $thedate . "' size='10'>" . " &nbsp;<input type='submit' value='Go!'></p>\r\n" . $propagateConfids . $propagateMode;
     }
     if (!empty($dateForm)) {
         $extraFieldsForms[] = $dateForm;
     }
     // -----------------------------
     // -- Single event selection form content
     // -----------------------------
     $selectSingleEventForm .= "            <select name='confid[]' onchange='submit()' style='font-size:1.1em'>\r\n" . "              <option value='0'>-&#45;- select from list -&#45;-</option>\r\n";
     if (isset($data["current"])) {
         foreach ($data["current"] as $record) {
             foreach ($record as $startdate => $event) {
                 $selectSingleEventForm .= "              <option value='" . $event["id"] . "'" . (in_array($event["id"], $confidArray) ? " selected='selected'" : "") . (strtotime($event["enddate"]) >= time() ? " class='future'>" . $event["title"] : " class='past'>[" . $event["title"] . "]") . "</option>\r\n";
             }
             // end foreach
         }
         // end foreach
     }
     // end if
     $selectSingleEventForm .= "            </select></p>\r\n";
     // -----------------------------
     // -- Joint events selection form content
     // -----------------------------
     $jEvents = current($jointEvents);
     if (!empty($jEvents)) {
         $selectJointEventsForm .= "            <input type='hidden' name='mode' value='joint'>\r\n";
         if (isset($jEvents["parent"]) && !empty($jEvents["parent"])) {
             $selectJointEventsForm .= "            <br><input type='checkbox' name='confid[]' value='" . $jEvents["parent"] . "'" . (in_array($jEvents["parent"], $confidArray) ? " checked='checked'" : "") . "> " . functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getEventTitle', $jEvents["parent"]) . "\r\n";
         }
         if (isset($jEvents["children"])) {
             foreach ($jEvents["children"] as $confid_children) {
                 $selectJointEventsForm .= "            <br><input type='checkbox' name='confid[]' value='" . $confid_children . "'" . (in_array($confid_children, $confidArray) ? " checked='checked'" : "") . "> " . functions::callMethod('fromdb_nwevents', 'fromdb/nwevents', 'getEventTitle', $confid_children) . "\r\n";
             }
         }
         $selectJointEventsForm .= "            <br><input type='submit' value='Show " . $text . " for selected events'></p>\r\n";
     }
     if ($GLOBALS["mode"] == "multiple") {
         // --------------------------------------------
         // -----------------------------
         // -- Multiple events
         // -----------------------------
         $toggleMultipleEventsForm .= "            <p><strong>Select " . "(one or more) " . "Nordita event (s)</strong> for which you want to display the " . $text . ":\r\n";
         if (IS_TESTSERVER) {
             $toggleMultipleEventsForm .= "            <input type='hidden' name='mode' value='single'>\r\n" . "            <p>&#187; <strong>Actually, I would rather</strong> like to be able to\r\n" . "            <input type='submit' value='select single events'> instead.\r\n";
         }
         $toggleMultipleEventsForm .= $propagateConfids . "            </p>\r\n";
         // ------------------
         $selectEventsForm .= "            <p>\r\n";
         if (isset($data["current"])) {
             foreach ($data["current"] as $record) {
                 foreach ($record as $startdate => $event) {
                     $selectEventsForm .= "            <input type='checkbox' name='confid[]' value='" . $event["id"] . "'" . (in_array($event["id"], $confidArray) ? " checked='chekced'" : "") . (strtotime($event["enddate"]) >= time() ? " class='future'>" . $event["title"] : " class='past'>[" . $event["title"] . "]") . "<br>\r\n";
                 }
                 // end foreach
             }
             // end foreach
         }
         // end if
         $selectEventsForm .= "            <input type='hidden' name='mode' value='multiple'>\r\n" . "            <input type='submit' value='Submit selected events'></p>\r\n";
         // ------------------
         $standardForms[] = $toggleMultipleEventsForm;
         $standardForms[] = $selectEventsForm;
     } elseif ($GLOBALS["mode"] == "joint") {
         // select joint events // -------------------------------------
         // -----------------------------
         // -- Joint events
         // -----------------------------
         $selectEventsForm .= $propagateConfids . "            <p>&#187; <strong>Actually, I would rather</strong> like to be able to\r\n" . "            <input type='submit' value='select single events'> instead.</p>\r\n" . "            <input type='hidden' name='mode' value='single'>\r\n";
         if (!empty($selectJointEventsForm)) {
             $selectJointEventsForm = "            <p><strong>Select " . "(one or more) " . "Nordita event (s)</strong> for which you want to display the " . $text . ":\r\n" . $selectJointEventsForm;
         }
         if (IS_TESTSERVER) {
             $toggleMultipleEventsForm .= $propagateConfids . "            <p>&#187; [ON TESTSERVER]: <strong>Actually, I would rather</strong> like to be able to\r\n" . "            <input type='submit' value='select multiple events'> instead.</p>\r\n" . "            <input type='hidden' name='mode' value='multiple'>\r\n";
         }
         // ------------------
         if (!empty($selectJointEventsForm)) {
             $standardForms[] = $selectJointEventsForm;
         }
         $standardForms[] = $selectEventsForm;
         $standardForms[] = $toggleMultipleEventsForm;
     } elseif ($GLOBALS["mode"] == "single") {
         // select single events // -------------------------------------
         // -----------------------------
         // -- Single events
         // -----------------------------
         $selectEventsForm .= "            <p><strong>Select " . (isset($GLOBALS["confid"]) ? "a new " : "the ") . "(single) " . "Nordita event</strong> for which you want to display the " . $text . ":<br>\r\n" . $selectSingleEventForm . $propagateMode;
         if (!empty($selectJointEventsForm)) {
             $selectJointEventsForm = "            <p>&#187; <strong>Actually, I would rather</strong> view the " . $text . " for the following events instead:\r\n" . $selectJointEventsForm;
         }
         if (IS_TESTSERVER) {
             $toggleMultipleEventsForm .= "            <p>&#187; [ON TESTSERVER]: <strong>Actually, I would rather</strong> like to be able to\r\n" . "            <input type='submit' value='select multiple events'> instead.</p>\r\n" . "            <input type='hidden' name='mode' value='multiple'>\r\n" . $propagateConfids;
         }
         // ------------------
         $standardForms[] = $selectEventsForm;
         if (!$noMultiple && !empty($selectJointEventsForm)) {
             $standardForms[] = $selectJointEventsForm;
         }
         if (!$noMultiple) {
             $standardForms[] = $toggleMultipleEventsForm;
         }
     }
     // end if (select single event) // -----------------
     foreach ($standardForms as $i => $data) {
         $standardForms[$i] = $formStart . $data . $formEnd;
     }
     foreach ($extraFieldsForms as $i => $data) {
         $extraFieldsForms[$i] = $formStart . $data . $formEnd;
     }
     // -----------------------------
     $stdout .= "\r\n" . "        <div class='box warning background padding only_online' style='padding-bottom:0'>\r\n" . "\r\n" . implode("\r\n", $standardForms) . "\r\n" . "        </div>\r\n" . "\r\n";
     if (!empty($extraFieldsForms)) {
         $stdout .= "        <div class='box warning background padding only_online' style='padding-bottom:0'>\r\n" . "\r\n" . implode("            <br>\r\n", $extraFieldsForms) . "\r\n" . "        </div>\r\n" . "\r\n";
     }
     return $stdout;
 }
예제 #3
0
 public static function drawAddComment()
 {
     $stdout = "";
     $showform = 1;
     $errormessage["left"] = $errormessage["right"] = "";
     $founderror = array();
     $confirmation = "";
     if (!class_exists("openid", FALSE)) {
         require_once PATH_CLASSES . "/lib/openid.php";
     }
     if (OPENIDDEBUG) {
         echo "<h2>drawAddComment</h2>";
         echo "<br>REQUEST=";
         debug::rrr();
         echo "<br>SESSION=";
         debug::rr(array_keys($_SESSION));
         echo "<br>COOKIE=";
         debug::rr(array_keys($_COOKIE));
     }
     //,"openid_identifier","openid_return_url","openid_server_url","openid_request","openid_identifier","openid_request"
     //$a=array("openid_news_validation_error","openid_news_form_html","openid_news_return_url","openid_news_request","openid_news_server_url");foreach ($a as $b) unset($_SESSION[$b]);
     /*
     echo "<html><head><title>OpenId transaction in progress</title></head>
     <body onload='document.forms[0].submit();'>
     <form accept-charset='UTF-8' enctype='application/x-www-form-urlencoded' id='openid_message' method='post' action='http://www.myopenid.com/server'>
     <input type='hidden' name='openid.ns' value='http://specs.openid.net/auth/2.0' />
     <input type='hidden' name='openid.ns.sreg' value='http://openid.net/extensions/sreg/1.1' />
     <input type='hidden' name='openid.ns.pape' value='http://specs.openid.net/extensions/pape/1.0' />
     <input type='hidden' name='openid.sreg.required' value='nickname,fullname,email' />
     <input type='hidden' name='openid.sreg.optional' value='gender,dob,postcode,country,language,timezone' />
     <input type='hidden' name='openid.pape.preferred_auth_policies' value='http://schemas.openid.net/pape/policies/2007/06/multi-factor-physical http://schemas.openid.net/pape/policies/2007/06/multi-factor http://schemas.openid.net/pape/policies/2007/06/phishing-resistant' />
     <input type='hidden' name='openid.pape.max_auth_age' value='0' />
     <input type='hidden' name='openid.realm' value='http://www.nordita.org/~hvzm/www.nordita.org/' />
     <input type='hidden' name='openid.mode' value='checkid_setup' />
     <input type='hidden' name='openid.return_to' value='http://www.nordita.org/~hvzm/www.nordita.org/news/nordic/index.php?articleid=25&amp;janrain_nonce=2013-03-09T03%3A04%3A18ZMC2RJ2' />
     <input type='hidden' name='openid.identity' value='http://hvzm.myopenid.com/' />
     <input type='hidden' name='openid.claimed_id' value='http://hvzm.myopenid.com/' />
     <input type='hidden' name='openid.assoc_handle' value='{HMAC-SHA1}{513aa6b2}{QGWDEw==}' />
     <input type='submit' value='Continue' />
     </form>
     <script>var elements = document.forms[0].elements;for (var i = 0; i < elements.length; i++) {  elements[i].style.display = 'none';}</script>
     </body></html>";die();
     */
     //if (OPENIDDEBUG) {echo "<br><strong>REFERRER</strong>: ";var_dump($_SERVER["HTTP_REFERER"]);}
     //if (OPENIDDEBUG) {echo "<br>SESSION BEFORE ADDCMT = ";if (isset($_SESSION["addcmt"])) var_dump($_SESSION["addcmt"]);echo "<br>SESSION BEFORE: CMT_TEXT = ";if (isset($_SESSION["cmt_text"])) var_dump($_SESSION["cmt_text"]);echo "<br>SESSION BEFORE: openid_identifier = ";if (isset($_SESSION["openid_identifier"])) var_dump($_SESSION["openid_identifier"]);echo "<br>SESSION BEFORE: janrain_nonce = ";if (isset($_SESSION["janrain_nonce"])) var_dump($_SESSION["janrain_nonce"]);echo "<br>SESSION BEFORE: openid_return_url = ";if (isset($_SESSION["openid_return_url"])) var_dump($_SESSION["openid_return_url"]);}
     //if (!class_exists("openid",FALSE)) require_once PATH_CLASSES . "/lib/openid.php";echo "<br><hr>";$pth = "/tmp/_php_consumer_test";echo "<h4>Content of directory $pth BEFORE:</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}$pth = "/tmp/_php_consumer_test/associations";echo "<h4>Content of directory $pth BEFORE:</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}
     //CLEAN://debug::rr(openid::cleanStore());echo "<h4>Content of directory $pth AFTER:</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}debug::rr(array_keys($_SESSION));echo "<br><hr>";
     /*
     //TODO: perhaps simplify with glob() ?
     
     echo "<hr>";
     $pth = "/tmp/_php_consumer_test";echo "<h4>$pth</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}
     $pth = "/tmp/_php_consumer_test/associations";echo "<h4>$pth</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) {echo "<br>$k $v : ";var_dump(is_dir($v));var_dump(is_file($v));var_dump(is_readable($v));var_dump(is_executable($v));var_dump(is_link($v));}}
     
     //$pth = "/tmp/_php_consumer_test/associations";echo "<h4>$pth</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}
     
     $pth = "/tmp/_php_consumer_test/nonces";echo "<h4>$pth</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}
     $pth = "/tmp/_php_consumer_test/temp";echo "<h4>$pth</h4>";if (is_dir($pth)) {$dir = scandir($pth);reset($dir);while ((list($k,$v)=each($dir))) echo "<br>$k $v";}
      echo "<hr>";
     */
     //debug::rrr();
     // --------------------------------
     // -- GPC indata
     // --------------------------------
     // needed for form, in all situations
     functions::gpc_declare_input("openid_identifier", "", false, array(), true);
     // needed for form, in all situations
     functions::gpc_declare_input("cmt_text", "", false, array(), true, false);
     functions::gpc_declare_input("cmt_name", "", false, array(), true, true);
     // needed on return from openid check
     functions::gpc_declare_input("addcmt", 0, true, array(), true);
     //functions::gpc_declare_input("janrain_nonce","",false,array(),true); // OBSOLETE?
     // -------------------------
     // -- If sign-out requested
     if (isset($_REQUEST["relog"])) {
         unset($_SESSION["openid_last_valid_identifier"]);
         unset($_SESSION["openid_identifier"]);
         if (isset($GLOBALS["domain"])) {
             unset($GLOBALS["domain"]);
         }
     }
     if (OPENIDDEBUG && isset($_REQUEST["relog"])) {
         echo "<br>openid_last_valid_identifier <strong>after relog</strong>= ";
         var_dump($_SESSION["openid_last_valid_identifier"]);
     }
     functions::gpc_declare_input("openid_last_valid_identifier", "", false, array(), true);
     if (OPENIDDEBUG) {
         echo "<br>openid_last_valid_identifier <strong>after gpc</strong> = ";
         var_dump($_SESSION["openid_last_valid_identifier"]);
     }
     if (OPENIDDEBUG) {
         echo "<br>openid_last_valid_identifier <strong>when setting domain</strong> = ";
         var_dump($_SESSION["openid_last_valid_identifier"]);
     }
     // -- Set domain of OpenID provider
     $GLOBALS["domain"] = openid::setOpDomain();
     if (OPENIDDEBUG) {
         echo "<br>freshly set <strong>DOMAIN</strong> = ";
         var_dump($GLOBALS["domain"]);
     }
     // -- Part of spam filter
     functions::gpc_declare_input(HONEYTRAP_ID, "", false);
     if (!empty($GLOBALS[HONEYTRAP_ID]) && isset($GLOBALS["addcmt"])) {
         $GLOBALS["addcmt"] = false;
     }
     // sent to openid check
     $_SESSION["articleid"] = !empty($GLOBALS["articleid"]) ? $GLOBALS["articleid"] : "";
     $_SESSION["openid_return_url"] = $GLOBALS["openid_return_url"] = URL_PREFIX . $_SERVER["PHP_SELF"] . (!empty($GLOBALS["articleid"]) ? "?articleid=" . $GLOBALS["articleid"] : "") . "";
     // -- Is user logged in to the news site
     $loggedinas = auth::isAuthenticated() ? auth::getUsername() : false;
     //if (OPENIDDEBUG) {echo "<br>SESSION AFTER: RETURN URL= ";if (isset($_SESSION["openid_return_url"])) var_dump($_SESSION["openid_return_url"]);echo "<br><br>GLOBALS CMT_TEXT=";var_dump($GLOBALS["cmt_text"]);echo "<br>GLOBALS ADDCMT=";var_dump($GLOBALS["addcmt"]);echo "<br>GLOBALS janrain_nonce=";var_dump($GLOBALS["janrain_nonce"]);}
     // --------------------------------
     // -- Check form input
     // --------------------------------
     if ($GLOBALS["addcmt"]) {
         if (OPENIDDEBUG) {
             echo "<h3>IN ADDCMT</h3>";
         }
         //echo "<p>openid_identifier=";var_dump($GLOBALS["openid_identifier"]);echo "<hr>"; echo "<p>openid_validation_error=";var_dump($GLOBALS["openid_validation_error"]);echo "<hr>";
         // -- Trim indata
         //TODO: spam filtering
         //TODO: check HTML validity
         //TODO: http://se.php.net/manual/en/function.strip-tags.php
         //$GLOBALS["cmt_text"] = "<p>" . str_replace("\r","</p>\r<p>",$GLOBALS["cmt_text"]) . "</p>";
         $allowed_html_tags = "";
         // "<p> <a> <b> <i> <strong> <em> <br>";
         $GLOBALS["cmt_text"] = strip_tags($GLOBALS["cmt_text"], $allowed_html_tags);
         $GLOBALS["cmt_text"] = trim($GLOBALS["cmt_text"]);
         $_SESSION["cmt_text"] = $GLOBALS["cmt_text"];
         $_SESSION["cmt_name"] = $GLOBALS["cmt_name"];
         //if (OPENIDDEBUG) {echo "<br>GLOBALS CMT_TEXT=";var_dump($GLOBALS["cmt_text"]);echo "<br>SESSION CMT_TEXT=";var_dump($_SESSION["cmt_text"]);}
         // -- Check for errors in submitted comment text
         if (empty($GLOBALS["cmt_text"])) {
             $founderror["cmt_text"] = 1;
             $errormessage["left"] .= "<p class='messages error'>Your comment looks quite empty</p>\r\n";
         }
         // -- Check for error messages from OpenId authentication call.
         //    Retrieved via session variable from page treated by CheckOpenid().
         functions::gpc_declare_input("openid_validation_error", "", false, array(), true);
         if (!empty($GLOBALS["openid_validation_error"])) {
             $founderror["openid_identifier"] = 1;
             $errormessage["right"] .= "<p class='messages error'>" . $GLOBALS["openid_validation_error"] . "</p>\r\n";
         }
         // -- Act on presence or absence of errors
         if (array_sum($founderror)) {
             // If errors found, display form with error messages
             $showform = 1;
         }
         // end if ($noerror)
     }
     // end "addcmt"
     // --------------------------------
     // -- If no errors found, insert comment into DB
     // --------------------------------
     if (!array_sum($founderror) && $GLOBALS["addcmt"]) {
         if (!class_exists("openid", FALSE)) {
             require_once PATH_CLASSES . "/lib/openid.php";
         }
         // set from session with fixed value; needed on return from openid check
         //functions::gpc_declare_input("openid_return_url","",false,array(),true);
         if ($loggedinas) {
             if (!class_exists("fromdb_nwnews", FALSE)) {
                 require_once PATH_CLASSES . "/fromdb/nwnews.php";
             }
             $GLOBALS["newsClass"] = new fromdb_nwnews();
             $idData = $GLOBALS["newsClass"]->getDataForLocalUser($loggedinas);
         } else {
             // needed on return from openid check
             functions::gpc_declare_input("openid_server_url", "", false, array(), true);
             if (in_array(openid::reduceDomain($GLOBALS["domain"]), openid::$oauthProviders)) {
                 // -- OAuth return values
                 if (OPENIDDEBUG) {
                     echo "<h3>ANALYZING OAUTH RETURN DATA</h3>";
                 }
                 //$returnUrl = isset($_SESSION["returnUrl"]) ? $_SESSION["returnUrl"] : URL_PREFIX.$_SERVER["REQUEST_URI"];
                 //$idData = openid::analyzeOauthResponse($returnUrl);
                 $idData = openid::analyzeOauthResponse($GLOBALS["openid_return_url"], openid::reduceDomain($GLOBALS["domain"]));
             } else {
                 // -- OpenID return values
                 if (OPENIDDEBUG) {
                     echo "<h3>ANALYZING OPENID RETURN DATA</h3>";
                 }
                 $idData = openid::analyzeOpenidResponse($GLOBALS["openid_return_url"], $GLOBALS["openid_server_url"]);
             }
             // $anonymous = false; foreach (openid::$anonymousUrlProviders as $p) if () $anonymous = true;
             if (is_string($idData)) {
                 $errormessage["right"] = "<p class='messages error'>" . $idData . "</p>";
                 $showform = 1;
             }
         }
         /*
         $idData = Array
         (
             [openid_identity] => http://hvzm.myopenid.com/
             [email] => hvzm@nordita.org
             [nickname] => hvzm
             [fullname] => Hans Mühlen
             [pape] => Array ()
         )
         idData = Array
         (
             [openid_news_identity] => http://openid.aol.com/hans.muhlen
             [email] => hans.muhlen@aol.com
             [pape] => Array
                 (
                     [extension] => Array
                         (
                             [0] => http://schemas.openid.net/pape/policies/2007/06/none
                         )
                 )
         )
         */
         //echo "<hr>IDATA=";debug::rr($idData);
         if (is_array($idData)) {
             //$name = "Anonymous";
             //if (isset($idData["data"]["nickname"]) && !empty($idData["data"]["nickname"])) $name = $idData["data"]["nickname"];
             //TODO
             $oidNick = openid::guessNickname($idData);
             if (!empty($GLOBALS["cmt_name"])) {
                 $name = $GLOBALS["cmt_name"];
             } elseif (!empty($oidNick)) {
                 $name = $oidNick;
             } else {
                 $name = "Anonymous";
             }
             $record = array("article_id" => $GLOBALS["articleid"], "text" => $GLOBALS["cmt_text"], "name" => $name, "author_id" => openid::guessEndUserField("author_id", $idData, 0), "image" => openid::guessEndUserField("image", $idData, ""));
             $res = self::addCommentInsert($record);
             if ($res) {
                 self::commentNotifyAdmin($record);
             }
             if (!$res) {
                 $errormessage["left"] = "\r\n" . "<p class='messages error'>Sorry, could not upload your comment</p>\r\n" . "\r\n";
                 $showform = 1;
             } else {
                 $showform = 1;
             }
         } else {
             $showform = 1;
         }
     }
     // --------------------------------
     // -- Output form, if requested
     // --------------------------------
     if ($showform) {
         // form uses $GLOBALS["cmt_text"] and $GLOBALS["articleid"]
         $stdout .= self::drawAddCommentForm($founderror, $errormessage, $loggedinas);
     }
     // --------------------------------
     // -- Cleanup
     // --------------------------------
     // always set from GPC;
     unset($_SESSION["addcmt"]);
     // always set from GPC; needed for form, in all situations
     unset($_SESSION["cmt_text"]);
     unset($_SESSION["cmt_name"]);
     // set on form submit in CheckOpenid() as result from openid check; then set here on second run from GPC
     unset($_SESSION["openid_validation_error"]);
     // always set from GPC;
     //    unset($_SESSION["janrain_nonce"]); // OBSOLETE?
     // always set to fixed value; sent to openid check and needed on return from openid check
     //    unset($_SESSION["openid_return_url"]);
     // always set from GPC; needed for form, in all situations
     //    unset($_SESSION["openid_identifier"]); // never delete!
     // set on form submit with no errors from GPC; needed on return from openid check
     //unset($_SESSION["openid_server_url"]);
     // --------------------------------
     //DEBUG:
     $t = "";
     $t .= "<div class='box blackborder padding'>\r\n<h4>OPENID REQUEST:</h4><pre>\r\n" . (!empty($_SESSION["openid_request"]) ? $_SESSION["openid_request"] : "-\r\n") . "</pre></div>\r\n\r\n";
     $t .= "<div class='box blackborder padding'>\r\n<h4>OPENID RESPONSE:</h4> <pre>\r\n" . (!empty($_SESSION["openid_response"]) ? $_SESSION["openid_response"] : "-\r\n") . "</pre></div>";
     //$t .= "\r\n\r\n<p>URL_PREFIX=".URL_PREFIX."\r\n<br>PHPSELF_PREFIX=".PHPSELF_PREFIX."\r\n<br>DOCROOT_PREFIX=".DOCROOT_PREFIX."</p>\r\n";
     if (IS_TESTSERVER && OPENIDDEBUG) {
         echo $t;
     } else {
         $stdout .= "\r\r<!--\r\r\n" . $t . "\r\n\r-->\r\r";
     }
     if (OPENIDDEBUG) {
         if (isset($idData)) {
             echo "<h4>idData:</h4> ";
             debug::rr($idData);
         }
     }
     return $stdout;
 }
예제 #4
0
 public static function OutputDirectorsReport()
 {
     functions::gpc_declare_input("r", false, true);
     if ($GLOBALS["r"] == 1) {
         unset($_SESSION["directorsreport"]);
     }
     debug::rrr();
     $stdout = $date_interval = "";
     $errormessage = array();
     $meetingdate = isset($_SESSION["directorsreport"]["meetingdate"]) ? $_SESSION["directorsreport"]["meetingdate"] : date("Y-m-d");
     $timestamp_from = isset($_SESSION["directorsreport"]["timestamp_from"]) ? $_SESSION["directorsreport"]["timestamp_from"] : strtotime("- 3 months");
     $timestamp_to = isset($_SESSION["directorsreport"]["timestamp_to"]) ? $_SESSION["directorsreport"]["timestamp_to"] : time();
     functions::gpc_declare_input("meetingdate_selected", false, true);
     functions::gpc_declare_input("meetingdate", $meetingdate, false);
     functions::gpc_declare_input("period_selected", false, true);
     functions::gpc_declare_input("month_from", date("n", $timestamp_from), false);
     functions::gpc_declare_input("year_from", date("Y", $timestamp_from), false);
     functions::gpc_declare_input("month_to", date("n", $timestamp_to), false);
     functions::gpc_declare_input("year_to", date("Y", $timestamp_to), false);
     // ------------------------
     // -- Input check
     // ------------------------
     if ($GLOBALS["meetingdate_selected"]) {
         if (!strtotime($GLOBALS["meetingdate"])) {
             $errormessage[] = "Incorrect date '" . $GLOBALS["meetingdate"] . "'. Please try again.";
         }
     } elseif ($GLOBALS["period_selected"]) {
         $timestamp_from = mktime(0, 0, 0, $GLOBALS["month_from"], 1, $GLOBALS["year_from"]);
         $timestamp_to = mktime(0, 0, 0, $GLOBALS["month_to"], 1, $GLOBALS["year_to"]);
         $lastday = date("t", $timestamp_to);
         $timestamp_to = mktime(0, 0, 0, $GLOBALS["month_to"], $lastday, $GLOBALS["year_to"]);
         if (!is_numeric($GLOBALS["month_from"]) || !is_numeric($GLOBALS["year_from"]) || !is_numeric($GLOBALS["month_to"]) || !is_numeric($GLOBALS["year_to"]) || !checkdate($GLOBALS["month_from"], 1, $GLOBALS["year_from"]) || !checkdate($GLOBALS["month_to"], 1, $GLOBALS["year_to"])) {
             $errormessage[] = "Incorrect month or year. Please try again.";
         }
         if ($timestamp_from > $timestamp_to) {
             $errormessage[] = "Incorrect period. Please try again.";
         }
     }
     // ------------------------
     // -- Print preamble
     // ------------------------
     $stdout .= "  <p><a href='" . $_SERVER["PHP_SELF"] . "?r=1' class='fakebuttonbutton'>Start over</a></p>\r\n" . "  <p class='bold'><a href='docsx/directors_reports/nordita_directors_report_MONTH_YEAR.tex'>Download TeX template for report</a>\r\n" . "  &#8212; <a href='docs/logo/nordita-logo-black-text-and-subtitle.pdf'>Download logo image file for TeX file</a></p>\r\n";
     // ------------------------
     // -- Print date selection form
     // ------------------------
     var_dump(!$GLOBALS["meetingdate_selected"]);
     if (!$GLOBALS["period_selected"] && (!$GLOBALS["meetingdate_selected"] || !empty($errormessage))) {
         if (!empty($errormessage)) {
             $stdout .= "  <div class='box error padding background bold'>\r\n" . "  <p>&#187; " . implode("</p>\r\n  <p>&#187; ", $errormessage) . "</p>\r\n" . "  </div>\r\n";
         }
         $stdout .= "  <form " . "action='" . $_SERVER["PHP_SELF"] . "' " . "method='POST' " . "enctype='multipart/form-data' " . "style='margin-top:1em;margin-bottom:1em'>\r\n" . "    <h3 style='margin-bottom:1em'>Please enter the date for the board meeting<br>(format <strong>YY-mm-dd</strong>):</h3>\r\n" . "    <p><input type='date' name='meetingdate' value='" . $GLOBALS["meetingdate"] . "'" . (!empty($errormessage) ? " class='error'" : "") . ">\r\n" . "    <input type='submit' name='meetingdate_selected' value='Select'>\r\n" . "    </p>\r\n " . "  </form>\r\n";
         debug::rr($_SESSION["directorsreport"]);
         return $stdout;
     } elseif (!$GLOBALS["period_selected"] || !empty($errormessage)) {
         $_SESSION["directorsreport"]["meetingdate"] = $GLOBALS["meetingdate"];
         $stdout .= "  <h2>Compiling a Director's Report for<br>the Board Meeting on " . $GLOBALS["meetingdate"] . "</h2>\r\n";
         if (!empty($errormessage)) {
             $stdout .= "  <div class='box error padding background bold'>\r\n" . "  <p>&#187; " . implode("</p>\r\n  <p>&#187; ", $errormessage) . "</p>\r\n" . "  </div>\r\n";
         }
         $stdout .= "  <form " . "action='" . $_SERVER["PHP_SELF"] . "' " . "method='POST' " . "enctype='multipart/form-data' " . "style='margin-top:1em;margin-bottom:1em'>\r\n" . "    <h3 style='margin-bottom:1em'>Select the period for this report</h3>\r\n" . "    <p>From \r\n" . "    <select name='month_from' style=''>\r\n";
         for ($m = 1; $m < 13; $m++) {
             $stdout .= "    <option value='" . $m . "'" . ($GLOBALS["month_from"] == $m ? " selected='selected'" : "") . ">" . date("F", mktime(0, 0, 0, $m)) . "</option>\r\n";
         }
         $stdout .= "    </select>\r\n" . "    <select name='year_from'>\r\n";
         for ($y = date("Y") - 1; $y <= date("Y") + 1; $y++) {
             $stdout .= "    <option value='" . $y . "'" . ($GLOBALS["year_from"] == $y ? " selected='selected'" : "") . ">" . date("Y", mktime(0, 0, 0, 1, 1, $y)) . "</option>\r\n";
         }
         $stdout .= "    </select>\r\n" . "    to \r\n " . "    <select name='month_to'>\r\n";
         for ($m = 1; $m < 13; $m++) {
             $stdout .= "    <option value='" . $m . "'" . ($GLOBALS["month_to"] == $m ? " selected='selected'" : "") . ">" . date("F", mktime(0, 0, 0, $m)) . "</option>\r\n";
         }
         $stdout .= "    </select>\r\n" . "    <select name='year_to'>\r\n";
         for ($y = date("Y") - 1; $y <= date("Y") + 1; $y++) {
             $stdout .= "    <option value='" . $y . "'" . ($GLOBALS["year_to"] == $y ? " selected='selected'" : "") . ">" . date("Y", mktime(0, 0, 0, 1, 1, $y)) . "</option>\r\n";
         }
         $stdout .= "    </select>\r\n" . "    <input type='submit' name='period_selected' value='Select'>\r\n" . "    </p>\r\n " . "  </form>\r\n";
         debug::rr($_SESSION["directorsreport"]);
         return $stdout;
     }
     // ------------------------
     // -- Print output
     // ------------------------
     $_SESSION["directorsreport"]["timestamp_from"] = $timestamp_from;
     $_SESSION["directorsreport"]["timestamp_to"] = $timestamp_to;
     debug::rr($_SESSION["directorsreport"]);
     var_dump(date("Y-m-d", $timestamp_from));
     var_dump(date("Y-m-d", $timestamp_to));
     $from = getdate($timestamp_from);
     $to = getdate($timestamp_to);
     $date_interval = $from["year"] == $to["year"] ? $from["mon"] == $to["mon"] ? $from["month"] . " " . $from["year"] : $from["month"] . " &#8212; " . $to["month"] . " " . $from["year"] : $from["month"] . " " . $from["year"] . " &#8212; " . $to["month"] . " " . $to["year"];
     $stdout .= "  <h2>TeX Template for a Director's Report" . "<br>for the period " . $date_interval . "<br>for the Board Meeting on " . functions::readableDate($_SESSION["directorsreport"]["meetingdate"]) . "</h2>\r\n";
     $stdout .= "  <div class='box blackborder padding' style='white-space:pre;font-family:monospace'>";
     $stdout .= "\\documentclass[twoside,10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\\usepackage[swedish]{babel}\n\\usepackage{amsmath}\n\\usepackage{amssymb,amsfonts,textcomp}\n\\usepackage{array}\n\\usepackage{hhline}\n\\usepackage{graphicx}\n\\usepackage{titlesec}\n\\usepackage{hyperref}\n\\usepackage{enumerate}\n\\usepackage{color}\n\\usepackage{multicol}\n\n\\setlength{\\textwidth}{155mm}        % A4\n\\setlength{\\textheight}{247mm}       % A4\n\\setlength{\\hoffset}{-1in}           % to compensate default 1 inch inner margin\n\\setlength{\\voffset}{-1in}           % to compensate default 1 inch top margin\n\\setlength{\\oddsidemargin}{30mm}\n\\setlength{\\evensidemargin}{30mm}\n\\setlength{\\marginparwidth}{17mm}\n\n\\titleformat{\\section}[display]{\\normalfont\\Huge\\bfseries}{}{0pt}{}\n\\titleformat{\\subsection}[display]{\\raggedright\\normalfont\\LARGE\\bf}{}{-5pt}{}\n\\titleformat{\\subsubsection}[display]{\\normalfont\\large\\bf}{}{-15pt}{}\n\n\\title{}\n\n% ------------------------------------------------------------\n\n\\begin{document}\n\n% Unhandled or unsupported graphics:\n% This image can be downloaded from http://www.nordita.org/docs/logo/nordita-logo-black-text-and-subtitle.pdf\n\\noindent\\includegraphics{nordita-logo-black-text-and-subtitle.pdf}\n\\newline\\rule{\\textwidth}{1pt}\n\n\\bigskip\n\n\\section{DIRECTOR’S REPORT \\newline\nfor " . $date_interval . "}\n\nPrepared by ........... for the meeting of the Nordita board on " . functions::readableDate($_SESSION["directorsreport"]["meetingdate"]) . ".\n\n\\bigskip\n\n% ------------------------------------------------------------\n\\subsection{STAFF}\n% Get data from http://nordita.org/alumni\n\n\\subsubsection{Faculty}\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{....} (.... physics) from ... ..... longer text ....\n\\end{itemize}\n\n\\noindent Faculty members that have left since the previous Director’s report:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) left Nordita ... for a position .........\n\\end{itemize}\n\n% If relevant, insert information about ongoing or concluded recruitments .......\n\n\\subsubsection{Post-doctoral Fellows}\n\n\\noindent ....... new Nordita Fellows arrived during the period covered by the report, and ......... postponed thier arrival:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{.....} (.... physics) from ..., arrived .....\n\\end{itemize}\n\n\\noindent ........ new postdoctoral fellow supported by project grants arrived during the report period, and ......... were continued on other project grants:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) from ..., arrived ..... under the ..... grant\n\\end{itemize}\n\n\\noindent Postdoctoral fellows that have left since the previous Director’s report:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) left Nordita ... for a position .........\n\\end{itemize}\n\n% Get data from http://nordita.org/people\n\\noindent Currently there are ......... Nordita Fellows, and ......... postdoctoral fellows supported by project grants.\n\n% --------- START -- ONLY FOR OCTOBER-JANUARY REPORT -----------------\n% Get data from http://jam.nordita.org\n\n\\bigskip\n\\noindent A total of 439 applications were received for Nordita Fellowships in Fall 2015 (compared to 455 in 2014, 399 in 2013, 331 in 2012, 226 in 2011, 403 in 2010, and 355 in 2009). Applicants placed themselves in one of six categories and the breakdown was as follows (numbers in parentheses are from previous years):\n\n% Modyfy this list in such a way that the history is kept and updated:\n\\begin{itemize}\\itemsep-3pt\n\\item Astrophysics and Astrobiology — 33 (2014: 46; 2013: 41; 2012: 33; 2011: 43)\n\\item Biological Physics — 8 (2014: 6; 2013: 6; 2012: 3; 2011: 3)\n\\item Condensed Matter Physics — 45 (2014: 42; 2013: 36; 2012: 34; 2011: 28)\n\\item Gravitation and Cosmology — 110 (2014: 137; 2013: 127; 2012: 118; 2011: 54)\n\\item High-Energy Physics — 243 (2014: 150; 2013: 189; 2012: 114; 2011: 87)\n\\item Other — [this option was removed] (2014: 74; 2013: –; 2012: 32; 2011: 11)\n\\end{itemize}\n\n\\noindent The applications were evaluated by the Nordita Research Committees and by members of the Nordita Faculty. The committees met in Stockholm in the beginning of December to make recommendations for a short list,\n% Get data from http://www.nordita.org/minutes/\nwhich was finalized at a faculty meeting on December ..............\n%The recruitment is ongoing with 5 accepted fellowships and 1 active offer.\nThe recruitment is completed with 6 accepted fellowships:\n% ABC listing\n% Get PhD data from http://jam.nordita.org\n\\begin{itemize}\\itemsep-3pt\n\\item \\textit{Stefano Bo} (biophysics), PhD 2015 from Turin, Italy\n\\item \\textit{......} (....... physics), PhD ..... from ........\n\\end{itemize}\nIn most cases, the top candidates accepted.\n% ABC listing\n% Get info from faculty member...\nInitial offers to\n... (..... physics),\n... (..... physics)\nwere eventually declined.\n\n% --------- END -- ONLY FOR OCTOBER-JANUARY REPORT -----------------\n\n\\subsubsection{PhD Students}\n\n........ new PhD students arrived at Nordita during the reporting period:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) from ..., arrived .....\n\\end{itemize}\n\n\\noindent Thesis defense:\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{....} successfully defended his ....... thesis ``........'' on 1 January 2016.\n\\end{itemize}\n\n\\noindent A complete list of current Nordita staff is at {\\textless}www.nordita.org/people{\\textgreater}. Nordita Alumni from 1957 to the present are at {\\textless}www.nordita.org/alumni{\\textgreater}.\n\n% ------------------------------------------------------------\n\\subsection{VISITORS}\n% Get data from http://www.nordita.org/science/phd_fellows/list_of_phd_fellows\n\n\\noindent ....... Visiting PhD Student Fellows stayed at Nordita during the period:\n\n% Arrival date listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) from ..., period\n\\end{itemize}\n\n\\noindent Four Visiting PhD Fellowships for 2016 have been awarded:\n% Get data from http://www.nordita.org/science/phd_fellows/list_of_phd_fellows\n\n% ABC listing\n\\begin{itemize}\n\\item \\textit{...} (.... physics) from ..., period. Contact person is ...............\n\\end{itemize}\n\n\\noindent Long-term visitors, staying one week or more, include:\n% Get data from http://nordita.org/science/visitors/list_of_visitors\n\n% Arrival date listing\n\\begin{itemize}\n\\item \\textit{.......} (.... physics) from ..., period\n\\end{itemize}\n\n\\noindent A more complete list of Nordita visitors, including short-term visits of less than a week, can be found online at {\\textless}www.nordita.org/visitors{\\textgreater}. A summary of visitors outside events, including nationality statistics, is at {\\textless}www.nordita.org/statistics/nationality\\_visitors{\\textgreater}.\n\n% ------------------------------------------------------------\n\\subsection{SCIENTIFIC PROGRAMS}\n% Get data from http://nordita.org/events\n\n........ Nordita Scientific Program took place during the period:\n\n\\begin{itemize}\n\\item \\textit{Water – the Most Anomalous Liquid}, 13 October – 7 November 2014; Coordinators: Lars G. M. Pettersson (Stockholm Univ.), Anders Nilsson (Stanford Univ.), Richard H. Henchman (Univ.\\ of Manchester)\n\\end{itemize}\n\n\\noindent A selection of upcoming programs:\n\n\\begin{itemize}\n\\item \\textit{Extended Theories of Gravity}, 2–20 March 2015; Coordinators: Kari Enqvist (Univ.\\ of Helsinki), Tomi Koivisto (Nordita), David Fonseca Mota (Univ.\\ of Oslo), Fawad Hassan (Stockholm Univ.), Lavinia Heisenberg (Nordita)\n\\end{itemize}\n\n\\noindent The complete list of Nordita events, including programs, conferences and schools, can be found online at {\\textless}www.nordita.org/events{\\textgreater}. Statistics including nationality of program participants is at {\\textless}www.nordita.org/statistics/nationality\\_programs{\\textgreater}.\n\n% ------------------------------------------------------------\n\\subsection{CONFERENCES, WORKSHOPS, AND SCHOOLS}\n% Get data from http://nordita.org/events\n\nThe following events have been organized and/or co-sponsored by Nordita during the period of this report:\n\n\\begin{itemize}\n\\item \\textit{Dark Energy Interactions}, 1–3 October 2014; Coordinators: Tomi Koivisto (Nordita), David Fonseca Mota (Univ.\\ of Oslo)\n\\end{itemize}\n\n\\noindent A selection of upcoming shorter events:\n\n\\begin{itemize}\n\\item \\textit{The 6th Nordic Workshop on Statistical Physics: Biological, Complex and Non-Equilibrium Systems}, 25–27 February 2015; Coordinators: Ralf Eichhorn (Nordita), Alberto Imparato (Aarhus Univ.)\n\\end{itemize}\n\n% ------------------------------------------------------------\n\\subsection{PUBLICATIONS}\n% Get data from http://nordita.org/preprints\n\n% Modify this text so that publication history is kept:\nA total of 181 Nordita preprints were registered in 2015, and 5 so far in 2016.\\\\\n(In 2014 a total of 152 preprints were registered, 121 in 2013, and 110 in 2012.)\n\n\\bigskip\n\n\\noindent All Nordita preprints are listed online at: {\\textless}www.nordita.org/preprints{\\textgreater}.\\\\\nPreprint statistics is at {\\textless}www.nordita.org/statistics/preprint{\\textgreater}.\n\n% ------------------------------------------------------------\n\\subsection{EXTERNAL FUNDING}\n\n\\begin{itemize}\n \\item \\textit{....} (... physics) was awarded ..........\n\\end{itemize}\n\n% ------------------------------------------------------------\n\\subsection{OTHER ISSUES}\n\n\\subsubsection{Funding from the Swedish Research Council (VR)}\n\n.......\n\n\\subsubsection{Funding from the Henrik Granholm Foundation}\n\n........\n\n\\subsubsection{Funding from the Knut and Alice Wallenberg Foundations}\n\n........\n\n\\subsubsection{Indirect support from the Faculty of Science, Stockholm University}\n\n.........\n\n% ------------------------------------------------------------\n\n\\bigskip\n\\end{document}";
     $stdout .= " </div>\r\n";
     // ------------------------
     return $stdout;
 }