Esempio n. 1
0
 public static function SyncZavodiWhereKategorijaActive()
 {
     $schoolCategories = SchoolCategory::model()->findAll('active=:active', array(':active' => 1));
     $kategorije = array();
     $kategorija_map = array();
     foreach ($schoolCategories as $schoolCategory) {
         $kategorije[] = $schoolCategory->name;
         $kategorija_map[$schoolCategory->name] = $schoolCategory->id;
     }
     echo "Current categories for sync:<br />";
     pre_print($kategorije);
     $list = self::GetRegZavod();
     if (!isset($list['return'])) {
         return array();
     }
     $list = $list['return'];
     echo "Current schools to sync:<br />";
     $country = Country::model()->find('country=:country', array(':country' => 'Slovenija'));
     if ($country == null) {
         echo "Add country Slovenija!<br />\n";
         die;
     }
     $country_id = $country->id;
     // cache all občine
     $municipalities = Municipality::model()->findAll('country_id=:country_id', array(':country_id' => $country_id));
     $municipality_map = array();
     foreach ($municipalities as $municipality) {
         $municipality_map[$municipality->name] = $municipality->id;
     }
     // cache all regije
     $regions = Region::model()->findAll('country_id=:country_id', array(':country_id' => $country_id));
     $region_map = array();
     foreach ($regions as $region) {
         $region_map[$region->name] = $region->id;
     }
     $counter = 0;
     $updated = 0;
     $inserted = 0;
     for ($i = 0; $i < count($list); ++$i) {
         if (in_array($list[$i]['KATEGORIJA'], $kategorije)) {
             $counter++;
             $el = $list[$i];
             $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => trim($el['ZAVOD_NAZIV']), ':country_id' => $country_id));
             if ($school == null) {
                 $school = new School();
                 $school->name = trim($el['ZAVOD_NAZIV']);
                 $school->country_id = $country_id;
                 $inserted++;
             }
             $school->school_category_id = $kategorija_map[trim($el['KATEGORIJA'])];
             // občina
             if (!isset($municipality_map[trim($el['OBCINANAZIV'])])) {
                 $municipality = new Municipality();
                 $municipality->name = trim($el['OBCINANAZIV']);
                 $municipality->country_id = $country_id;
                 $municipality->save();
                 $municipality_map[trim($el['OBCINANAZIV'])] = $municipality->id;
             }
             $school->municipality_id = $municipality_map[trim($el['OBCINANAZIV'])];
             // regija
             if (!isset($region_map[trim($el['REGIJANAZIV'])])) {
                 $region = new Region();
                 $region->name = trim($el['REGIJANAZIV']);
                 $region->country_id = $country_id;
                 $region->save();
                 $region_map[trim($el['REGIJANAZIV'])] = $region->id;
             }
             $school->region_id = $region_map[trim($el['REGIJANAZIV'])];
             $school->post = trim($el['POSTANAZIV']);
             $school->postal_code = trim($el['POSTASIFRA']);
             $school->identifier = trim($el['ZAVPRS']);
             $school->headmaster = trim($el['ZAVRAVN']);
             if (isset($el['ZAVDAVST'])) {
                 $school->tax_number = trim($el['ZAVDAVST']);
             }
             if ($school->save()) {
                 $updated++;
             }
         }
     }
     echo 'Found schools to sync: ', $counter, "<br />\n";
     echo 'New schools imported: ', $inserted, "<br />\n";
     echo 'Updated schools: ', $updated - $inserted, "<br />\n";
 }
