function add_students_from_csv($files) { $filename = ""; //print_r($files); $filename = $files["file"]["tmp_name"]; //print_r($files); $options['delimiter'] = ","; //echo tableFromCsv($files["file"]["name"], true, $options); //echo "<pre>"; $result = extractCsv($filename, true, $options); // echo"<pre>";print_r($result); // echo "iambatman . $result"; // print_r($result); $ids = array_column($result, "ID #"); //echo "<pre>";print_r($ids); $keys = array_keys($result[0]); $check_keys = array_slice($keys, 0, 6); //echo "<pre>";print_r($check_keys); $format_key = array("ID #", "Last", "First", "Advisor", "Start SEM.", "Option"); // echo "<pre>";print_r($format_key); //echo "value".($check_keys === $format_key); if ($check_keys === $format_key) { //echo "iambatman"; $students = array(); $counter = 0; // echo"<pre>";print_r($ids); for ($i = 0; $i < sizeof($ids); $i++) { $check = studentid_validation($ids[$i]); if ($check == "false") { // echo "<br>".$ids[$i]; $students[$counter][$i] = $ids[$i]; $counter++; } // echo $i." ".$ids[$i]."<br>"; } if ($counter > 0) { // echo"<pre>";print_r($students); return $students; } else { $keys = array_keys($result[0]); //echo "<pre>";print_r($keys); /*foreach ($result as $i => $values) { //echo "<pre>";print_r($values); add_student($values); }*/ foreach ($result as $i => $values) { add_student($values); for ($i = 6; $i < sizeof($keys); $i++) { //echo $values ['ID #'].$keys[$i];print_r($values[$keys[$i]]);echo "<br>"; add_foundatation($values['ID #'], "GCIS " . $keys[$i], $values[$keys[$i]]); } } return 1; } } else { return 0; } }
include 'includes/header.php'; include 'includes/menu.php'; include "includes/cms_call.php"; include "../cms/array.php"; $error = ""; if (isset($_POST['submit'])) { $dbc = dbConnect('local'); // print_r($_POST); $values['ID #'] = $_POST['studentid']; $values['Last'] = $_POST['lname']; $values['First'] = $_POST['fname']; $values['Advisor'] = $_POST['advisor']; $values['startsem'] = $_POST['start_semester']; $values['startyear'] = $_POST['start_year']; $values['Option'] = $_POST['major']; $check = studentid_validation($_POST['studentid']); //print_r($values); if ($check == "false") { $result = 0; echo '<script>alert("Student id already exists"); </script>'; } else { //print_r($values); $result = add_student($values); } if ($result == 1) { $_SESSION['student'] = $_POST; redirect_to("add_student_foundation.php"); } else { $error = "Student data enter failed"; } }
//echo "<pre> batman";print_r($result); $keys = array_keys($result[0]); $loop = sizeof($result); $numkey = sizeof($keys); $numofstudent = -1; $numofcourse = -1; $numofgrd = -1; $add = 0; //print_r($keys); //echo "$loop"; $result_id = array_column($result, 'ID'); $result_id = array_filter($result_id); //print_r($result_id); foreach ($result_id as $ids) { //print_r($ids); $check = studentid_validation($ids); if ($check == "true") { $students_notfound[$counter] = $ids; $counter++; } } //print_r($students_notfound); if ($counter == 0) { for ($i = 0; $i < $loop; $i++) { for ($j = 0; $j < $numkey; $j++) { //echo "<pre>".$keys[$j]." ".$result[$i][$keys[$j]]; if (!empty($result[$i]['ID']) && $keys[$j] == "ID") { $numofstudent++; $numofcourse = -1; $numofgrd = -1; $studentdata[$numofstudent]['studentid'] = $result[$i]['ID'];