I have created a system where users can search for payment solutions for their business here: http://104.236.45.72/
When you click an answer for a question, you'll notice that as you click through on chrome, you get a list at the top of previously answered questions.
When you view this same thing on your mobile device, you'll notice that the questions as the top only show ONE. It's like the session is not persisting on mobile. I have no idea why and I've tried changing the session driver from database to file and tried replacing all of the "$request->session->" references with "Session::", which leads to the same thing, it working on desktop and only showing one previous answer on mobile.
Here is the function being called when you answer a question on the fontend.
public function questions(Request $request, $id, $parentId, $question)
{
//Get the industry...
$data['industry'] = Industries::find($id);
//Get the parent level question and one child...
$data['parentQuestion'] = Questions::where('parentId', $parentId)->where('industryId', $id)->get();
if(count($data['parentQuestion']) > 0) {
foreach($data['parentQuestion'] as $pq) {
if($pq->parentId != 0) {
//How many steps are currently in the array?
if ($request->session()->has('lastSteps')) {
$hasLastSteps = TRUE;
}else {
$hasLastSteps = FALSE;
}
$stepCount = 1;
if($hasLastSteps == TRUE) {
$stepCount += count(Session('lastSteps'));
}
//Get the last steps ready...
$lsQuestion = Questions::find($question);
$lsAnswer = Questions::find($parentId);
$lsQ = array(
'unique' => uniqid(),
'questionId' => $question,
'question' => $lsQuestion->question,
'answer' => $lsAnswer->question,
'url' => '/'.$request->path(),
'stepCount' => $stepCount
);
$dup = 0;
//see if the session has a lastSteps array...
if ($hasLastSteps == TRUE) {
$temp = Session('lastSteps');
foreach($temp as $t) {
if($t['questionId'] == $question) {
$dup = 1;
}
}
}
//No duplicates exist, go ahead and add it to the session!
if($dup === 0) {
$request->session()->push('lastSteps', $lsQ);
}
}
//Grab its children...
if($pq->type === 'question') {
$data['children'] = Questions::where('industryId', $id)->where('parentId', $pq->id)->get();
}else {
//its an endpoint / answer!
}
}
}
//see if the session has a follow up array...
if ($request->session()->has('followUp')) {
$data['followUp'] = Session('followUp');
}else {
$data['followUp'] = array();
}
//see if the session has a lastSteps array...
if ($request->session()->has('lastSteps')) {
$data['lastSteps'] = Session('lastSteps');
}else {
$data['lastSteps'] = array();
}
return view('frontend.questions', $data);
}
Related
I have an IVR that plays some audios for the user and then I need to redirect to another php file. The strange thing is that this redirect does not work.
NOTE 1: the redirect that does not work is the last one ($response->redirect("./chooseLicense.php?rs=$rs"))
NOTE 2: if I put it in if(!is_object($rs)) it works perfectly.
Can anyone tell me why this happens?
Snippet of my code:
$rs = json_decode(Curl::post(baseUrl . "users/auth/", $cpfOrCnpj, $password));
// logText('rs in login', $rs);
if(!is_object($rs)) {
$gather->play("https://digital-lock-api.azurewebsites.net/ura-hmg/assets/audios/licenseNotFound.mp3");
}
if($rs->licenses === []) {
$gather->play("https://digital-lock-api.azurewebsites.net/ura-hmg/assets/audios/licenseNotFound.mp3");
}
if(count($rs->licenses) == 1) {
$licenseId = $rs->licenses[0]->id;
$isBlocked = $rs->licenses[0]->blocked;
$token = $rs->auth->token;
$response->redirect("./waitForFlip.php?licenseId=$licenseId&isBlocked=$isBlocked&token=$token");
}
if(count($rs->licenses) > 1) {
$count = 0;
foreach($rs->licenses as $license) {
$count++;
$gather->play("https://digital-lock-api.azurewebsites.net/ura-hmg/assets/audios/chooseLicense$count.mp3");
$gather->play($license->nicknameAudioUrl);
}
$rs = json_encode($rs);
logText("rs encode", $rs);
$response->redirect("./chooseLicense.php?rs=$rs");
}
I'm using codigniter 3.1.2 and using simple if condition in php but really confused when I checked my condition is true getting result from else condition as well and if as well mean getting data in from both cases.
public function editexperience($UserID = 0, $ID = 0) {
if ($this->Access->HaveAccess('Edit')) {
$Row = $this->Experience->Row($ID);
if ($ID > 0 && $Row){
print_r($Row);
Def(array(
'Update'=>'users/submit/updateexperience/'
),'Actions');
$User = $this->Model->Row(intval($UserID), '', 'CTRY.Currency');
$ID = intval($ID);
$Data['Row'] = $Row;
Def($Row,'Row');
$Data['Title'] = 'Edit Experience';
$Data['Fields'] = $this->GetExperienceFields($User->Currency, true);
$this->Main->SetPage('Helper/Edit', $Data, true);
} else {
TempNote('There is problem while getting request data!', 'Error');
redirect(URI(_E('{Page.List}'), true), 'refresh');
die();
}
}
}
In code I mentioned if I have Row then load template of edit.
Suppose:
I have Row and its loading edit template and also showing the error of else condition really confuse what is happening.
My PHP version is 5.6.31
TempNote Function
function TempNote($Message, $Type) {
//Prepare Data
$Current = array('Message'=>$Message,'Type'=>$Type);
//Get current instance
$Ins = & get_instance();
$Old = $Ins->Main->Messages;
// If another is already set and that should not be current
if (!empty($Old)) {
foreach ($Old as $Key=>$Now) {
if ($Now === $Current){
unset($Old[$Key]);
}
}
}
$Ins->Main->Messages[] = $Current;
$Ins->session->set_flashdata('Message', $Ins->Main->Messages);
}
I have this PHP code where I am loading a quiz into the view. When I select and submit an answer the view is changed and displays only the correct message or the wrong one.
What I am trying to achieve is when clicking the submit button for the answer, to keep the question and just display under if correct or not.
This is the code that I have:
function guess()
{
$guess = $this->input->get('name',false);
$personid = $this->input->get('id',false);
if ($guess === null) {
$newguess['data'] = $this->Starmodel->getQuestion();
$this->load->view('starview',$newguess);
}
else {
$res= $this->Starmodel->isCorrectAnswer($personid,$guess);
$person = $this->load->view('starview', array('iscorrect' => $res,
'name' => $guess));
}
}
My main view is starview.php. Can I use divs and target a specific load a view inside the specific div? How can I do this?
Thank you
Let say this your startview view...
//Your question goes here
//Answer part
<?php if($this->input->post()):
echo $answer_view_data
endif; ?>
In your function guess()
function guess()
{
$guess = $this->input->get('name',false);
$personid = $this->input->get('id',false);
if ($guess === null) {
$newguess['data'] = $this->Starmodel->getQuestion();
$this->load->view('starview',$newguess);
}
else {
$res= $this->Starmodel->isCorrectAnswer($personid,$guess);
$answer_data = 'Sample answer data';
$person = $this->load->view('starview', array('iscorrect' => $res,
'name' => $guess, 'answer_data' => $answer_data));
}
}
Whenever comment on any one of the issues, comment save successfully.
Comment saving code in given below:
$user = elgg_get_logged_in_user_entity();
$p_url = parse_url($_SERVER['HTTP_REFERER']);
if($p_url['path'] == '/issues/view' || $p_url['path'] == '/issues/respond')
$tracker_comment = TRUE;
else
$tracker_comment = FALSE;
if($tracker_comment)
{
action_gatekeeper();
// Get input
$entity_guid = (int) get_input('entity_guid');
$comment_text = get_input('generic_comment');
// Let's see if we can get an entity with the specified GUID
if ($entity = get_entity($entity_guid)) {
$comment = new ElggComment();
$comment->description = $comment_text;
$comment->owner_guid = $user->getGUID();
$comment->container_guid = $entity->getGUID();
$comment->access_id = $entity->access_id;
$guid = $comment->save();
// If posting the comment was successful, say so
if ($guid) {
system_message(elgg_echo("generic_comment:posted"));
} else {
register_error(elgg_echo("generic_comment:failure"));
}
} else {
register_error(elgg_echo("generic_comment:notfound"));
}
// Forward to the
forward($entity->getURL());
}
else
RETURN TRUE;
I am unable to retrieve the last comment username not updated in list of issues. I am using elgg_get_annotation() to retrieve the last comment details.
But not retrieving the details. Last comment code in given bellow.
if ($table_rows) {
foreach ( $table_rows as $entity ) {
if ($entity->unread == 1) {
$unread = "Yes";
} else {
$unread = "No";
}
if ($entity->assigned_to == 0) {
$assigned = "No";
} else {
$assigned = "Yes";
}
$last_options = array ();
$comments = elgg_get_annotations(array(
'annotation_names' => 'issue_tracker_changes',
'guid' => $entity->guid,
'limit' => 1,
'order_by' => 'n_table.id DESC',
));
foreach ( $comments as $comment ) {
$last_comment = get_entity ( $comment->owner_guid );
}
Comments are no longer annotations since Elgg 1.9 but entities. You are creating comment using ElggComment class that represents entity so you're using Elgg 1.9 or newer. You just need to use elgg_get_entities instead of elgg_get_annotations. Use type object and subtype comment.
I am struggling to workout a good method to update one column of my wcx_options table.
The new data is sent fine to the controller but my function isn't working at all.
I assumed i could loop through each column by option_id updating with the values from the array.
The database:
I update the option_value column with the new information via a jQuery AJAX Call to a controller which then calls a function from the backend class.
So far i have the following code:
if(isset($_POST['selector'])) {
if($_POST['selector'] == 'general') {
if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && isset($_POST['token'])
&& $_POST['token'] === $_SESSION['token']){
$site_name = $_POST['sitename'];
$site_url = $_POST['siteurl'];
$site_logo = $_POST['sitelogo'];
$site_tagline = $_POST['sitetagline'];
$site_description = $_POST['sitedescription'];
$site_admin = $_POST['siteadmin'];
$admin_email = $_POST['adminemail'];
$contact_info = $_POST['contactinfo'];
$site_disclaimer = $_POST['sitedisclaimer'];
$TimeZone = $_POST['TimeZone'];
$options = array($site_name, $site_url, $site_logo, $site_tagline, $site_description, $site_admin, $admin_email,$contact_info, $site_disclaimer, $TimeZone);
// Send the new data as an array to the update function
$backend->updateGeneralSettings($options);
}
else {
$_SESSION['status'] = '<div class="error">There was a Problem Updating the General Settings</div>';
}
}
}
This is what i have so far in terms of a function (It doesnt work):
public function updateGeneralSettings($options) {
$i = 1;
foreach($options as $option_value) {
$where = array('option_id' => $i);
$this->queryIt("UPDATE wcx_options SET option_value='$option_value' WHERE option_id='$where'");
$i++;
}
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}
With the given DB-layout i'd suggest to organize your data as assiciative array using the db fieldnames, like:
$option = array(
'site_name' => $_POST['sitename'],
'site_url' => $_POST['siteurl'],
// etc.
'timeZone' => $_POST['TimeZone']
);
And than use the keys in your query:
public function updateGeneralSettings($options) {
foreach($options as $key => $value) {
$this->queryIt("UPDATE wcx_options SET option_value='$value' WHERE option_name='$key'");
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}
}
(However, are you sure, you do not want to have all options together in one row?)
Change your query, you try to use an array as where condition. In the syntax you used that won't work. Just use the counter as where condition instead of define a $where variable. Try this:
public function updateGeneralSettings($options) {
$i = 1;
foreach($options as $option_value) {
$this->queryIt("UPDATE wcx_options SET option_value='$option_value' WHERE option_id='$i'");
$i++;
}
if($this->execute()) {
$_SESSION['success'] = 'Updated General Settings Successfully';
}
}