Esempio n. 2
0
 public function calculateCompetitionAwards($competition_id, $competition_category_id)
 {
     // reset awards to null to all competitiors
     CompetitionUser::model()->updateAll(array('award' => NULL), 'competition_id=:competition_id and competition_category_id=:competition_category_id', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id));
     $cus = CompetitionUser::model()->findAll('competition_id=:competition_id and competition_category_id=:competition_category_id and disqualified=:disqualified', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id, ':disqualified' => 0));
     $whole_competition = array();
     $competition_per_school = array();
     $totalpoints = 0;
     foreach ($cus as $cu) {
         if ($cu == null) {
             $cu = new CompetitionUser();
         }
         $result = $cu->getCompetitionNumericResult(true);
         if ($totalpoints == 0) {
             $totalpoints = (int) $result['totalpoints'];
         }
         $whole_competition[] = array('id' => $cu->id, 'result' => (int) $result['result']);
         if (!isset($competition_per_school[$cu->school_id])) {
             $competition_per_school[$cu->school_id] = array();
         }
         $competition_per_school[$cu->school_id][] = array('id' => $cu->id, 'result' => (int) $result['result']);
     }
     Generic::orderBy($whole_competition, 'order by result desc', false, true);
     // 1/5 najboljših na tekmovanju prejme bronasto priznanje
     $awarded_users = array();
     $petina = ceil(count($whole_competition) / 5);
     $last_result = 0;
     for ($i = 0; $i < $petina; ++$i) {
         $awarded_users[] = $whole_competition[$i]['id'];
         $last_result = $whole_competition[$i]['result'];
     }
     // add users with same result as the last one in petina
     for ($i = $petina; $i < count($whole_competition); ++$i) {
         if ($last_result == $whole_competition[$i]['result']) {
             $awarded_users[] = $whole_competition[$i]['id'];
         } else {
             break;
         }
     }
     // max 1/3 na šoli, če le dosežejo tekmovalci vsaj polovico vseh točk
     $totalpointshalf = round($totalpoints / 2);
     $awards_per_school = array();
     foreach ($competition_per_school as $school_id => $competitors) {
         $awards_per_school[$school_id] = 0;
         Generic::orderBy($competitors, 'order by result desc', false, true);
         echo "Competitors on school with ID: ", $school_id, "<br />";
         pre_print($competitors);
         $tretjina = ceil(count($competitors) / 3);
         $process_edge = true;
         // če je pred tretjino tekmovalec z manj kot polovico točk, ne gledamo več tekmovalcev ob robu tretjine
         $last_result = 0;
         for ($i = 0; $i < $tretjina; ++$i) {
             if ($competitors[$i]['result'] >= $totalpointshalf) {
                 if (!in_array($competitors[$i]['id'], $awarded_users)) {
                     $awarded_users[] = $competitors[$i]['id'];
                 }
                 $awards_per_school[$school_id]++;
                 $last_result = $competitors[$i]['result'];
             } else {
                 $process_edge = false;
             }
         }
         if ($process_edge) {
             for ($i = $tretjina; $i < count($competitors); ++$i) {
                 if ($last_result == $competitors[$i]['result']) {
                     if (!in_array($competitors[$i]['id'], $awarded_users)) {
                         $awarded_users[] = $competitors[$i]['id'];
                     }
                     $awards_per_school[$school_id]++;
                 } else {
                     break;
                 }
             }
         }
     }
     echo "Awards per school: <br />";
     pre_print($awards_per_school);
     // save awards to database
     for ($i = 0; $i < count($awarded_users); ++$i) {
         CompetitionUser::model()->updateAll(array('award' => 5), 'id=:id', array(':id' => $awarded_users[$i]));
     }
     return true;
 }
Esempio n. 3
0
 /**
  * @author Gaurav Dhiman.
  * @method forget_password	
  */
 public function forget_password()
 {
     pre_print($_POST);
     $this->load->view('admin/others/login');
 }
Esempio n. 4
0
 /**
  * @author Ankush.
  * @method student by Birthday listing
  */
 public function generateGRnum($standard = '', $pref = 'std')
 {
     $grNum = $this->model_student->grNum($standard);
     $new_gr = '';
     if (is_numeric($grNum['gr_num'])) {
         $new_gr = $grNum['gr_num'] + 1;
         echo $new_gr;
         exit;
     } else {
         if ($pref != '') {
             list($alpha, $numeric) = sscanf($grNum['gr_num'], "%[A-Z]%[0-9]");
             pre_print($numeric);
         }
         exit;
     }
 }
 * 
 * 
 */
require 'bitcoinCharts.php';
$bitcoinCharts = new BitcoinCharts();
/*
 * Weighted Prices
 */
$weightedPrices = $bitcoinCharts->weighted_prices();
pre_print($weightedPrices, 'Weighted Prices');
/*
 * Markets Data
 */
$marketsData = $bitcoinCharts->markets();
pre_print($marketsData, 'Markets Data');
/*
 * Historic Trade Data
 */
$tradeData = $bitcoinCharts->trades(array('symbol' => 'mtgoxUSD'));
pre_print($tradeData, 'Historical Trade Data');
/*
 * This function is used to test output 
 */
function pre_print($var, $head = NULL)
{
    echo '<pre>';
    echo '<h2>' . $head . '</h2>';
    print_r($var);
    echo '</pre>';
    echo '<hr>';
}
Esempio n. 6
0
 /**
  * @author Gaurav Dhiman.
  * @method edit student	
  */
 public function edit($stud_id)
 {
     if (isset($_POST['submit']) && !empty($_POST)) {
         //
         $arrData = array();
         $arrData = copy_posted($arrData, array('std', 'stream', 'division', 'semester', 'admit_to', 'medium', 'fname', 'mname', 'lname', 'father_mname', 'father_qualification', 'father_occupation', 'father_pq', 'father_mobile', 'father_ofc_num', 'father_ofc_name', 'adrs_father_ofc', 'father_email', 'father_aadhar', 'father_ai', 'father_pan', 'mother_fname', 'mother_qualification', 'mother_occupation', 'mother_pq', 'mother_mobile', 'mother_ofc_num', 'mother_ofc_name', 'adrs_mother_ofc', 'mother_email', 'mother_aadhar', 'mother_ai', 'mother_pan', 'is_divorced', 'is_adopted', 'sibbling1', 'sibbling2', 'sibbling3', 'adrs_residence', 'adrs_native', 'city', 'pincode', 'district', 'birth_place', 'alt_phone', 'gender', 'religion', 'caste', 's_caste', 'weight', 'height', 'birth_date', 'admission_date', 'fee_scheme', 'start_std', 'blood_grp', 'status', 'mother_tongue', 'nationality', 'near_rly_stn', 'seat_num', 'child_num', 'passed_out', 'last_percentage', 'handicap', 'nss', 'leaving_date'));
         $arrData['modified'] = date('y-m-d H:i:s');
         $arrData['updated_by'] = "Gaurav Dhiman";
         $arrData['admit_to'] = date('Y-m-d H:i:s', strtotime($arrData['admit_to']));
         $arrData['birth_date'] = date('Y-m-d H:i:s', strtotime($arrData['birth_date']));
         $arrData['admission_date'] = date('Y-m-d H:i:s', strtotime($arrData['admission_date']));
         //pre_print($arrData);
         $response = $this->model_student->update_student($stud_id, $arrData);
         pre_print($response);
         if ($response > 0) {
             redirect('student/listing');
         } else {
             $arrData['student_details'] = $this->model_student->get_student($stud_id);
             //pre_print($arrData);
             superadmin_view('student/edit_student', $arrData);
         }
     } else {
         $arrData['student_details'] = $this->model_student->get_student($stud_id);
         //pre_print($arrData);
         superadmin_view('student/edit_student', $arrData);
     }
 }
Esempio n. 7
0
<?php

