. */ // Things to change to make more like your school: // Entry Types [we distinguish lessons that require computers as unmovable] // use three variables below to set a default and one alternative type // Periods and Break/Lunchtimes, see explanation below (search for PERIOD EXPLANATION) $defaultEntryType = "G"; // Default Type for each Entry, as per your config.inc.php $alternateEntryType = "GJ"; $alternateEntrySubCodes = "XYZ"; /* ---------------------------------------------------------------------------------------------------------- */ $alternateEntrySubCodes = explode("|", $alternateEntrySubCodes); // Report all errors error_reporting(E_ALL); function importCSV(){ // Function generates an array with the data from the CSV given // Read the file $content = file_get_contents($_FILES["csvfile"]["tmp_name"]); $content = substr($content, strpos($content, "\n") + 1); // Explode entries by line breaks $entries = explode("\n", $content); for($i=0;$i Mon:07 // Means sorting works properly $entry[2] = substr($entry[2],1,4)."0".substr($entry[2],5,1); $room[$entry[2]] = trim($entry[0]); $day[$entry[2]] = trim($entry[1]); $period[$entry[2]] = trim($entry[2]); $class[$entry[2]] = trim($entry[3]); $teacher[$entry[2]] = trim($entry[4]); $subcode[$entry[2]] = trim($entry[5]); $nostudents[$entry[2]] = trim($entry[6]); $duration[$entry[2]] = 1; // Give all entries a default type of movable (E) $entrytype[$entry[2]] = $defaultEntryType; // Create an array of the items which we can then sort $listof[count($listof)] = $entry[2]; } } function addDurations(){ global $room,$day,$period,$class,$teacher,$nostudents,$duration,$entrytype,$subcode,$alternateEntrySubCodes,$alternateEntryType; global $listof; // Sort our array of the items sort($listof); for($i=0;$i 0){ $entrytype[$listof[$i]] = $alternateEntryType; } } } } // Submit a request; now actually submits a GET request. function submitPOST($postData){ if (!isset($getData)) { $getData = ""; } foreach($postData as $data){ // Change the argument-supplied data to a GET string on the URL $getData .= ($getData ? "&" : "").urlencode($data[0])."=".urlencode($data[1]); } if ($getData != "") { // Echo the URL supplied for debugging. echo $_POST["phpLocation"]."?".$getData."
"; // Create an iframe which will load the URL supplied and show the output as necessary echo ""; } } if($_FILES["csvfile"] && $_POST["firstDOT"] && $_POST["lastDOT"] && $_POST["phpLocation"]){ // Start doing things. $entries = splittoReOrder(importCSV()); addDurations(); // First Day Of Term $firstDOT = strtotime($_POST["firstDOT"]." 12:00"); $lastDOT = strtotime($_POST["lastDOT"]." 12:00"); echo "

Results

Check below to see if entries were created successfully

    "; foreach($listof as $item){ $thisTS = $firstDOT; // Clear the Post Data array; it's kept each loop, annoyingly. $postData = NULL; if((int)$duration[$item] >= 1 && strlen($item) >= 6) { // Only execute this if the item has got a duration // i.e. don't execute if it's the second entry for a double period // And if the item name is at least 6 characters long (Fri:01); we get the odd blank one. echo "
  1. "; // Create Post Data: $postData[0][0] = "name"; $postData[0][1] = $class[$item]." [".$teacher[$item] . "]"; //echo $postData[0][1] . "
    "; $postData[1][0] = "description"; if($nostudents[$item] > 0){ // if we know the no. students we supply it in the description $postData[1][1] = $nostudents[$item]." Students"; } // Find the first day of term with the same weekday name // eg. first Friday of term to create first item for the repeating entry while(date("D",$thisTS) != substr($item,0,3)){ $thisTS += 86400; } $postData[2][0] = "start_day"; $postData[2][1] = date("j",$thisTS); $postData[3][0] = "start_month"; $postData[3][1] = date("n",$thisTS); $postData[4][0] = "start_year"; $postData[4][1] = date("Y",$thisTS); $postData[5][0] = "start_seconds"; // PERIOD EXPLANATION: // Latest MRBS stores 'periods' as 1 minute slots starting at 1200 (12*60*60 - see INSTALL document) // In CRGS's MRBS the number of minutes to add to get to each period is as follows: // Registration AM = 0 // P1-4 = 1-4 // Break = 5 // P5-6 = 6-7 // Lunch = 8 // Registration PM = 9 // P7-10 = 10-13 // After School = 14 // Evening = 15 // Other schools will have to modify the following to make it work for their period layout // NB If there are breaks in the day for break and lunch (like here), need to update addDurations function as well - see above //echo substr($period[$item],4,3); //die(); //this_period uses SIMS periods 1-6 if(substr($period[$item],4,3) == "RgA"){ // If this is an AM registration period $start_secs = 12*60*60; } elseif(substr($period[$item],4,3) == "RgP"){ // If this is a PM registration period $start_secs = 12*60*60 + (60 * 9); } else { // If this is an ordinary period $this_period = (int)substr($period[$item],4,2); // Get the period number into an integer if($this_period == 3 or $this_period == 4){$this_period += 1;} // If we are Periods 3 and 4, add one (to skip break) elseif($this_period == 5 or $this_period == 6){$this_period += 2;} // If we are Periods 5 and 6, add two (to skip break and lunch) elseif($this_period >= 7){$this_period += 3;} // If we are Period 7 or beyond, add three (to skip break, lunch and registration PM) $start_secs = 12*60*60 + (60 * $this_period); // Convert the period number into seconds for MRBS } $postData[5][1] = $start_secs; $postData[6][0] = "end_day"; $postData[6][1] = date("j",$thisTS); $postData[7][0] = "end_month"; $postData[7][1] = date("n",$thisTS); $postData[8][0] = "end_year"; $postData[8][1] = date("Y",$thisTS); $postData[9][0] = "end_seconds"; $postData[9][1] = $start_secs + ($duration[$item] - 1) * 60; // Set the end time of this lesson. Needs to be set to the time that the final period *starts* (i.e. duration - 1) $postData[10][0] = "rooms[]"; if (!is_numeric($room[$item])) { // If it looks like the conversion hasn't taken place yet, moan & go on to the next item echo "ERROR: Room ID '". $room[$item] . "' is not numeric. Need to change the Room values into MRBS IDs in the csv file.
    "; continue; } else { $postData[10][1] = $room[$item]; } $postData[11][0] = "type"; $postData[11][1] = $entrytype[$item]; $postData[12][0] = "rep_type"; $postData[12][1] = 6; $postData[13][0] = "rep_end_day"; $postData[13][1] = date("j",$lastDOT); $postData[14][0] = "rep_end_month"; $postData[14][1] = date("n",$lastDOT); $postData[15][0] = "rep_end_year"; $postData[15][1] = date("Y",$lastDOT); $postData[16][0] = "rep_num_weeks"; $postData[16][1] = 2; $postData[17][0] = "returl"; $postData[17][1] = ""; $postData[18][0] = "create_by"; $postData[18][1] = "DATAIMPORT"; $postData[19][0] = "rep_id"; $postData[19][1] = "0"; $postData[20][0] = "edit_type"; $postData[20][1] = "series"; } // ...and send the info off. submitPOST($postData); } echo "

Again!

"; } else { echo " CSV Add

Multi-Add to MRBS from CSV

E J McCutcheon 2009, C Hill 2010-2011


CSV File Notes:
Start of Term: End of Term:

File:

Relative location of edit_entry_handler.php:

"; } //Start of Term: //End of Term: ?>