Пример #1
0
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;
    }
}
    redirect_to("select_multiple_student_report.php");
}
if (isset($_POST['submit'])) {
    $course_set = array();
    $status_set = array();
    $temp = 1;
    //echo "<pre>";
    // print_r($_POST);
    @($course_set = array_column($_POST['table'], 'course'));
    @($status_set = array_column($_POST['table'], 'status'));
    $loop = sizeof($course_set);
    $studentid = $_SESSION['student']['studentid'];
    //echo $studentid."batman";
    if ($loop >= 1) {
        for ($i = 0; $i <= $loop - 1; $i++) {
            $result = add_foundatation($studentid, $course_set[$i], $status_set[$i]);
        }
        $success = $result;
    } else {
        $success = 1;
    }
    //$result = add_student($values);
    if ($success == 1) {
        $_SESSION['student'] = $_POST;
        echo "<script>";
        echo 'alert("Student Record Added Successfully");';
        echo "window.location.href ='add_student_details.php';";
        echo '</script>';
    }
}
?>