private function _add() { use_helper('Validate'); $data = $_POST['experience']; Flash::set('experience_postdata', $data); // Add pre-save checks here $errors = false; // CSRF checks if (isset($_POST['csrf_token'])) { $csrf_token = $_POST['csrf_token']; if (!SecureToken::validateToken($csrf_token, BASE_URL . 'experience/add')) { Flash::set('error', __('Invalid CSRF token found!')); redirect(get_url('experience/add')); } } else { Flash::set('error', __('No CSRF token found!')); redirect(get_url('experience/add')); } if (empty($data['name'])) { Flash::set('error', __('You have to specify a experience name!')); redirect(get_url('experience/add')); } if ($errors !== false) { // Set the errors to be displayed. Flash::set('error', implode('<br/>', $errors)); redirect(get_url('experience/add')); } $oExperience = new Experience(); $last_seq = $oExperience->getLastExperienceSeq(); $new_experience = new Experience($data); $new_experience->created_by_id = AuthUser::getId(); $new_experience->created_on = date('Y-m-d H:i:s'); $new_experience->sequence = $last_seq + 1; if ($new_experience->save()) { if (isset($_FILES)) { if (strlen($_FILES['upload_file']['name']) > 0) { $experience_id = $new_experience->lastInsertId(); //okstmtcc 20150827 Replace image filename spaces $_FILES['upload_file']['name'] = str_replace(array(" ", "(", ")"), array("_", "", ""), $_FILES['upload_file']['name']); $overwrite = false; $file = $this->upload_experience_main_image($experience_id, $_FILES['upload_file']['name'], FILES_DIR . '/experience/images/', $_FILES['upload_file']['tmp_name'], $overwrite); if ($file === false) { Flash::set('error', __('Image has not been uploaded!')); redirect(get_url('experience/edit/' . $new_experience->id)); } } } Flash::set('success', __('Experience has been added!')); Observer::notify('experience_after_add', $new_experience->name); // save and quit or save and continue editing? if (isset($_POST['commit'])) { redirect(get_url('experience')); } else { redirect(get_url('experience/edit/' . $new_experience->id)); } } else { Flash::set('error', __('Experience has not been added!')); redirect(get_url('experience/add')); } }
$experience->id = (int) $_GET['id']; if ($experience->delete()) { $session->message("Experience deleted "); redirect_to($_SERVER['PHP_SELF'] . "?#" . $_GET['id']); die; } else { $message = join("<br />", $experience->errors); } } if (isset($_GET['action']) && $_GET['action'] == "add") { if (isset($_POST['bt_add'])) { $add_new = new Experience(); $add_new->experience_name = $_POST['txt_experience_name']; $add_new->var_name = $add_new->mod_write_check($_POST['txt_experience_name']); $add_new->is_active = $_POST['txt_is_active']; if ($add_new->save()) { $session->message("New Year Experience added."); redirect_to($_SERVER['PHP_SELF']); die; } else { $message = join("<br />", $add_new->errors); } } } $experience = Experience::find_all(); $manage_lists = array(); if ($experience && is_array($experience)) { $i = 1; foreach ($experience as $list) { $manage_lists[$i]['id'] = $list->id; $manage_lists[$i]['experience_name'] = $list->experience_name;
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"); } }
public function save() { $isSaved = null; $experience = new Experience(); $transaction = $experience->dbConnection->beginTransaction(); try { if (isset($this->free) && $this->free === true) { unset($this->Price); } $experience->Name = $this->Name; $experience->ExperienceType = $this->ExperienceType; $experience->Audience = $this->Audience; $experience->Category_ID = $this->Category_ID; $experience->Start = $this->Start; $experience->End = $this->End; $experience->Description = $this->Description; $experience->Offering = $this->Offering; $experience->FinePrint = $this->FinePrint; $experience->Price = $this->Price; $experience->Min_occupancy = $this->Min_occupancy; $experience->Max_occupancy = $this->Max_occupancy; $experience->MaxPerPerson = $this->MaxPerPerson; $experience->MultipleAllowed = $this->MultipleAllowed; $appropriateAges = 0; if (isset($this->AppropriateAges) && is_array($this->AppropriateAges)) { foreach ($this->AppropriateAges as $age) { $appropriateAges += $age; } } $experience->AppropriateAges = $appropriateAges; $location = $this->getLocation(); $experience->Location_ID = $location->Location_ID; $experience->save(); $this->experience = $experience; if ($this->imageFiles != null) { foreach ($this->imageFiles as $imageFile) { $content = Content::AddContent($imageFile, 'Class Image', ContentType::ImageID); $experienceToContent = new ExperienceToContent(); $experienceToContent->Experience_ID = $this->experience->Experience_ID; $experienceToContent->Content_ID = $content->Content_ID; $experienceToContent->save(); } } if (isset($this->fromRequest_ID) && is_numeric($this->fromRequest_ID)) { $request = Request::model()->findByPk($this->fromRequest_ID); if ($request != null) { $request->Created_Experience_ID = $this->experience->Experience_ID; $request->save(); // Notify the students foreach ($request->requestors as $user) { if ($user->User_ID != $this->experience->Create_User_ID) { $userName = CHtml::link($this->experience->createUser->fullName, array('//user/view', 'id' => $this->experience->createUser->User_ID)); $requestName = CHtml::link($request->Name, array('//request/view', 'id' => $request->Request_ID)); $experienceName = CHtml::link($this->experience->Name, array('//experience/view', 'id' => $this->experience->Experience_ID)); Message::SendNotification($user->User_ID, "{$userName} has picked up the request \"{$requestName}\" and created the experience \"{$experienceName}\"."); } } } } $tagsArray = Tag::model()->string2array($this->tags); foreach ($tagsArray as $tagName) { $tag = Tag::model()->findOrCreate($tagName); $experienceToTag = new ExperienceToTag(); $experienceToTag->Experience_ID = $this->experience->Experience_ID; $experienceToTag->Tag_ID = $tag->Tag_ID; $experienceToTag->save(); } if (isset($this->sessions) && strlen($this->sessions) > 0) { $sessionData = json_decode($this->sessions); foreach ($sessionData as $sessionItem) { $session = new Session(); $session->Experience_ID = $this->experience->Experience_ID; $session->Start = $sessionItem->Start; $session->End = $sessionItem->End; $session->save(); } } $transaction->commit(); $isSaved = true; } catch (Exception $e) { $isSaved = false; $transaction->rollback(); } return $isSaved; }
function updatePosition() { $positionList = $this->input->post('positionList'); $idList = $this->input->post('idList'); $o = new Experience(); for ($i = 0; $i < count($idList); $i++) { $o->where("id", $idList[$i]); $o->get(); $o->position = $positionList[$i]; $o->save(); $o->clear(); } redirect("admin/experiences/listAll/"); }