JezK
Edit File: 2021-09-24sa_operations.php
<?php include("error_codes.php"); include("class.phpmailer.php"); include("connect.php"); //define('APP_LOGO_PATH','http://'.$_SERVER[HTTP_HOST].'/school/uploads/'); class sa_operations { /*********************To Escape string quotes*********************/ function getpreventInjections($string) { $safe=mysql_real_escape_string($string); return $safe; } /*********************ADMIN LOGIN AUTHENTICATION*******************/ function admin_login($user,$password) { $user=$this->getpreventInjections($user); $password=$this->encryptIt($password); $sql="select * from ced_t_authentication_details where email='".$user."' and password='".$password."' and school_id=0"; $res=mysql_query($sql); if(mysql_num_rows($res)>0) { $rec=mysql_fetch_array($res); $response[0]=md5(uniqid(rand(), true)); $response[1]=$rec['authenticate_id']; } else { $response=ERR202; } return $response; } /**************************GET ALL SCHOOL FOR LISTING*************************/ function get_Allschoolformanage() { $qry="select school_id,school_name,school_email,school_phone,school_status,school_license from ced_t_school order by school_id desc"; $exe=mysql_query($qry); if(mysql_num_rows($exe)) { while($res=mysql_fetch_assoc($exe)) { $row[]=$res; } return $row; } else return '0'; } /*********************ADD NEW SCHOOL*********************/ function createNewSchool($whodid,$schname,$sch_email,$sch_address,$sch_address1,$phno,$city,$district,$state,$pincode,$website,$contperson,$mobile,$nooflic,$duration,$modules) { $schname=$this->getpreventInjections($schname); $sch_email=$this->getpreventInjections($sch_email); $exist_school=$this->check_email_existance($sch_email); $exist_phone=$this->check_phone_exist($phno); $sch_address=$this->getpreventInjections($sch_address); $sch_address1=$this->getpreventInjections($sch_address1); $city=$this->getpreventInjections($city); $district=$this->getpreventInjections($district); $state=$this->getpreventInjections($state); $pincode=$this->getpreventInjections($pincode); $phno=$this->getpreventInjections($phno); $website=$this->getpreventInjections($website); $contperson=$this->getpreventInjections($contperson); $mobile=$this->getpreventInjections($mobile); $nooflic=$this->getpreventInjections($nooflic); $duration=$this->getpreventInjections($duration); $sch_lic_name=$schname.'_'.date('Y').date('m').date('d').'_'.$nooflic; $emailenc=$schname.''.date('Y-m-d H:i:s'); $savemod=implode(',',$modules); $savemod=rtrim($savemod,','); if(!$exist_phone && !$exist_school) { $shuffler=date('Ymd')."0123456789"; $digit16=substr(str_shuffle($shuffler),0,16); //$digit16=md5(uniqid($emailenc, true)); //school table insertion $qry="insert into ced_t_school set school_name='".$schname."',school_license='".$digit16."',school_email='".$sch_email."',school_address_line_1='".$sch_address."',school_address_line_2='".$sch_address1."',school_phone='".$phno."',school_site_url='".$website."',school_city='".$city."',school_district='".$district."',school_state='".$state."',school_pincode='".$pincode."',school_status=1,created_on='".date('Y-m-d')."',created_by='$whodid'"; $exe=mysql_query($qry); $sch_id=mysql_insert_id(); if($sch_id) { //school license insertion $effectiveDate = date('Y-m-d'); $effectiveDate2 = date('Y-m-d', strtotime("+".$duration." months", strtotime($effectiveDate))); // activating the school licence $insert_lic="insert into ced_t_school_licenses set school_id='".$sch_id."',license_name='".$sch_lic_name."',license_key='".$digit16."',license_count='".$nooflic."',license_valid_months='".$duration."',license_valid_from='".$effectiveDate."',license_valid_to='".$effectiveDate2."',license_status=1,modules_included='".$savemod."',created_by='$whodid'"; mysql_query($insert_lic); $schlic_id=mysql_insert_id(); // school contacts insertion $insert_contact="insert into ced_t_school_contacts set school_id='".$sch_id."',contact_name='".$contperson."',contact_number='".$mobile."',created_on='".date('Y-m-d')."',created_by='$whodid'"; mysql_query($insert_contact); // purchased modules insertions foreach($modules as $val) { $purchase_prevs="insert into ced_t_school_purchased_modules set module_id='".$val."',school_id='".$sch_id."',purchase_date='".date('Y-m-d')."',created_by='$whodid',created_on='".date('Y-m-d')."'"; mysql_query($purchase_prevs); } $send=$this->SendLicenceKeytoSchool($sch_id); $response=ERR203; return $response; } else { $response=ERR204; } } else if($exist_phone) { return 'phone_exist'; } else if($exist_school) { return 'email_exist'; } } /*********************DISPLAY SCHOOL COMPLETE DETAILS*********************/ function viewSchoolDetails($schoolid) { $qry="select s.school_name,s.school_email,s.school_address_line_1,s.school_address_line_2,s.school_phone,s.school_site_url,s.school_city,s.school_district,s.school_state,s.school_pincode,c.contact_name,c.contact_number from ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$schoolid; $exe=mysql_query($qry); $row=mysql_fetch_array($exe); $record['school_name']=$row['school_name']; $record['school_email']=$row['school_email']; $record['school_address']=$row['school_address_line_1']; $record['school_address1']=$row['school_address_line_2']; $record['school_contact']=$row['school_phone']; $record['school_city']=$row['school_city']; $record['school_district']=$row['school_district']; $record['school_state']=$row['school_state']; $record['school_pincode']=$row['school_pincode']; $record['school_site_url']=$row['school_site_url']; $record['contact_name']=$row['contact_name']; $record['contact_number']=$row['contact_number']; $mpurchase="select module_id from ced_t_school_purchased_modules where school_id='$schoolid' order by module_id asc"; $mexe=mysql_query($mpurchase); while($res=mysql_fetch_array($mexe)) { $rec[]=$res['module_id']; } $record['purchase_modules']=$rec; $licinfo="select license_count,license_valid_from,license_valid_to,license_key from ced_t_school_licenses where school_id='$schoolid' order by school_license_id desc"; $lexe=mysql_query($licinfo); $lrec=mysql_fetch_array($lexe); $record['license_count']=$lrec['license_count']; $record['license_key']=$lrec['license_key']; $d1=str_replace('-','/',$lrec['license_valid_from']); $d2=str_replace('-','/',$lrec['license_valid_to']); $record['validity']=date('d/m/Y',strtotime($d1)).' to '.date('d/m/Y',strtotime($d2)); return $record; } /*********************UPDATE SCHOOL INFO*********************/ function update_school_details($me,$schid,$schname,$sch_email,$sch_address,$sch_address1,$phno,$city,$district,$state,$pincode,$website,$contperson,$mobile,$nooflic,$duration,$modules,$prev_mods) { $sch_email=$this->getpreventInjections($sch_email); $exist_school=$this->check_email_existance_check($sch_email,$schid); $exist_phone=$this->check_phone_exist_edit($phno,$schid); $schname=$this->getpreventInjections($schname); $sch_address=$this->getpreventInjections($sch_address); $sch_address1=$this->getpreventInjections($sch_address1); $city=$this->getpreventInjections($city); $district=$this->getpreventInjections($district); $state=$this->getpreventInjections($state); $pincode=$this->getpreventInjections($pincode); $phno=$this->getpreventInjections($phno); $website=$this->getpreventInjections($website); $contperson=$this->getpreventInjections($contperson); $mobile=$this->getpreventInjections($mobile); //return $prev_modules; if(!$exist_phone && !$exist_school) { $sql = "UPDATE `ced_t_school` SET `school_name` = '".$schname."',`school_email` = '".$sch_email."',`school_address_line_1` = '".$sch_address."', `school_address_line_2` = '".$sch_address1."',`school_phone` = '".$phno."',school_city='".$city."',school_district='".$district."',school_state='".$state."',school_pincode='".$pincode."', `school_site_url` = '".$website."',updated_by='$me' WHERE `school_id`=".(int)$schid; //echo $sql; $res = mysql_query($sql); $authen="update ced_t_authentication_details set email='".$phno."',updated_by='$me' where school_id='$schid' and school_su=1"; mysql_query($authen); $contupd="update ced_t_school_contacts set contact_name='".$contperson."',contact_number='".$mobile."',updated_by='$me' where school_id=".(int)$schid; mysql_query($contupd); $prev_mods=explode(',',rtrim($prev_mods,',')); for($i=1;$i<=6;$i++) { if(in_array($i,$prev_mods)) { if(in_array($i,$modules)) { } else { $sql_remove = 'DELETE FROM `ced_t_school_purchased_modules` WHERE `school_id` = "'.$schid.'" and `module_id` = "'.$i.'"'; $res_remove = mysql_query($sql_remove); } } else { if(in_array($i,$modules)) { $insert_prev="insert into ced_t_school_purchased_modules set module_id='".$i."',school_id='".$schid."',purchase_date='".date('Y-m-d')."',created_by='$me',created_on='".date('Y-m-d')."'"; mysql_query($insert_prev); } } } $imprev=trim(implode(',',$modules),',');; $latestprevs="update ced_t_school_licenses set modules_included='".$imprev."' where school_id=".(int)$schid; mysql_query($latestprevs); return 'ok'; } else if($exist_phone) { return 'exist_phone'; } else if($exist_school) { return 'email_exist'; } else { return ERR204; } } /*********************GET SCHOOL DETAILS FOR UPDATE*********************/ function getSchoolDetailsforUpdate($id) { $editschool=array(); $sql="select * from ced_t_school where school_id=".(int)$id; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $res=mysql_fetch_array($exe); $record['school_name']=$res['school_name']; $record['school_email']=$res['school_email']; $record['school_address_line_1']=$res['school_address_line_1']; $record['school_address_line_2']=$res['school_address_line_2']; $record['school_phone']=$res['school_phone']; $record['school_site_url']=$res['school_site_url']; $record['school_city']=$res['school_city']; $record['school_district']=$res['school_district']; $record['school_state']=$res['school_state']; $record['school_pincode']=$res['school_pincode']; $contqry="select * from ced_t_school_contacts where school_id='".$id."'"; $licexe=mysql_query($contqry); if(mysql_num_rows($licexe)) { $licres=mysql_fetch_array($licexe); $record['contact_name']=$licres['contact_name']; $record['contact_number']=$licres['contact_number']; } $prevqry="select license_count,license_valid_months from ced_t_school_licenses where school_id='".$id."' order by school_license_id desc"; $prevexe=mysql_query($prevqry); if(mysql_num_rows($prevexe)) { $prevres=mysql_fetch_array($prevexe); { $record['license_count']=$prevres['license_count']; $record['valid_months']=$prevres['license_valid_months']; } } return $record; } else { return ERR205; } } /*********************DELETE SCHOOL IF NO RECORDS BOUND WITH IT********************/ function deletetheSchool($school_id) { $sql1="select school_id from ced_t_academicyear where school_id=".(int)$school_id; $exe1=mysql_query($sql1); $sql2="select school_id from ced_t_class where school_id=".(int)$school_id; $exe2=mysql_query($sql2); $sql3="select school_id from ced_t_subjects where school_id=".(int)$school_id; $exe3=mysql_query($sql3); if(mysql_num_rows($exe1) || mysql_num_rows($exe2) || mysql_num_rows($exe3)) { return 'AEBT'; } else { $qry="delete from ced_t_school where school_id=".(int)$school_id; mysql_query($qry); $qry1="delete from ced_t_school_licenses where school_id=".(int)$school_id; mysql_query($qry1); $qry2="delete from ced_t_school_contacts where school_id=".(int)$school_id; mysql_query($qry2); $qry3="delete from ced_t_school_purchased_modules where school_id=".(int)$school_id; mysql_query($qry3); $qry4="delete from ced_t_authentication_details where school_id=".(int)$school_id; mysql_query($qry4); return 'ok'; } } /******************* Funciton for getting app details*************/ function gettingAppDetails() { $data=array(); $sql="SELECT `details_id`,`app_logo`,`app_name`,`sender_mail`,`support_mail`,`domain` FROM `ced_t_app_details` where `details_id`=1"; $result=mysql_query($sql); if(mysql_num_rows($result)>0) { $row=mysql_fetch_array($result); $data['details_id']=$row['details_id']; //$data['app_logo']=APP_LOGO_PATH.$row['app_logo']; $data['app_logo']=ADMIN_PATH."uploads/".$row['app_logo']; $data['app_name']=$row['app_name']; $data['sender_mail']=$row['sender_mail']; $data['support_mail']=$row['support_mail']; $data['domain']=$row['domain']; } return $data; } /**************************ACTIVATE OR DEACTIVATE SCHOOL*************************/ function activateORdeactivateschool($id,$whodid,$status) { $appdetails=$this->gettingAppDetails(); $show=0; $qry="update ced_t_school set school_status='$status',school_status_updated_by='$whodid',updated_by='$whodid' where school_id=".(int)$id; $exe=mysql_query($qry); if(mysql_affected_rows()) { if($status==1) { $lic_info=$this->get_All_licensesOfschool($id); if($lic_info!=0) foreach($lic_info as $lic) { if($lic[license_valid_to] > date('Y-m-d')) { $lic_active="update ced_t_school_licenses set license_status=1 where school_license_id=".(int)$lic['school_license_id']; mysql_query($lic_active); } } //////////////////////SEND ACTIVATION MAIL $sql="SELECT s.school_name,s.school_email,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$id; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $avail_license="SELECT sum(license_count) as available_lic FROM `ced_t_school_licenses` WHERE `license_valid_to` > CURRENT_DATE and license_status=1 and school_id=".(int)$id; $lcount=mysql_query($avail_license); if(mysql_num_rows($lcount)) { $show=mysql_fetch_array($lcount); } $subject="Reactivation of ".$appdetails['app_name']." for ".$res[school_name]; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>This is to kindly inform you that your school has been reactivated. You have a total of ".$show[available_lic]." active licenses for ".$appdetails['app_name']." Parent App.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p> <p>Thanking you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); } else if($status==0) { $lic_info=$this->get_All_licensesOfschool($id); if($lic_info!=0) foreach($lic_info as $lic) { $qry1="update ced_t_school_licenses set license_status=0 where school_license_id=".(int)$lic['school_license_id']; $qry2="update ced_t_student_licenses set license_status=0 where school_license_id=".(int)$lic['school_license_id']; mysql_query($qry1); mysql_query($qry2); $notify="SELECT s.student_firstname,s.student_lastname,l.student_id,sp.device_id FROM `ced_t_student_licenses` l JOIN ced_t_students_parent sp on l.student_id=sp.student_id join ced_t_students s on sp.student_id=s.student_id WHERE l.`school_license_id`=".(int)$lic['school_license_id']; $get=mysql_query($notify); if(mysql_num_rows($get)) { while($off=mysql_fetch_array($get)) { if($off['device_id']!='') { $msg['type']="lic_status"; $msg['message']=$off['student_firstname']." ".$off['student_lastname']." has been deactivated. Please contact school admin"; $msg['student_id']=$off['student_id']; $this->send_notice($off['device_id'],$msg); } } } } //////////////////////SEND DEACTIVATION MAIL $sql="SELECT s.school_name,s.school_email,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$id; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $subject="Deactivation of ".$appdetails['app_name']." for ".$res[school_name]; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>This is to kindly inform you that your school has been deactivated. Please reach our support team at ".$appdetails['support_mail']." to reactivate the school.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p> <p>Thanking you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); } return '100'; } else { return '101'; } } /*********************REGENERATE SCHOOL LICENCE KEY******************/ function getReGenerateLicenceKey($school_id,$whodid) { $sql="select school_id,school_email from ced_t_school where school_id='".$school_id."'"; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $emailenc=$res['school_email']; $shuffler=date('Ymd')."0123456789abcdefghijklm"; $digit16=substr(str_shuffle($shuffler),0,16); //$digit16=md5(uniqid($emailenc, true)); $qry="update ced_t_school set school_license='".$digit16."',school_status_updated_by='$whodid',updated_by='$whodid' where school_id='".$school_id."'"; $upd=mysql_query($qry); $qry1="update ced_t_school_licenses set license_key='".$digit16."',created_by='$whodid' where school_id=".(int)$school_id; mysql_query($qry1); $sent=$this->SendLicenceKeytoSchool($school_id); if($sent) return '1'; else return '0'; } /*********************DISPLAY SCHOOL LICENSE INFO ******************/ function get_All_licensesOfschool($schid) { $sql="select * from ced_t_school_licenses where school_id=".(int)$schid; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { while($res=mysql_fetch_assoc($exe)) { $row[]=$res; } return $row; } else return '0'; } /*********************ADD NEW LICENSE TO SCHOOL ********************/ function add_licensetoSchool($sch_id,$schname,$license_count,$duration) { $appdetails=$this->gettingAppDetails(); $mods=array(); $prevmod="select module_id from ced_t_school_purchased_modules where school_id=".(int)$sch_id; $exemod=mysql_query($prevmod); while($resmod=mysql_fetch_array($exemod)) { $mods[]=$resmod['module_id']; } /*foreach($modules as $mod) { if(in_array($mod,$mods)) { } else { $qry="insert into ced_t_school_purchased_modules set module_id='".$mod."',purchase_date='".date('Y-m-d')."',school_id='".$sch_id."',created_by='1',created_on='".date('Y-m-d')."'"; mysql_query($qry); } }*/ $modules_include=implode(',',$mods); $modules_include=rtrim($modules_include,','); $schname=$schname.'_'.date('Ymd').'_'.$license_count; $check="select school_license from ced_t_school where school_id=".(int)$sch_id; $exe=mysql_query($check); $res=mysql_fetch_array($exe); $license_key=$res['school_license']; $effectiveDate1=date('Y-m-d'); $effectiveDate2= date('Y-m-d', strtotime("+".$duration." months", strtotime($effectiveDate1))); $sql="insert into ced_t_school_licenses set school_id='".$sch_id."',license_name='".$schname."',license_key='".$license_key."',license_count='".$license_count."',license_valid_from='".$effectiveDate1."',license_valid_to='".$effectiveDate2."',license_valid_months='".$duration."',license_status='1',modules_included='".$modules_include."',created_by=1"; mysql_query($sql); $sql="SELECT s.school_name,s.school_email,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$sch_id; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $subject="Purchase of ".$appdetails['app_name']." Licenses"; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p><br> <p>Thank you for purchasing ".$license_count." number of ".$appdetails['app_name']." Parent App licenses. The validity of these licenses is ".$duration." Month(s) and the expiry date is ".date('d/m/Y',strtotime($effectiveDate2)).". Please ensure to renew these licenses before the expiry date.</p><br> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p><br> <p>Thanking you once again for selecting our services</p><br> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); } /*********************GET SCHOOL NAME BY SCHOOL ID********************/ function getschool_nameById($schid) { $sql="select school_name from ced_t_school where school_id=".(int)$schid; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); return $res['school_name']; } /*********************SEND LICENSE KEY TO SCHOOL********************/ function SendLicenceKeytoSchool($schoolid) { $appdetails=$this->gettingAppDetails(); $sql1="select license_count,license_valid_months,license_valid_to from ced_t_school_licenses where school_id=".(int)$schoolid." order by school_license_id asc limit 1"; $lc=mysql_query($sql1); $lres=mysql_fetch_array($lc); $sql="SELECT s.school_name,s.school_email,s.school_phone,s.school_license,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$schoolid; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $crpt=$this->encryptIt($res[school_license]); $crpt=urlencode($crpt); $qry="select m.module_name from ced_t_school_modules m inner join ced_t_school_purchased_modules s on m.module_id=s.module_id where school_id=".(int)$schoolid." order by s.module_id"; $row=mysql_query($qry); while($result=mysql_fetch_array($row)) { $mods.='<li>'.$result[module_name].'</li>'; } $subject = "Welcome to ".$appdetails['app_name']; $message = " <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>Thank you for registering with ".$appdetails['app_name'].". You have selected the following products / services offered by us:</p> <ul>".$mods."</ul> <p>To complete the registration process and access all the features linked to your account<a href='".ADMIN_PATH."registration.php?authid=".$crpt."®on=".$res[school_phone]."'> click here</a> and enter the following <b>License Key:</b></p> <p>".$res[school_license]."</p> <p>You have purchased ".$lres[license_count]." number of ".$appdetails['app_name']." Parent App licenses. The validity of these licenses is ".$lres[license_valid_months]." Month(s) and the expiry date is ".date('d-m-Y',strtotime($lres[license_valid_to])).". Please ensure to renew these licenses before the expiry date.</p> <p>Once registered, you would be able to login into ".$appdetails['app_name']." using ".$appdetails['domain'].". You would also be provided access to the following mobile apps:</p> <ul> <li>Parent App - Available on Google Play Store</li> <li>Teacher App - Will be separately provided</li> <li>Driver App - Will be separately provided</li></ul> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail']."</p> <p>Thanking you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); if($sent) return '1'; else return '0'; } function mailsend($mailto,$msg,$subject) { $mail = new PHPMailer(); $mail->IsSendmail(); $body = $msg;//file_get_contents('contents.html'); $mail->SetFrom('anil@krify.net', 'anil'); $address = $mailto; $mail->AddAddress($address); $mail->Subject = $subject; $mail->MsgHTML($body); $status=$mail->Send(); return $status; } function check_phone_exist($phone) { $qry="select school_id from ced_t_school where school_phone='".$phone."'"; $res=mysql_query($qry); $cnt1=mysql_num_rows($res); $qry1="select staff_id from ced_t_school_staff where staff_mobile='".$phone."'"; $res1=mysql_query($qry1); $cnt2=mysql_num_rows($res1); if($cnt1==0 && $cnt2==0) return 0; else return 1; } function check_phone_exist_edit($phone,$schid) { $qry="select school_id from ced_t_school where school_phone='".$phone."' and school_id<>".(int)$schid; $res=mysql_query($qry); $cnt1=mysql_num_rows($res); $qry1="select staff_id from ced_t_school_staff where staff_mobile='".$phone."'"; $res1=mysql_query($qry1); $cnt2=mysql_num_rows($res1); if($cnt1==0 && $cnt2==0) return 0; else return 1; } /*********************CHECK EMAIL IS EXIST IN THE SYSTEM OR NOT********************/ function check_email_existance($email) { //$sql = 'SELECT `email` FROM `ced_t_authentication_details` WHERE `email` = "'.$email.'" and parent_app_access<>1'; $sql="select staff_id from ced_t_school_staff where staff_email='".$email."'"; $res = mysql_query($sql); $cnt1 = mysql_num_rows($res); $sql1="select school_email from ced_t_school where school_email='".$email."'"; $res1 = mysql_query($sql1); $cnt2 = mysql_num_rows($res1); if($cnt1==0 && $cnt2==0) return 0; else return 1; } /*********************CHECK EMAIL IS EXIST IN THE SYSTEM OR NOT FOR EDIT********************/ function check_email_existance_check($email,$schid) { $sql1="select school_email from ced_t_school where school_email='".$email."' and school_id<>".(int)$schid; $res1 = mysql_query($sql1); $cnt1 = mysql_num_rows($res1); //$sql2 = 'SELECT `email` FROM `ced_t_authentication_details` WHERE `email` = "'.$email.'" and school_id='.(int)$schid.' and school_su<>1 and parent_app_access<>1'; $sql2="select staff_email from ced_t_school_staff where staff_email='".$email."' and school_id<>".(int)$schid; $res2 = mysql_query($sql2); $cnt2 = mysql_num_rows($res2); if($cnt1==0 && $cnt2==0) return 0; else return 1; } /*********************GET SCHOOL LICENCE ID*********************/ function get_lic_id_school($sch_id) { $sql = 'SELECT `schlic_id` FROM `ced_t_school_licenses` WHERE `school_id` = "'.$sch_id.'"'; $res = mysql_query($sql); $row = mysql_fetch_array($res); return $row['schlic_id']; } /*********************GET SCHOOL PREVILAGES*********************/ function get_school_privileges($sch_id) { $sql = 'SELECT purchased_module_id,module_id FROM ced_t_school_purchased_modules WHERE `school_id` = "'.$sch_id.'"'; $res = mysql_query($sql); if(mysql_num_rows($res) > 0) { $status['res'] = '1'; while($row = mysql_fetch_array($res)) { $data[] = $row['module_id']; } $status['result'] = $data; } else { $status['res'] = '0'; } return $status; } /******************************SUPER ADMIN CHANGE PASSWORD**************/ function superadmin_settigs_change_password($email,$current_password,$new_password) { $current_password=$this->encryptIt($current_password); $new_password=$this->encryptIt($new_password); $sql="SELECT `authenticate_id` FROM `ced_t_authentication_details` WHERE `email`='".$email."' and `password`='".$current_password."' and `school_id`='0' and `status`='0' "; $result=mysql_query($sql); $row=mysql_fetch_array($result); if(mysql_num_rows($result)>0) { $sql2="UPDATE `ced_t_authentication_details` SET `password`='".$new_password."' where `email`='".$email."' and `authenticate_id`='".$row['authenticate_id']."' "; $result2=mysql_query($sql2); if($result2) { $error=1; } else { $error=2; } } else { $error=3; } return $error; } /***********GET SUPER ADMIN EMAIL***********/ function get_authentication_email($authid) { $sql="SELECT `email` FROM `ced_t_authentication_details` WHERE `authenticate_id`='".$authid."'"; $result=mysql_query($sql); $row['email']=mysql_fetch_array($result); return $row['email']; } /*********************MAKE DEACTIVE SCHOOL(DEPRICIATED)*********************/ function getActive_DeActiveSchool($sch_id) { $sql="update ced_t_school set school_status='0' where school_id='".$sch_id."'"; $exe=mysql_query($sql); if(mysql_affected_rows()) { return ERR207; } } /********************* EMAIL THE PASSWORD *********************/ function forgotpwd_sendpasswordbyemail($email) { $appdetails=$this->gettingAppDetails(); $qexist="SELECT `password` FROM `ced_t_authentication_details` WHERE `email` ='".$email."' and `school_id`='0' and `status`='0' "; $exe=mysql_query($qexist); if(mysql_num_rows($exe)>0) { $password=mysql_fetch_array($exe); $pwd=$this->decryptIt($password['password']); $to = $email; $subject = "Forgot Password: ".$appdetails['app_name']; $message = ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-family:verdana,arial,san-sarif;"> <tr><td align="left" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td valign="top" align="center"> <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center"> <tr> <td colspan="2" style="padding:0px 10px" align="center" height="75" valign="middle" width="150"> <img src="#" alt="" align="center" > </td> </tr> </table> </td></tr> <tr><td align="left" valign="top"> </td></tr> <tr> <td style="" align="left" valign="top"> <b>You have requested for forgot password. Your Password is <font color="blue">'.$pwd.'.</font> You may Login now</b><br/> </td> </tr> <tr><td><br/><br/> Thanks and Regards,<br/> '.$appdetails['app_name'].' Team<br/> </td></tr> </table> </td></tr> </table>'; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8"; $headers .= "From: ".$appdetails['app_name']." <".$appdetails['sender_mail'].">"; $sent=mail($to,$subject,$message,$headers); //$mailer=$this->sendingemail($to,$subject,$message); //return 1; if($sent) return 1; else return 2; } else { return 3; } } /*************************ENCRYPTION FUNCTION FOR PRIVATE KEYS*************************/ function encryptIt($q) { $cryptKey = 'qJB0rGtIn5UB1xG03efyCp'; $qEncoded = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) ); return( $qEncoded ); } /*************************GET LICENSE DETAILS BY LICENSE ID*************************/ function get_licenseSetInfo($lid) { $sql="select s.school_name,s.school_id,sl.* from ced_t_school_licenses sl inner join ced_t_school s on s.school_id=sl.school_id where school_license_id=".(int)$lid; $exe=mysql_query($sql); if(mysql_num_rows($exe)) { $row=mysql_fetch_array($exe); $data['school_name']=$row['school_name']; $data['school_id']=$row['school_id']; $data['license_count']=$row['license_count']; $data['license_valid_from']=date('Y-m-d',strtotime($row['license_valid_from'])); $data['license_valid_to']=date('Y-m-d',strtotime($row['license_valid_to'])); $data['modules_included']=$row['modules_included']; return $data; } } function check_password($pass,$uid) { $sql="SELECT `password` FROM `ced_t_authentication_details` WHERE `authenticate_id` = '".$uid."' "; $result=mysql_query($sql); $row=mysql_fetch_array($result); $pwd=$this->decryptIt($row['password']); return $pwd; } /*************************SECRET KEY DECRYPT FUNCTION*************************/ function decryptIt($q) { $cryptKey = 'qJB0rGtIn5UB1xG03efyCp'; $qDecoded = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0"); return( $qDecoded ); } /*************************RENEWAL LICENSE BY LICENSE ID*************************/ function renewal_this_license($lcid,$months,$start,$end,$schid,$count) { $appdetails=$this->gettingAppDetails(); $qry="update ced_t_school_licenses set license_valid_from='".$start."',license_valid_to='".$end."',license_valid_months='".$months."',license_status=1 where school_license_id=".(int)$lcid; $q=mysql_query($qry); $sql="SELECT s.school_name,s.school_email,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$schid; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $subject="Renewal of ".$appdetails['app_name']." Licenses"; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>Thank you for renewing ".$count." number of ".$appdetails['app_name']." Parent App licenses. The validity of these licenses is ".$months." Month(s) and the expiry date is ".date('d/m/Y',strtotime($end)).". Please ensure to renew these licenses before the expiry date.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['sender_mail'].".</p> <p>Thank you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); return 'ok'; } /*************************ACTIVATE OR DEACTIVATE LICENSE*************************/ function deactivatetheLicense($licid,$sts) { $appdetails=$this->gettingAppDetails(); $keepactive=0; $sql="select l.license_count,s.school_id,s.school_name,s.school_email,c.contact_name from ced_t_school_licenses l,ced_t_school s,ced_t_school_contacts c where l.school_id=s.school_id and s.school_id=c.school_id and l.school_license_id=".(int)$licid; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); if($sts=='up') { $qry1="update ced_t_school_licenses set license_status=1 where school_license_id=".(int)$licid; $qry2="update ced_t_student_licenses set license_status=1 where school_license_id=".(int)$licid; mysql_query($qry1); //mysql_query($qry2); $email=$res[school_email]; $subject="Reactivation of ".$appdetails['app_name']." Licenses"; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>This is to kindly inform you that '".$res[license_count]."' number of ".$appdetails['app_name']." Parent App licenses have been reactivated for your school.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p> <p>Thank you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); $qry3="update ced_t_school set school_status=1 where school_id=".(int)$res[school_id]; mysql_query($qry3); $notify="SELECT s.student_firstname,s.student_lastname,l.student_id,sp.device_id FROM `ced_t_student_licenses` l JOIN ced_t_students_parent sp on l.student_id=sp.student_id join ced_t_students s on sp.student_id=s.student_id WHERE l.`school_license_id`=".(int)$licid; $get=mysql_query($notify); if(mysql_num_rows($get)) { while($off=mysql_fetch_array($get)) { if($off['device_id']!='') { $msg['type']="lic_status"; $msg['message']=""; $msg['student_id']=$off['student_id']; $this->send_notice($off['device_id'],$msg); } } } } else { $qry1="update ced_t_school_licenses set license_status=0 where school_license_id=".(int)$licid; $qry2="update ced_t_student_licenses set license_status=0 where school_license_id=".(int)$licid; mysql_query($qry1); mysql_query($qry2); $email=$res[school_email]; $subject="Deactivation of ".$appdetails['app_name']." Licenses"; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>This is to kindly inform you that '".$res[license_count]."' number of ".$appdetails['app_name']." Parent App licenses have been deactivated for your school. Please reach our support team at ".$appdetails['support_mail']." if you wish to reactivate these licenses.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p> <p>Thank you for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); $lic_info=$this->get_All_licensesOfschool($res['school_id']); if($lic_info!=0) foreach($lic_info as $lic) { if($lic[license_status]==1) { $keepactive=1; } } if($keepactive==0) { $deactive="update ced_t_school set school_status=0 where school_id=".(int)$res['school_id']; mysql_query($deactive); //////////////////////SEND DEACTIVATION MAIL $sql="SELECT s.school_name,s.school_email,c.contact_name FROM ced_t_school s inner join ced_t_school_contacts c on s.school_id=c.school_id where s.school_id=".(int)$res[school_id]; $exe=mysql_query($sql); $res=mysql_fetch_array($exe); $email=$res[school_email]; $subject="Deactivation of ".$appdetails['app_name']." for ".$res[school_name]; $message=" <html> <head> <title>".$appdetails['app_name']."</title> </head> <body> <p>Dear ".$res['contact_name']."(".$res[school_name]."),</p> <p>This is to kindly inform you that your school has been deactivated. Please reach our support team at ".$appdetails['support_mail']." to reactivate the school.</p> <p>If you have any questions related to your account, you can email us at ".$appdetails['support_mail'].".</p> <p>Thanking you once again for selecting our services</p> <address>Warm Regards,<br> ".$appdetails['app_name']." Team</address> </body> </html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: '.$appdetails['app_name'].' <'.$appdetails['sender_mail'].'>'; $headers .= 'Cc: '.$appdetails['sender_mail']; $sent=mail($email,$subject,$message,$headers); } $notify="SELECT s.student_firstname,s.student_lastname,l.student_id,sp.device_id FROM `ced_t_student_licenses` l JOIN ced_t_students_parent sp on l.student_id=sp.student_id join ced_t_students s on sp.student_id=s.student_id WHERE l.`school_license_id`=".(int)$licid; $get=mysql_query($notify); if(mysql_num_rows($get)) { while($off=mysql_fetch_array($get)) { if($off['device_id']!='') { $msg['type']="lic_status"; $msg['message']=$off['student_firstname']." ".$off['student_lastname']." has been deactivated. Please contact school admin"; $msg['student_id']=$off['student_id']; $this->send_notice($off['device_id'],$msg); } } } } } function send_notice($registatoin_ids,$msg) { $registatoin_ids=array($registatoin_ids); $googleapi='AIzaSyDfQ9YXKCJEKgaush2VudGeZNCivxHBOh8'; $url = 'https://android.googleapis.com/gcm/send'; $fields = array('registration_ids' => $registatoin_ids,'data' => $msg); $headers = array('Authorization: key='.$googleapi,'Content-Type: application/json'); // Open connection $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } } ?>