Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- if(!isset($_SESSION['userId']))
- header('location:../../');
- else {
- if((!isset($_POST['streamId']) || $_POST['streamId'] =='')
- || (!isset($_POST['branchId']) || $_POST['branchId'] =='')
- || (!isset($_POST['batchId']) || $_POST['batchId'] =='')
- || (!isset($_POST['divisionId']) || $_POST['divisionId'] =='')
- || (!isset($_POST['semId']) || $_POST['semId'] =='')) {
- header('location:../../views/student/list.php');
- }
- $tmp = explode(".", $_FILES["studnetExcel"]["name"]);
- if((strcmp($tmp[1], 'xls')!=0) && (strcmp($tmp[1], 'xlsx')!=0)) {
- echo "string";
- }
- else {
- require_once('../../config/connection.php');
- $streamResult = mysql_query("SELECT * FROM streams WHERE streams_id='".$_POST['streamId']."' ");
- $branchResult = mysql_query("SELECT * FROM branches WHERE streams_id='".$_POST['streamId']."' AND branches_id='".$_POST['branchId']."' ");
- $batchResult = mysql_query("SELECT * FROM batches WHERE streams_id='".$_POST['streamId']."' AND branches_id='".$_POST['branchId']."' AND batches_id='".$_POST['batchId']."'");
- $divisionResult = mysql_query("SELECT * FROM division WHERE division_id='".$_POST['divisionId']."' ");
- $semResult = mysql_query("SELECT * FROM edu_system WHERE streams_id='".$_POST['streamId']."' AND edu_sys_id='".$_POST['semId']."' ");
- if((mysql_num_rows($streamResult) == 1) && (mysql_num_rows($branchResult) == 1) && (mysql_num_rows($batchResult) == 1) && (mysql_num_rows($divisionResult) == 1) && (mysql_num_rows($semResult) == 1)) {
- require_once '../../Classes/PHPExcel/IOFactory.php';
- $objPHPExcel = PHPExcel_IOFactory::load($_FILES["studnetExcel"]["tmp_name"]);
- $value='';
- foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
- $worksheetTitle = $worksheet->getTitle();
- $highestRow = $worksheet->getHighestRow();
- $highestColumn = $worksheet->getHighestColumn();
- $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
- $nrColumns = ord($highestColumn) - 64;
- for ($row = 4; $row <= $highestRow; ++ $row) {
- $value.="(NULL,".$_POST['streamId'].",".$_POST['branchId'].",".$_POST['batchId'].",".$_POST['divisionId'].",".$_POST['semId'].",";
- for ($col = 0; $col < $highestColumnIndex; ++ $col) {
- $cell = $worksheet->getCellByColumnAndRow($col, $row);
- if($col==$highestColumnIndex-1) {
- $value .= "'".$cell->getValue()."',";
- $value .= $_SESSION['role']['id'].","."'active'";
- }
- else {
- if($row>2 && str_replace(' ', '', $worksheet->getCellByColumnAndRow($col, 1)->getValue())=="JoinDate")
- $value .= "'".date('Y-m-d',strtotime($cell->getValue()))."',";
- else
- $value .= "'".$cell->getValue()."',";
- }
- }
- $value .= '),';
- }
- }
- if(mysql_query("INSERT IGNORE INTO students(students_id,streams_id,branches_id,batches_id,division_id,edu_sys_id,annrl_no,first_name,middle_name,last_name,address1,city,state,pincode,address2,gender,cast,blood_group,contact,dob,email,join_date,password,p_contact,p_email,added_by,status) VALUES".substr($value, 0,-1))) {
- $_SESSION['message'] = "STUDENT SUCCESSFULY ADDED";
- header("location:../../views/student/add.php?streamId=".$_POST['streamId']."&branchId=".$_POST['branchId']."&batchId=".$_POST['batchId']."&divisionId=".$_POST['divisionId']."&semId=".$_POST['semId']);
- }
- else {
- if(mysql_errno() == 1062) {
- $inc=-1;
- if(preg_match('/email/', mysql_error())) {
- $inc++;$_SESSION['notify'][$inc] = "STUDENT/PARENTS EMAIL IS ALREADY EXISTED";
- header("location:../../views/student/add.php?streamId=".$_POST['streamId']."&branchId=".$_POST['branchId']."&batchId=".$_POST['batchId']."&divisionId=".$_POST['divisionId']."&semId=".$_POST['semId']);
- }
- else if(preg_match('/annrl_no/', mysql_error())) {
- $inc++;$_SESSION['notify'][$inc] = "ENROLMENT NUMBERs REPEATED";
- header("location:../../views/student/add.php?streamId=".$_POST['streamId']."&branchId=".$_POST['branchId']."&batchId=".$_POST['batchId']."&divisionId=".$_POST['divisionId']."&semId=".$_POST['semId']);
- }
- }
- else {
- echo mysql_error();
- echo mysql_errno();
- }
- }
- }
- else{
- header("location:../../views/student/add.php");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement