public function actionEditmoreinfo($user_id)
 {
     $user_more_info = UserInfoAR::model()->findByPk($user_id);
     $this->assign('user_more', $user_more_info);
     $maritalStatus = MaritalStatus::model()->findAll();
     // 'MaritalStatus', 'marital_status_id'),
     $hometown = Hometown::model()->findAll();
     // 'Province', 'hometown_id'),
     $nation = Nation::model()->findAll();
     // 'Nation', 'nation_id'),
     $bodyType = BodyType::model()->findAll();
     // 'BodyType', 'body_type_id'),
     $education = Education::model()->findAll();
     // 'Education', 'education_id'),
     $school = School::model()->findAll();
     // 'School', 'school_id'),
     $province = Province::model()->findAll();
     // 'Province', 'province_id'),
     $job = Job::model()->findAll();
     // '$maritalSta,
     $this->assign('maritalStatus', $maritalStatus);
     $this->assign('hometown', $hometown);
     $this->assign('nation', $nation);
     $this->assign('bodyType', $bodyType);
     $this->assign('education', $education);
     $this->assign('school', $school);
     $this->assign('province', $province);
     $this->assign('job', $job);
 }
Beispiel #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return School the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = School::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #3
0
 /**
  * Returns array of all schools
  */
 public static function getAllSchools()
 {
     $schools = School::model()->findAll();
     $schoolNames = array();
     foreach ($schools as $school) {
         $schoolNames[] = $school->name;
     }
     return $schoolNames;
 }
Beispiel #4
0
 public function actionGetSchoolList()
 {
     ini_set("log_errors", 1);
     ini_set("error_log", "/tmp/php-error.log");
     $maxmarkers = 5000;
     $result = array();
     $result['SchoolList'] = array();
     if (empty($_POST)) {
         $result['IsError'] = true;
         $result['Message'] = '数据接收失败';
     } else {
         $result['IsError'] = false;
         //type
         $criteria = new CDbCriteria();
         if ($_POST['type'] == 's') {
             $criteria->addCondition('type =1');
         }
         if ($_POST['type'] == 'e') {
             $criteria->addCondition('type =0');
         }
         if (!empty($_POST['province'])) {
             $criteria->addCondition('province="' . $_POST['province'] . '"');
         }
         $chinese = preg_match("/\\p{Han}+/u", $_POST['xingzhi']);
         //XingZhi
         if (!empty($_POST['xingzhi']) && !$chinese) {
             $criteria->addCondition("xingzhi like '" . $_POST['xingzhi'] . "%'");
         }
         //Pingfen
         if (!empty($_POST['pingfen']) && intval($_POST['pingfen']) > 0) {
             $criteria->addCondition("pingfen >='" . $_POST['pingfen'] . "'");
         }
         //Rank
         //$criteria->order = "paiming ASC";
         $criteria->addCondition("paiming >=1");
         //End of Condition
         $count = School::model()->count($criteria);
         //Display school list if maxmarker is less
         $criteria->order = "paiming";
         $school = School::model()->findAll($criteria);
         foreach ($school as $val) {
             $paiming = !empty($val->paiming) ? $val->paiming : '无';
             $rating = !empty($val->pingfen) ? $val->pingfen : '无';
             $result["SchoolList"][] = array($paiming, $val->school, $val->grade, $val->address, $val->city, $val->tel, $val->id);
         }
     }
     echo json_encode($result);
 }
Beispiel #5
0
 public function importCompetitiors($competition_id, $competition_category_id, $content)
 {
     $lines = explode("\n", $content);
     $header = explode(';', $lines[0]);
     $competition_questions = CompetitionQuestionCategory::model()->with('competitionQuestion')->with('competitionQuestion.question')->findAll('competition_category_id=:competition_category_id and competitionQuestion.competition_id=:competition_id', array(':competition_category_id' => $competition_category_id, ':competition_id' => $competition_id));
     $questions_to_import = array();
     foreach ($competition_questions as $cq) {
         if ($cq == null) {
             $cq = new CompetitionQuestionCategory();
         }
         $questions_to_import[trim($cq->competitionQuestion->question->title)] = $cq->competition_question_id;
     }
     echo 'Question to import:<br />';
     pre_print($questions_to_import);
     // map fields
     $colQuestionMap = array();
     $found_c = array();
     for ($i = 0; $i < count($header); ++$i) {
         $col = explode('(', $header[$i]);
         $c = trim($col[0]);
         if (isset($questions_to_import[$c])) {
             $colQuestionMap[$i] = $questions_to_import[$c];
             $found_c[] = $c;
         }
     }
     if (count($colQuestionMap) != count($questions_to_import)) {
         echo 'Question to import and question in CSV does not match!';
         echo 'Question to import:<br />';
         pre_print($questions_to_import);
         echo 'Found questions: <br />';
         pre_print($found_c);
         echo 'CSV header line cols: <br />';
         pre_print($header);
         echo 'Question column mapping found:<br />';
         pre_print($colQuestionMap);
         die;
     } else {
         echo 'Question column exist, we can start importing.<br />';
     }
     // check for required columns
     $required_fields = array('Priimek' => -1, 'Ime' => -1, 'Mentor' => -1, 'Šola' => -1, 'Spol' => -1, 'Razred' => -1);
     $required_keys = array_keys($required_fields);
     // not required fields
     $required_fields['ID1'] = -1;
     $required_fields['ID2'] = -1;
     $required_keys2 = array_keys($required_fields);
     for ($i = 0; $i < count($header); ++$i) {
         if (in_array(trim($header[$i]), $required_keys2)) {
             $required_fields[trim($header[$i])] = $i;
         }
     }
     $missing_fields = array();
     for ($i = 0; $i < count($required_keys); ++$i) {
         if ($required_fields[$required_keys[$i]] == -1) {
             $missing_fields[] = $required_keys[$i];
         }
     }
     if (count($missing_fields) > 0) {
         echo 'Some required fields are missing:<br />';
         pre_print($missing_fields);
         die;
     }
     $competition = Competition::model()->findByPk($competition_id);
     if ($competition == null) {
         echo 'Provided Competition does not exist!';
         die;
     }
     $competitionCategory = CompetitionCategory::model()->findByPk($competition_category_id);
     if ($competitionCategory == null) {
         echo 'Provided Competition Category does not exist!';
         die;
     }
     for ($i = 1; $i < count($lines); ++$i) {
         if (trim($lines[$i]) == '') {
             continue;
         }
         $cols = explode(';', $lines[$i]);
         $cu = new CompetitionUser();
         $cu->competition_category_id = $competition_category_id;
         $cu->competition_id = $competition_id;
         $cu->first_name = $cols[$required_fields['Ime']];
         $cu->last_name = $cols[$required_fields['Priimek']];
         $cu->gender = $cols[$required_fields['Spol']] == 'M' ? 0 : 1;
         $cu->class = $cols[$required_fields['Razred']];
         $sc = School::model()->find('name=:name', array(':name' => trim($cols[$required_fields['Šola']])));
         if ($sc == null) {
             echo 'Provided school not found in database! School name: ', $cols[$required_fields['Šola']], '<br />';
             die;
         }
         $cu->school_id = $sc->id;
         $scm = SchoolMentor::model()->with('user.profile')->find('school_id=:school_id and CONCAT_WS(\' \', `profile`.`last_name`, `profile`.`first_name`) LIKE :mentor', array(':school_id' => $sc->id, ':mentor' => trim($cols[$required_fields['Mentor']])));
         if ($scm == null) {
             echo 'Provided school mentor not found in database! School name: ', $cols[$required_fields['Šola']], ', School mentor: ', $cols[$required_fields['Mentor']], '<br />';
             die;
         }
         // ali je šola prijavljena na tekmovanje za to kategorijo
         $ccs = CompetitionCategorySchool::model()->find('competition_id=:competition_id and competition_category_id=:competition_category_id and school_id=:school_id', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id, ':school_id' => $sc->id));
         if ($ccs == null) {
             echo 'Provided school is not competing in this category! School name: ', $cols[$required_fields['Šola']], ', Competition: ', $competition->name, ', Competition category: ', $competitionCategory->name, '<br />';
             die;
         }
         // ali je mentor prijavljen na tej šoli za to tekmovalno kategorijo
         $ccsm = CompetitionCategorySchoolMentor::model()->find('competition_category_school_id=:competition_category_school_id and user_id=:user_id', array(':competition_category_school_id' => $ccs->id, ':user_id' => $scm->user_id));
         if ($ccsm == null) {
             echo 'Provided mentor is not competing on this school on this competition in this category! School mentor: ', $cols[$required_fields['Mentor']], ', School name: ', $cols[$required_fields['Šola']], ', Competition: ', $competition->name, ', Competition category: ', $competitionCategory->name, '<br />';
             die;
         }
         $cu->competition_category_school_mentor_id = $ccsm->id;
         $cu->start_time = null;
         $cu->finish_time = null;
         $cu->finished = 2;
         if (isset($cols[$required_fields['ID1']])) {
             $cut = CompetitionUser::model()->findByPk($cols[$required_fields['ID1']]);
             if ($cut != null) {
                 if ($cut == null) {
                     $cut = new CompetitionUser();
                 }
                 $cu->start_time = $cut->start_time;
                 $cu->finish_time = $cut->finish_time;
                 $cut->disqualified_reason = 'Prenos v pravilno kategorijo tekmovanja';
                 $cut->disqualified_request = 1;
                 $cut->disqualified = 1;
                 $cut->save();
             }
         }
         if (isset($cols[$required_fields['ID2']])) {
             $cut = CompetitionUser::model()->findByPk($cols[$required_fields['ID2']]);
             if ($cut != null) {
                 if ($cut == null) {
                     $cut = new CompetitionUser();
                 }
                 if ($cu->start_time == null) {
                     $cu->start_time = $cut->start_time;
                     $cu->finish_time = $cut->finish_time;
                 } else {
                     $time_diff1 = strtotime($cu->finish_time) - strtotime($cu->start_time);
                     $time_diff2 = strtotime($cut->finish_time) - strtotime($cut->start_time);
                     if ($time_diff2 > $time_diff1) {
                         $cu->start_time = $cut->start_time;
                         $cu->finish_time = $cut->finish_time;
                     }
                 }
                 $cut->disqualified_reason = 'Prenos v pravilno kategorijo tekmovanja';
                 $cut->disqualified_request = 1;
                 $cut->disqualified = 1;
                 $cut->save();
             }
         }
         // ali tekmovalec s temi podatki že obstaja
         $cuc = CompetitionUser::model()->find('competition_id=:competition_id and competition_category_id=:competition_category_id and competition_category_school_mentor_id=:competition_category_school_mentor_id and school_id=:school_id and first_name=:first_name and last_name=:last_name and gender=:gender and class=:class', array(':competition_id' => $competition_id, ':competition_category_id' => $competition_category_id, ':competition_category_school_mentor_id' => $cu->competition_category_school_mentor_id, ':school_id' => $cu->school_id, ':last_name' => $cu->last_name, ':first_name' => $cu->first_name, ':gender' => $cu->gender, ':class' => $cu->class));
         if ($cuc != null) {
             echo 'Competition User already exists, skipping...';
             continue;
         }
         $cu->save();
         // import answers
         $question_keys = array_keys($colQuestionMap);
         for ($k = 0; $k < count($question_keys); ++$k) {
             $cuq = new CompetitionUserQuestion();
             $cuq->competition_user_id = $cu->id;
             $cuq->competition_question_id = $colQuestionMap[$question_keys[$k]];
             $cuq->ordering = $k + 1;
             $cuq->random_seed = number_format(mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax(), 9, '.', '');
             $cuq->last_change = $cu->finish_time;
             $custom_answer_ex = explode('|', $cols[$question_keys[$k]]);
             $custom_answer = trim($custom_answer_ex[0]);
             $cuq->custom_answer = $custom_answer;
             $cuq->save();
         }
         echo 'Successfully imported user with ID: ', $cu->id, '<br />';
     }
 }
            ?>
"><?php 
            echo $js->username;
            ?>
</a></td>
	<td><?php 
            echo $js->first_name . " " . $js->last_name;
            ?>
</td>


	<td><?php 
            $educ = Education::model()->findByAttributes(array('FK_user_id' => $js->id));
            $school = "";
            if ($educ) {
                $school = School::model()->findByAttributes(array('id' => $educ->FK_school_id))->name;
            }
            echo $school;
            ?>
</td>	
       
        <td class="info1">
	<?php 
            $temp = StudentSkillMap::model()->findAllByAttributes(array('userid' => $js->id));
            foreach ($temp as $one) {
                echo Skillset::model()->findByAttributes(array('id' => $one->skillid))->name . " - ";
            }
            ?>
</td>
</tr>
<?php 
Beispiel #7
0
 public function import($content)
 {
     $header_cols = array('name' => 0, 'school_category_id' => 1, 'level_of_education' => 2, 'post' => 3, 'postal_code' => 4, 'municipality_id' => 5, 'region_id' => 6, 'country_id' => 7);
     header('Content-Type: text/html; charset=utf-8');
     $lines = explode("\n", $content);
     for ($i = 1; $i < count($lines); ++$i) {
         if (trim($lines[$i]) == '') {
             continue;
         }
         $cols = explode(";", $lines[$i]);
         // država
         $country_id = 0;
         $country = Country::model()->find('country=:country', array(':country' => trim($cols[$header_cols['country_id']])));
         if ($country == null) {
             echo Yii::t('app', 'Country does not exist! Country: ') . trim($cols[$header_cols['country_id']]);
             die;
         }
         $country_id = $country->id;
         // regija
         $region = Region::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['region_id']]), ':country_id' => $country_id));
         if ($region == null) {
             $region = new Region();
             $region->country_id = $country_id;
             $region->name = trim($cols[$header_cols['region_id']]);
             $region->save();
         }
         $region_id = $region->id;
         // občina
         $municipality = Municipality::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['municipality_id']]), ':country_id' => $country_id));
         if ($municipality == null) {
             $municipality = new Municipality();
             $municipality->country_id = $country_id;
             $municipality->name = trim($cols[$header_cols['municipality_id']]);
             $municipality->save();
         }
         $municipality_id = $municipality->id;
         $school_name = trim($cols[$header_cols['name']]);
         if ($school_name[0] == '"') {
             $school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8');
         }
         $school_name = str_replace('""', '"', $school_name);
         $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => $school_name, ':country_id' => $country_id));
         if ($school == null) {
             $school = new School();
             $school->name = $school_name;
             $school->country_id = $country_id;
             $school->municipality_id = $municipality_id;
             $school->region_id = $region_id;
             $school->post = trim($cols[$header_cols['post']]);
             $school->postal_code = trim($cols[$header_cols['postal_code']]);
             $school->school_category_id = (int) trim($cols[$header_cols['school_category_id']]);
             $school->level_of_education = (int) trim($cols[$header_cols['level_of_education']]);
             $school->save();
             echo 'Imported: ', $school_name, "<br />\n";
             if (count($school->errors) > 0) {
                 print_r($school->errors);
                 die;
             }
         } else {
             echo 'Already imported: ', $school_name, "<br />\n";
         }
     }
 }
Beispiel #8
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";
 }
Beispiel #9
0
 /**
  * 重置某个园所有未激活用户的密码为手机后四位
  * GET /school/{schoolId}/user/reset
  */
 public function actionRestresetpassword()
 {
     // check school
     if (isset($_GET['schoolId'])) {
         $school = School::model()->findByPk($_GET['schoolId']);
         if ($school == null || $school->archived == 0) {
             return $this->sendResponse(404, 'school is not found');
         }
     }
     $criteria = new CDbCriteria();
     $criteria->compare('archived', 1);
     $criteria->order = 'created_time desc';
     if (isset($_GET['schoolId'])) {
         $criteria->compare('school_id', $_GET['schoolId']);
     }
     $criteria->compare('open_id', null);
     $users = User::model()->findAll($criteria);
     $count = 0;
     foreach ($users as $user) {
         if ($user->open_id != null) {
             continue;
         }
         $password = substr($user->mobile, -4);
         if ($user->password != User::model()->encrypt($password)) {
             $count++;
             $user->username = trim($user->username);
             $user->mobile = trim($user->mobile);
             $user->password = $password;
             if (!$user->save()) {
                 return $this->sendResponse(500, 'failed to reset password ' . $user->id);
             } else {
                 /*
                 					Notification::addNotification(
                                         $user->id,
                                         "您的优购优惠券管理后台激活密码已重置为您手机号码的后四位,请使用新密码激活您在优购优惠券管理后台的账号。如需帮助,请发邮件至support@yougouwx.com。对您造成的不便深表歉意。",
                                         1
                                     );*/
             }
         }
     }
     echo CJSON::encode($count);
 }
Beispiel #10
0
 public function GetSchoolName($id)
 {
     $school = School::model()->findByPk($id);
     if ($school != null) {
         return $school->name;
     } else {
         return '';
     }
 }
 public function importMentorsWithCodes($competition_id, $country_id, $csv)
 {
     $country = Country::model()->findByPk($country_id);
     if ($country == null) {
         echo 'Country does not exist!';
         die;
     }
     header('Content-Type: text/html; charset=utf-8');
     if ($country->country == 'Srbija') {
         // popravek imen kategorij, ki se parsajo
         $cols = array('E-poštni naslov' => 'email', 'Telefon' => 'phone', 'Ime' => 'name', 'Priimek' => 'surname', 'Država' => 'country', 'Ime škole' => 'school', 'Koordinator' => 'coordinator_on_school', 'Uporabniško ime' => 'username', 'Geslo' => 'password', 'Dabarčić' => 'category_name_Dabarčić', 'Mladi dabar' => 'category_name_Mladi dabar', 'Dabar' => 'category_name_Dabar', 'Stariji dabar' => 'category_name_Stariji dabar');
     } else {
         $cols = array('E-poštni naslov' => 'email', 'Telefonska številka' => 'phone', 'Ime' => 'name', 'Priimek' => 'surname', 'Država' => 'country', 'Šola' => 'school', 'Koordinator' => 'coordinator_on_school', 'Uporabniško ime' => 'username', 'Geslo' => 'password', 'Bobrček' => 'category_name_Bobrček', 'Mladi bober' => 'category_name_Mladi bober', 'Bober' => 'category_name_Bober', 'Stari bober' => 'category_name_Stari bober');
     }
     $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];
             echo "Found:", $h_cols, "<br />";
         } else {
             echo "Not found:", $h_cols, "<br />";
         }
         $index++;
     }
     if (count($cols_matrix) != count($cols)) {
         echo 'One of required header columns is missing. Required columns: ', implode(', ', $keys), "<br />";
         echo 'Got cols: ', implode(', ', $header_cols), "<br />";
         echo 'Cols matrix: ', implode(', ', $cols_matrix), "<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);
             if (count(explode('category_name_', $cols_matrix[$index])) > 1 && in_array($data[$cols_matrix[$index]], array('srednja šola', 'osnovna šola', 'srednja šola)', 'osnovna šola)', 'Samo za srednje', 'Samo za osnovne'))) {
                 $data[$cols_matrix[$index]] = '';
             } else {
                 if ($cols_matrix[$index] == 'coordinator_on_school') {
                     if ($data[$cols_matrix[$index]] != '') {
                         $data['coordinator'] = true;
                     } else {
                         $data['coordinator'] = false;
                     }
                 } else {
                     if ($cols_matrix[$index] == 'school') {
                         $school_name = trim($data['school']);
                         if ($school_name[0] == '"') {
                             $school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8');
                         }
                         $school_name = str_replace('""', '"', $school_name);
                         $school_check = School::model()->find('name=:name', array(':name' => $school_name));
                         if ($school_check != null) {
                             $data['school_id'] = $school_check->id;
                         } else {
                             echo 'Šola ne obstaja! Šola: ', $data['school'], '<br />';
                         }
                     } else {
                         if ($cols_matrix[$index] == 'username') {
                             $data[$cols_matrix[$index]] = str_replace('.', '', $data[$cols_matrix[$index]]);
                             $data[$cols_matrix[$index]] = str_replace('á', 'a', $data[$cols_matrix[$index]]);
                         }
                     }
                 }
             }
             $index++;
         }
         if ($data['email'] == '' && $data['name'] == '') {
             continue;
         }
         if (count($data) != count($keys) + 2) {
             echo 'Record is invalid, it does not have all required fields. Skipping...<br />';
             echo count($data), ' vs. ', count($keys) + 2, '...<br />';
             pre_print($keys);
             pre_print($data);
             continue;
         }
         $datas[] = $data;
     }
     // pre_print($datas);
     // category matching to ids in database
     $category_matching = array();
     foreach ($cols_matrix as $mc) {
         $ex = explode('category_name_', $mc);
         if (count($ex) > 1) {
             $category_name = $ex[1];
             $competitionCategory = CompetitionCategory::model()->find('name=:name', array(':name' => $category_name));
             if ($competitionCategory == null) {
                 echo 'Competition category ', $category_name, ' not found in database!<br />';
                 die;
             } else {
                 $category_matching[$category_name] = $competitionCategory->id;
             }
         }
     }
     foreach ($datas as $data) {
         // check if user with this email already exists
         $check_email = User::model()->find('email=:email', array(':email' => $data['email']));
         $user_id = 0;
         if ($check_email != null) {
             echo 'User with email ', $data['email'], ' is already in system. Skipping importing user...<br />';
             $user_id = $check_email->id;
         }
         // check username
         $check_username = User::model()->find('username=:username', array(':username' => $data['username']));
         if ($check_username != null) {
             echo 'User with username ', $data['username'], ' is already in system. Skipping importing user...<br />';
             $user_id = $check_username->id;
         }
         // check if school exist
         if (!isset($data['school_id'])) {
             echo 'School ID not known! <br />';
             continue;
         }
         if ($user_id == 0) {
             $user = new User();
             $user->username = $data['username'];
             $user->password = $this->encrypting($data['password']);
             $user->email = $data['email'];
             $user->activkey = $this->encrypting(microtime() . $data['password']);
             $user->createtime = time();
             $user->superuser = 0;
             $user->status = 1;
             $user->create_at = date('Y-m-d H:i:s');
             if ($user->save()) {
                 $user_id = $user->id;
                 $profile = new Profile();
                 $profile->user_id = $user->id;
                 $profile->first_name = $data['name'];
                 $profile->last_name = $data['surname'];
                 $country = Country::model()->find('country=:country', array(':country' => $data['country']));
                 if ($country != null) {
                     $country_id = $country->id;
                 } else {
                     $country_id = 1;
                 }
                 $profile->country_id = $country_id;
                 $profile->language_id = 1;
                 $profile->user_role = 5;
                 $profile->timezone = 'Europe/Ljubljana';
                 $profile->phone_number = $data['phone'];
                 if (!$profile->save()) {
                     echo 'Error saving user profile!<br />';
                     pre_print($data);
                     die;
                 }
             } else {
                 echo 'Error saving user!<br />';
                 pre_print($user->errors);
                 pre_print($data);
                 die;
             }
         }
         if ($user_id != 0) {
             // add user as mentor to school
             $school_mentor_id = 0;
             $schoolMentor = SchoolMentor::model()->find('user_id=:user_id and school_id=:school_id', array(':user_id' => $user_id, ':school_id' => $data['school_id']));
             if ($schoolMentor == null) {
                 $schoolMentor = new SchoolMentor();
                 $schoolMentor->user_id = $user_id;
                 $schoolMentor->school_id = $data['school_id'];
                 if (isset($data['coordinator']) && $data['coordinator']) {
                     $schoolMentor->coordinator = 1;
                 }
                 $schoolMentor->active = 1;
                 $schoolMentor->activatedBy = 1;
                 $schoolMentor->activated_timestamp = date('Y-m-d H:i:s');
                 if ($schoolMentor->save()) {
                     $school_mentor_id = $schoolMentor->id;
                 } else {
                     echo 'Error adding user id ', $user_id, ' to be school mentor at school id ', $data['school_id'], '<br />';
                     die;
                 }
             } else {
                 $school_mentor_id = $schoolMentor->id;
             }
             // preveri ali je šola že prijavljena na tekmovanje s to kategorijo
             $competitionCategoryId = 0;
             foreach ($data as $key => $value) {
                 if (trim($value) == '') {
                     continue;
                 }
                 $ex = explode('category_name_', $key);
                 if (count($ex) > 1) {
                     $competitionCategoryId = $category_matching[$ex[1]];
                     $competitionCategorySchool = CompetitionCategorySchool::model()->find('competition_id=:cid and competition_category_id=:ccid and school_id=:school_id', array(':cid' => $competition_id, ':school_id' => $data['school_id'], ':ccid' => $competitionCategoryId));
                     if ($competitionCategorySchool == null) {
                         $competitionCategorySchool = new CompetitionCategorySchool();
                         $competitionCategorySchool->competition_id = $competition_id;
                         $competitionCategorySchool->competition_category_id = $competitionCategoryId;
                         $competitionCategorySchool->school_id = $data['school_id'];
                         if (!$competitionCategorySchool->save()) {
                             echo 'Error adding competiton category to school, school id: ', $data['school_id'], ', competiton_category_id: ', $competitionCategoryId, '<br />';
                             die;
                         }
                     }
                     // shranimo mentorja in njegovo tekmovalno kodo
                     $competitionCategorySchoolMentorCheck = CompetitionCategorySchoolMentor::model()->find('access_code=:access_code', array(':access_code' => $value));
                     if ($competitionCategorySchoolMentorCheck == null) {
                         $competitionCategorySchoolMentor = new CompetitionCategorySchoolMentor();
                         $competitionCategorySchoolMentor->user_id = $user_id;
                         $competitionCategorySchoolMentor->competition_category_school_id = $competitionCategorySchool->id;
                         $competitionCategorySchoolMentor->access_code = $value;
                         if (!$competitionCategorySchoolMentor->save()) {
                             echo 'Error adding access code for user!<br />';
                             pre_print($data);
                             die;
                         }
                     } else {
                         if ($competitionCategorySchoolMentorCheck->user_id == $user_id && $competitionCategorySchoolMentorCheck->competition_category_school_id == $competitionCategorySchool->id) {
                             // ok
                         } else {
                             echo 'Error adding access code! Access code already in use.<br />';
                             pre_print($data);
                             die;
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #12
0
	protected function beforeDelete()
	{
		//ko co id teacher nhu o afterSave nen phai get lay
		$getID= PostsComments::model()->findAll(
			array("condition"=>"commentId=$this->id"));
		$li = CHtml::listData($getID,'postId','commentId');
		$key=key($li);
		
		$model2 = School::model()->findAll(
					 array("condition"=>"id =  $key",'select'=>'rate1,rate2,rate3,rate4,rate5,count',));
		if ($model2<>NULL)
		{
			self::minusPointTeacher($model2,$key);
		}


		$models = Teacher::model()->findAll(
					 array("condition"=>"id =  $key",'select'=>'rate1,rate2,rate3,rate4,rate5,count',));
		if ($models<>NULL)
		{
			self::minusPointSchool($models,$key);
		}

		
		return parent::beforeDelete();
	}
Beispiel #13
0
 public function actionRegisterLinkedIn()
 {
     // if user canceled, redirect to home page
     if (isset($_GET['oauth_problem'])) {
         $problem = $_GET['oauth_problem'];
         if ($problem == 'user_refused') {
             $this->redirect('/JobFair/index.php');
         }
     }
     if (!isset($_SESSION)) {
         session_start();
     }
     //edit by Manuel making the link dynamic, using Yii
     $config['base_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/auth1.php';
     $config['callback_url'] = 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/user/RegisterLinkedIn';
     $config['linkedin_access'] = '2rtmn93gu2m4';
     $config['linkedin_secret'] = 'JV0fYG9ls3rclP8v';
     include_once Yii::app()->basePath . "/views/user/linkedin.php";
     # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
     $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']);
     //$linkedin->debug = true;
     if (isset($_REQUEST['oauth_verifier'])) {
         $_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
         $linkedin->request_token = unserialize($_SESSION['requestToken']);
         $linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
         $linkedin->getAccessToken($_REQUEST['oauth_verifier']);
         $_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
         header("Location: " . $config['callback_url']);
         exit;
     } else {
         $linkedin->request_token = unserialize($_SESSION['requestToken']);
         $linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
         $linkedin->access_token = unserialize($_SESSION['oauth_access_token']);
     }
     # You now have a $linkedin->access_token and can make calls on behalf of the current member
     $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,industry,email-address,languages,phone-numbers,skills,educations,location:(name),positions,picture-urls::(original))");
     $data = simplexml_load_string($xml_response);
     // get user by linkedinid
     $model = new User();
     $user = User::model()->findByAttributes(array('linkedinid' => $data->id));
     // check if user exits in database, if so login
     if ($user != null) {
         if ($user->disable != 1) {
             $identity = new UserIdentity($user->username, '');
             if ($identity->authenticateOutside()) {
                 Yii::app()->user->login($identity);
             }
             $this->redirect("/JobFair/index.php/home/studenthome");
             return;
         } else {
             $this->redirect("/JobFair/index.php/site/page?view=disableUser");
             return;
         }
         // register
     } else {
         // 			print "<pre>"; print_r('user is null');print "</pre>";
         // check that there is no duplicate user if so link to that account
         $duplicateUser = User::model()->findByAttributes(array('email' => $data->{'email-address'}));
         if ($duplicateUser != null) {
             // get username and link the accounts
             $username = $duplicateUser->username;
             $user = User::model()->find("username=:username", array(':username' => $username));
             $user->linkedinid = $data->{'id'};
             $user->save(false);
             $user_id = $user->id;
             // ------------------BASIC INFO---------------
             $basic_info = null;
             $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $user_id));
             if ($basic_info == null) {
                 $basic_info = new BasicInfo();
             }
             $basic_info->userid = $user_id;
             $basic_info->save(false);
             // ------------------BASIC INFO -----------------
             // -----------------EDUCATION ----------------------
             // get number of educations to add
             $educ_count = $data->educations['total'];
             // delete current educations
             $delete_educs = Education::model()->findAllByAttributes(array('FK_user_id' => $user_id));
             foreach ($delete_educs as $de) {
                 $de->delete();
             }
             // add educations
             for ($i = 0; $i < $educ_count; $i++) {
                 // first check if current education is in school table. if not, add it
                 $current_school_name = $data->educations->education[$i]->{'school-name'};
                 $school_exists = School::model()->findByAttributes(array('name' => $current_school_name));
                 if ($school_exists == null) {
                     $new_school = new School();
                     $new_school->name = $current_school_name;
                     $new_school->save();
                     $school_id = School::model()->findByAttributes(array('name' => $current_school_name))->id;
                 } else {
                     $school_id = $school_exists->id;
                 }
                 // now ready to add new education
                 $new_educ = new Education();
                 $new_educ->degree = $data->educations->education[$i]->degree;
                 $new_educ->major = $data->educations->education[$i]->{'field-of-study'};
                 // 	   	$model->admission_date=date('Y-m-d',strtotime($model->admission_date));
                 $new_educ->graduation_date = date('Y-m-d', strtotime($data->educations->education[$i]->{'end-date'}->year));
                 // 	   	print "<pre>"; print_r($new_educ->graduation_date);print "</pre>";return;
                 $new_educ->FK_school_id = $school_id;
                 $new_educ->FK_user_id = $user_id;
                 $new_educ->additional_info = $data->educations->education[$i]->notes;
                 $new_educ->save(false);
             }
             // -----------------EDUCATION ----------------------
             // -----------------EXPERIENCE -------------------
             // get number of educations to add
             $pos_count = $data->positions['total'];
             // delete current positions
             $delete_pos = Experience::model()->findAllByAttributes(array('FK_userid' => $user_id));
             foreach ($delete_pos as $de) {
                 $de->delete();
             }
             for ($i = 0; $i < $pos_count; $i++) {
                 $new_pos = new Experience();
                 $new_pos->FK_userid = $user_id;
                 $new_pos->company_name = $data->positions->position[$i]->company->name;
                 $new_pos->job_title = $data->positions->position[$i]->title;
                 $new_pos->job_description = $data->positions->position[$i]->summary;
                 $temp_start_date = $data->positions->position[$i]->{'start-date'}->month . '/01/' . $data->positions->position[$i]->{'start-date'}->year;
                 $new_pos->startdate = date('Y-m-d', strtotime($temp_start_date));
                 if ($data->positions->position[$i]->{'is-current'} == 'true') {
                     $new_pos->enddate = '';
                 } else {
                     $temp_end_date = $data->positions->position[$i]->{'end-date'}->month . '/01/' . $data->positions->position[$i]->{'end-date'}->year;
                     $new_pos->enddate = date('Y-m-d', strtotime($temp_end_date));
                 }
                 $new_pos->city = '';
                 $new_pos->state = '';
                 $new_pos->save(false);
             }
             // -----------------EXPERIENCE -------------------
             // ----------------------SKILLS----------------------
             // get number of educations to add
             $linkedin_skill_count = $data->skills['total'];
             for ($i = 0; $i < $linkedin_skill_count; $i++) {
                 // check if skill exists in skill set table, if not, add it to skill set table
                 if (Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name)) == null) {
                     $new_skill = new Skillset();
                     $new_skill->name = $data->skills->skill[$i]->skill->name;
                     $new_skill->save(false);
                     //echo 'New Skill ' . $new_skill->attributes;
                 }
                 // check if student has that skill, if not add it to student-skill-map table
                 if (StudentSkillMap::model()->findByAttributes(array('userid' => $user_id, 'skillid' => Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id)) == null) {
                     $new_sdnt_skill = new StudentSkillMap();
                     $new_sdnt_skill->userid = $user_id;
                     $new_sdnt_skill->skillid = Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id;
                     $new_sdnt_skill->ordering = $i + 1;
                     $new_sdnt_skill->save(false);
                     echo 'New Skill for student' . $new_sdnt_skill->attributes;
                 }
             }
             // ----------------------SKILLS----------------------
             if ($duplicateUser->disable != 1) {
                 $identity = new UserIdentity($duplicateUser->username, '');
                 if ($identity->authenticateOutside()) {
                     Yii::app()->user->login($identity);
                 }
                 $mesg = "LinkedIn";
                 //get variables
                 $mesg = "LinkedIn";
                 $phone = $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'};
                 if ($phone != null) {
                     $phone = strip_tags($data->{'phone-numbers'}->{'phone-number'}->{'phone-number'}->asXML());
                 }
                 $city = $data->location->name;
                 if ($city != null) {
                     $city = strip_tags($data->location->name->asXML());
                 }
                 $state = '';
                 $about_me = $data->headline;
                 if ($about_me != null) {
                     $about_me = strip_tags($data->headline->asXML());
                 }
                 $picture = $data->{'picture-urls'}->{'picture-url'}[0];
                 if ($picture != null) {
                     $picture = strip_tags($data->{'picture-urls'}->{'picture-url'}[0]->asXML());
                 }
                 $this->actionLinkTo($data->{'email-address'}, $data->{'first-name'}, $data->{'last-name'}, $picture, $mesg, $phone, $city, $state, $about_me);
                 return;
             } else {
                 $this->redirect("/JobFair/index.php/site/page?view=disableUser");
                 return;
             }
         }
         // Populate user attributes
         $model->FK_usertype = 1;
         $model->registration_date = new CDbExpression('NOW()');
         $model->activation_string = 'linkedin';
         $model->username = $data->{'email-address'}[0];
         $model->first_name = $data->{'first-name'};
         $model->last_name = $data->{'last-name'};
         $model->email = $data->{'email-address'};
         $model->image_url = $data->{'picture-urls'}->{'picture-url'}[0];
         $model->linkedinid = $data->id;
         //Hash the password before storing it into the database
         $hasher = new PasswordHash(8, false);
         $model->password = $hasher->HashPassword('tester');
         $model->activated = 1;
         $model->has_viewed_profile = 1;
         $model->save(false);
         // 		// ------------------BASIC INFO---------------
         $basic_info = null;
         $basic_info = BasicInfo::model()->findByAttributes(array('userid' => $model->id));
         if ($basic_info == null) {
             $basic_info = new BasicInfo();
         }
         $basic_info->userid = $model->id;
         $basic_info->phone = $data->{'phone-numbers'}->{'phone-number'}->{'phone-number'};
         $basic_info->city = $data->location->name;
         $basic_info->state = '';
         $basic_info->about_me = $data->headline;
         $basic_info->save(false);
         // ------------------BASIC INFO -----------------
         // -----------------EDUCATION ----------------------
         // get number of educations to add
         $educ_count = $data->educations['total'];
         // delete current educations
         $delete_educs = Education::model()->findAllByAttributes(array('FK_user_id' => $model->id));
         foreach ($delete_educs as $de) {
             $de->delete();
         }
         // add educations
         for ($i = 0; $i < $educ_count; $i++) {
             // first check if current education is in school table. if not, add it
             $current_school_name = $data->educations->education[$i]->{'school-name'};
             $school_exists = School::model()->findByAttributes(array('name' => $current_school_name));
             if ($school_exists == null) {
                 $new_school = new School();
                 $new_school->name = $current_school_name;
                 $new_school->save();
                 $school_id = School::model()->findByAttributes(array('name' => $current_school_name))->id;
             } else {
                 $school_id = $school_exists->id;
             }
             // now ready to add new education
             $new_educ = new Education();
             $new_educ->degree = $data->educations->education[$i]->degree;
             $new_educ->major = $data->educations->education[$i]->{'field-of-study'};
             // 	   	$model->admission_date=date('Y-m-d',strtotime($model->admission_date));
             $new_educ->graduation_date = date('Y-m-d', strtotime($data->educations->education[$i]->{'end-date'}->year));
             // 	   	print "<pre>"; print_r($new_educ->graduation_date);print "</pre>";return;
             $new_educ->FK_school_id = $school_id;
             $new_educ->FK_user_id = $model->id;
             $new_educ->additional_info = $data->educations->education[$i]->notes;
             $new_educ->save(false);
         }
         // -----------------EDUCATION ----------------------
         // -----------------EXPERIENCE -------------------
         // get number of educations to add
         $pos_count = $data->positions['total'];
         // delete current positions
         $delete_pos = Experience::model()->findAllByAttributes(array('FK_userid' => $model->id));
         foreach ($delete_pos as $de) {
             $de->delete();
         }
         for ($i = 0; $i < $pos_count; $i++) {
             $new_pos = new Experience();
             $new_pos->FK_userid = $model->id;
             $new_pos->company_name = $data->positions->position[$i]->company->name;
             $new_pos->job_title = $data->positions->position[$i]->title;
             $new_pos->job_description = $data->positions->position[$i]->summary;
             $temp_start_date = $data->positions->position[$i]->{'start-date'}->month . '/01/' . $data->positions->position[$i]->{'start-date'}->year;
             $new_pos->startdate = date('Y-m-d', strtotime($temp_start_date));
             if ($data->positions->position[$i]->{'is-current'} == 'true') {
                 $new_pos->enddate = '';
             } else {
                 $temp_end_date = $data->positions->position[$i]->{'end-date'}->month . '/01/' . $data->positions->position[$i]->{'end-date'}->year;
                 $new_pos->enddate = date('Y-m-d', strtotime($temp_end_date));
             }
             $new_pos->city = '';
             $new_pos->state = '';
             $new_pos->save(false);
         }
         // -----------------EXPERIENCE -------------------
         // ----------------------SKILLS----------------------
         // get number of educations to add
         $linkedin_skill_count = $data->skills['total'];
         for ($i = 0; $i < $linkedin_skill_count; $i++) {
             // check if skill exists in skill set table, if not, add it to skill set table
             if (Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name)) == null) {
                 $new_skill = new Skillset();
                 $new_skill->name = $data->skills->skill[$i]->skill->name;
                 $new_skill->save(false);
                 //echo 'New Skill ' . $new_skill->attributes;
             }
             // check if student has that skill, if not add it to student-skill-map table
             if (StudentSkillMap::model()->findByAttributes(array('userid' => $model->id, 'skillid' => Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id)) == null) {
                 $new_sdnt_skill = new StudentSkillMap();
                 $new_sdnt_skill->userid = $model->id;
                 $new_sdnt_skill->skillid = Skillset::model()->findByAttributes(array('name' => $data->skills->skill[$i]->skill->name))->id;
                 $new_sdnt_skill->ordering = $i + 1;
                 $new_sdnt_skill->save(false);
             }
         }
         // ----------------------SKILLS----------------------
         // LOGIN
         $user = User::model()->find("username=:username", array(':username' => $model->username));
         $identity = new UserIdentity($user->username, 'tester');
         if ($identity->authenticate()) {
             Yii::app()->user->login($identity);
         }
         $this->redirect("/JobFair/index.php/user/ChangeFirstPassword");
     }
 }
Beispiel #14
0
 public function actionEmployersearch()
 {
     $srch_keyword = $_POST['skillkeyword'];
     // Get skill keyword to search
     $pieces = trim($srch_keyword);
     $pieces = explode(" ", $pieces);
     // split words to search
     $count = sizeof($pieces);
     // get number of word to search
     $query = '';
     for ($i = 0; $i < $count; $i++) {
         if ($i == $count - 1) {
             $query = $query . 'name like \'%' . $pieces[$i] . '%\'';
         } else {
             $query = $query . 'name like \'%' . $pieces[$i] . '%\' OR ';
         }
     }
     $criteria = new CDbCriteria();
     $criteria->condition = $query;
     $results = array();
     if ($srch_keyword != null) {
         $skillsArray = Skillset::model()->findAll($criteria);
         foreach ($skillsArray as $sk) {
             $student_ids = StudentSkillMap::model()->findAllByAttributes(array('skillid' => $sk->id));
             // search student skill map for students with that skill
             foreach ($student_ids as $tmp) {
                 $duplicate = 0;
                 if (sizeof($results) > 0) {
                     foreach ($results as $t) {
                         if ($t->id == $tmp->userid) {
                             $duplicate = 1;
                         }
                     }
                 }
                 if ($duplicate == 0) {
                     $results[] = User::model()->findByAttributes(array('id' => $tmp->userid));
                 }
             }
         }
         $school_id = School::model()->findAll($criteria);
         // get school ID
         foreach ($school_id as $si) {
             $student_ids = Education::model()->findAllByAttributes(array('FK_school_id' => $si->id));
             // search educations with school ID
             foreach ($student_ids as $tmp) {
                 $duplicate = 0;
                 if (sizeof($results) > 0) {
                     foreach ($results as $t) {
                         if ($t->id == $tmp->FK_user_id) {
                             $duplicate = 1;
                         }
                     }
                 }
                 if ($duplicate == 0) {
                     $results[] = User::model()->findByAttributes(array('id' => $tmp->FK_user_id));
                 }
             }
         }
     }
     if (isset($_GET['user'])) {
         $username = $_GET['user'];
     } else {
         $username = Yii::app()->user->name;
     }
     $user = User::model()->find("username=:username", array(':username' => $username));
     // pass user
     $skills = Skillset::getNames();
     // pass skills
     $universites = School::getAllSchools();
     // pass companies
     // 		foreach ($results as $tr){
     // 			print "<pre>"; print_r($tr->attributes);print "</pre>";
     // 		}
     // 		return;
     $this->render('employerSearchResults', array('results' => $results, 'skills' => $skills, 'universities' => $universites, 'user' => $user));
 }
Beispiel #15
0
 public function actionGetSchoolMap()
 {
     $_POST = (array) json_decode(file_get_contents('php://input'), true);
     $postParms = !empty($_POST['parms']) ? $_POST['parms'] : array();
     $maxmarkers = 200;
     $result = array();
     $result['SchoolList'] = array();
     if (empty($_POST)) {
         $result['IsError'] = true;
         $result['Message'] = '数据接收失败';
     } else {
         $result['IsError'] = false;
         //type
         $criteria = new CDbCriteria();
         if ($postParms['type'] == TRUE) {
             //secondary school
             $criteria->addCondition('type =1');
         }
         /* 
         			if($postParms['type'] ==  FALSE ) {  //elementary school
         				$criteria->addCondition('type =0');
         			}  */
         $chinese = preg_match("/\\p{Han}+/u", $postParms['xingzhi']);
         //XingZhi
         if (!empty($postParms['xingzhi']) && !$chinese) {
             $criteria->addCondition("xingzhi like '" . $postParms['xingzhi'] . "%'");
         }
         //Pingfen
         if (!empty($postParms['pingfen']) && intval($postParms['pingfen']) > 0) {
             $criteria->addCondition("pingfen >='" . $postParms['pingfen'] . "'");
         }
         //Rank
         if (!empty($postParms['rank']) && intval($postParms['rank']) > 0) {
             //$criteria->order = "paiming ASC";
             $criteria->addCondition("paiming <='" . $postParms['rank'] . "'");
         }
         //lat and long selection
         if (!empty($postParms['bounds'])) {
             $latlon = explode(',', $postParms['bounds']);
             $minLat = floatval($latlon[0]);
             $maxLat = floatval($latlon[2]);
             $minLon = floatval($latlon[1]);
             $maxLon = floatval($latlon[3]);
             $criteria->addCondition("lat <= :maxLat");
             $criteria->params += array(':maxLat' => $maxLat);
             $criteria->addCondition("lat >= :minLat");
             $criteria->params += array(':minLat' => $minLat);
             $criteria->addCondition("lng <= :maxLon");
             $criteria->params += array(':maxLon' => $maxLon);
             $criteria->addCondition("lng >= :minLon");
             $criteria->params += array(':minLon' => $minLon);
         }
         //Filter Invalid Lat
         $criteria->addCondition("lat > 20");
         //End of Condition
         $count = School::model()->count($criteria);
         //Display grid list if # of maxmarker is large
         if ($count >= $maxmarkers) {
             $result['type'] = "grid";
             $criteria->addCondition("pingfen >0");
             error_log("Count:" . $count . "Grid Mode");
             $criteria->limit = 2000;
             $school = School::model()->findAll($criteria);
             $result['Message'] = '成功';
             $gridx = $postParms['gridx'] ? $postParms['gridx'] : 5;
             $gridy = $postParms['gridy'] ? $postParms['gridy'] : 5;
             $tiley = ($maxLat - $minLat) / $gridy;
             $tilex = ($maxLon - $minLon) / $gridx;
             //Generate grid center Lat/Lng
             for ($x = 1; $x <= $gridx; $x++) {
                 for ($y = 1; $y <= $gridy; $y++) {
                     $gridCenterlat = $minLat + $tiley / 2 + ($y - 1) * $tiley;
                     $gridCenterlng = $minLon + $tilex / 2 + ($x - 1) * $tilex;
                     $result['gridList']["G" . $x . $y]['GeocodeLat'] = $gridCenterlat;
                     $result['gridList']["G" . $x . $y]['GeocodeLng'] = $gridCenterlng;
                 }
             }
             //Get count of school in each tile
             foreach ($school as $val) {
                 $gridlat = ceil(($val->lat - $minLat) / $tiley);
                 $gridlng = ceil(($val->lng - $minLon) / $tilex);
                 $rating = $val->pingfen;
                 $result['gridList']["G" . $gridlng . $gridlat]['GridName'] = "G" . $gridlng . $gridlat;
                 $result['gridList']["G" . $gridlng . $gridlat]['SchoolCount']++;
                 $result['gridList']["G" . $gridlng . $gridlat]['TotalRating'] += $rating;
             }
         }
         //Display school list if maxmarker is less
         if ($count < $maxmarkers) {
             $result['type'] = "school";
             $criteria->order = "paiming";
             $school = School::model()->findAll($criteria);
             $result['Message'] = '成功';
             foreach ($school as $val) {
                 $schoolList = array();
                 $schoolList['School'] = $val->school;
                 $schoolList['Paiming'] = !empty($val->paiming) ? $val->paiming : '无';
                 $schoolList['Pingfen'] = !empty($val->pingfen) ? $val->pingfen : '无';
                 $schoolList['Grade'] = $val->grade;
                 $schoolList['City'] = $val->city;
                 $schoolList['Zip'] = $val->zip;
                 $schoolList['Province'] = $val->province;
                 $schoolList['Tel'] = $val->tel;
                 $schoolList['Address'] = $val->address;
                 $schoolList['Lat'] = $val->lat;
                 $schoolList['Lng'] = $val->lng;
                 $schoolList['URL'] = $val->url;
                 $schoolList['Schoolnumber'] = $val->schoolnumber;
                 $result['SchoolList'][] = $schoolList;
             }
         }
     }
     echo json_encode($result);
 }
 public function actionLoadSchools()
 {
     $userData = Yii::app()->getRequest()->getPost('Profile', array());
     $country_id = isset($userData['country_id']) ? $userData['country_id'] : 0;
     if ($country_id != 0) {
         $data = School::model()->findAll('country_id=:country_id', array(':country_id' => $country_id));
         $listData = array();
         foreach ($data as $models) {
             $value = $models['id'];
             $coordinator = SchoolMentor::model()->find('school_id=:school_id', array(':school_id' => $value));
             if ($coordinator != null || $coordinator != 0) {
                 $name = $coordinator->user->profile->first_name;
                 $lastName = $coordinator->user->profile->last_name;
                 $text = $models['name'] . ' ( ' . Yii::t('app', 'Coordinator') . ': ' . $name . ' ' . $lastName . ' )';
             } else {
                 $text = $models['name'];
             }
             $listData[$value] = $text;
         }
         $data = $listData;
         // $data = CHtml::listData($data,"id","name");
         echo CHtml::tag('option', array('value' => 'choose'), Yii::t('app', 'choose'), true);
         foreach ($data as $value => $name) {
             //CHtml::encode($name)
             echo CHtml::tag('option', array('value' => $value), $name, true);
         }
     } else {
         echo 'Invalid country';
     }
 }