pre_print('herahfjahsdfkljhaskldfhlkasjdfhkajsdfhk');
 public function importMentorsWithIdsAndCodes($competition_id, $country_id, $csv)
 {
     $country = Country::model()->findByPk($country_id);
     if ($country == null) {
         echo 'Country does not exist!';
         die;
     }
     $competition = Competition::model()->findByPk($competition_id);
     if ($competition == null) {
         echo 'Competition does not exist!';
         die;
     }
     header('Content-Type: text/html; charset=utf-8');
     if ($country->country == 'Srbija') {
         // popravek imen kategorij, ki se parsajo
         $cols = array('Mentor ID' => 'mentor_id', 'kategorija' => 'category_name', 'koda' => 'access_code');
     } else {
         $cols = array('Mentor ID' => 'mentor_id', 'kategorija' => 'category_name', 'koda' => 'access_code');
     }
     $lines = explode("\n", trim($csv));
     $header_line = $lines[0];
     $header_cols = explode(';', trim($header_line));
     $keys = array_keys($cols);
     $cols_matrix = array();
     $index = 0;
     foreach ($header_cols as $h_cols) {
         $h_cols = trim($h_cols);
         if (in_array($h_cols, $keys)) {
             $cols_matrix[$index] = $cols[$h_cols];
         }
         $index++;
     }
     if (count($cols_matrix) != count($cols)) {
         echo 'One of required header columns is missing. Required columns: ', implode(', ', $keys), "<br />";
         die;
     }
     // pre_print($cols_matrix);
     $datas = array();
     for ($i = 1; $i < count($lines); ++$i) {
         $col = explode(';', trim($lines[$i]));
         $data = array();
         $index = 0;
         foreach ($col as $c) {
             $data[$cols_matrix[$index]] = trim($c);
             $index++;
         }
         $datas[] = $data;
     }
     // pre_print($datas);
     $categoryCache = array();
     $imported = 0;
     foreach ($datas as $data) {
         if (isset($data['mentor_id']) && $data['mentor_id'] != '' && mb_substr($data['mentor_id'], 0, 1, 'UTF-8') == 'M') {
             $mentor_id = trim(ltrim($data['mentor_id'], "M"));
             $category_name = $data['category_name'];
             if (isset($categoryCache[$category_name])) {
                 $competition_category_id = $categoryCache[$category_name];
             } else {
                 $competitionCategory = CompetitionCategory::model()->find('country_id=:country_id and name=:name', array(':country_id' => $country_id, ':name' => $category_name));
                 if ($competitionCategory == null) {
                     echo 'Competition Category ', $category_name, ' cannot be found in database.';
                     die;
                 } else {
                     $categoryCache[$category_name] = $competitionCategory->id;
                     $competition_category_id = $categoryCache[$category_name];
                 }
             }
             $access_code = $data['access_code'];
             $schoolMentor = SchoolMentor::model()->findByPk($mentor_id);
             if ($schoolMentor == null) {
                 echo 'School mentor with ID: ', $mentor_id, ' could not be found!';
                 die;
             }
             // check if school already on competition in this category
             $competitionCategorySchool = CompetitionCategorySchool::model()->find('competition_id=:cid and competition_category_id=:ccid and school_id=:sid', array(':cid' => $competition_id, ':ccid' => $competition_category_id, ':sid' => $schoolMentor->school_id));
             if ($competitionCategorySchool == null) {
                 $competitionCategorySchool = new CompetitionCategorySchool();
                 $competitionCategorySchool->competition_id = $competition_id;
                 $competitionCategorySchool->competition_category_id = $competition_category_id;
                 $competitionCategorySchool->school_id = $schoolMentor->school_id;
                 if (!$competitionCategorySchool->save()) {
                     echo 'Error saving competition category school!';
                     die;
                 }
             }
             // check if access code already in use
             $competitionCategorySchoolMentor = CompetitionCategorySchoolMentor::model()->find('access_code=:access_code', array(':access_code' => $access_code));
             if ($competitionCategorySchoolMentor != null) {
                 if ($competitionCategorySchoolMentor->user_id != $schoolMentor->user_id || $competitionCategorySchoolMentor->competition_category_school_id != $competitionCategorySchool->id) {
                     echo 'Cannot import access code: ', $access_code, ', because is already used by id: ', $competitionCategorySchoolMentor->id;
                     die;
                 }
             } else {
                 $competitionCategorySchoolMentor = new CompetitionCategorySchoolMentor();
                 $competitionCategorySchoolMentor->access_code = $access_code;
                 $competitionCategorySchoolMentor->competition_category_school_id = $competitionCategorySchool->id;
                 $competitionCategorySchoolMentor->user_id = $schoolMentor->user_id;
                 if (!$competitionCategorySchoolMentor->save()) {
                     echo 'Error saving CompetitionCategorySchoolMentor for access code: ', $access_code;
                     die;
                 } else {
                     $imported++;
                 }
             }
         } else {
             echo 'Error importing data: <br />';
             pre_print($data);
             die;
         }
     }
     echo '<br />Number of imported access codes: ', $imported;
 }
Esempio n. 9
0
/**
Функция выполняет вывод значения переменной и выполняет остановку выполнения скрипта
*/
function debugStop($var)
{
    pre_print($var);
    die;
}