I am working on a codeigniter listing application, everything is working fine in the application but when I am submitting the listing form, the user session data is lost.
I am having: agentId in session, which is visible after login but after submitting it is not in the session data.
Code:
$agentId = $this->session->userdata('agentId');
var_dump($this->session->userdata);
die;
\\ This session showing all user data including agentId
$data['p_title'] = $this->project_model->projectName().' :: Property : Add New Property';
$data['Message'] = '';
$data['heading'] = 'Property: Add New Property';
$data['pageName'] = 'property';
$data['title'] = filter_value('title', '');
$data['meta_decription'] = filter_value('meta_decription', '');
$data['keywords'] = filter_value('keywords', '');
$data['type'] = filter_value('type', '');
$data['sub_type'] = filter_value('sub_type', '');
//$data['sub_type1'] = filter_value('sub_type1', '');
$data['bedrooms'] = filter_value('bedrooms', '');
$data['kitchen'] = filter_value('kitchen', '');
$data['parking'] = filter_value('parking', 'YES');
$data['bathrooms'] = filter_value('bathrooms', '');
$data['area'] = filter_value('area', '');
$data['price'] = filter_value('price', '0.00');
$data['location'] = filter_value('location', '');
$data['city'] = filter_value('city', 82);
$data['country'] = filter_value('country', 102);
$data['details'] = filter_value('details', '');
$data['featured'] = filter_value('featured', 'NO');
$data['countries'] = $this->general_model->listCountries($data['country']);
$data['cities'] = $this->general_model->listCities($data['country'], $data['city']);
$this->form_validation->set_rules('title', 'Property title', 'trim|required');
if($this->form_validation->run() === TRUE){
$agentId = $this->session->userdata('agentId');
var_dump($this->session->userdata);
die;
\\ but here the agent id and rest of user session data is removed.
$Date = getCurrentDate();
$Time = getCurrentTime();
$DbFieldsAry = array('agentId', 'title', 'meta_decription', 'keywords', 'type', 'sub_type', 'bedrooms', 'kitchen', 'parking', 'bathrooms', 'area', 'price', 'location', 'city', 'country', 'details', 'featured', 'date');
$InfoAry = array($this->session->userdata('agentId'), $data['title'], $data['meta_decription'], $data['keywords'], $data['type'], $data['sub_type'], $data['bedrooms'], $data['kitchen'], $data['parking'], $data['bathrooms'], $data['area'], $data['price'], $data['location'], $data['city'], $data['country'], $data['details'], $data['featured'], $Date);
if($this->general_model->addInfo_Simple($DbFieldsAry, $InfoAry, 'tbl_properties_list')){
$activityId = $this->general_model->getSingleValue($data['title'], 'title', 'property_id', 'tbl_properties_list');
setMessage('success_message', 'New property added successfully. Add pictures to property.');
redirect(base_url().'property/update/'.$activityId.'/0', 'refresh');
}
else{
setMessage('error_message', 'Unable to perofrm this operation, please try again later!');
redirect(base_url().'property/user_listing', 'refresh');
}
}
$data['allowed'] = true;
$data['warning'] = '';
if(!isSuperAdmin()){
$total_properties = $this->general_model->getTotalDataSimple1('property_id','tbl_properties_list');
if(allowed_properties() <= $total_properties){
$data['allowed'] = false;
$data['warning'] = '<br/>You have reached to maximum limit of your property upload listing.<br/>Click HERE to change payment plan.<br/><br/><br/><br/><br/>';
}
}
$this->load->view('add_property', $data);
The first var_dump for session check shows all session data, but why is all the user session data lost after submitting?
Related
I am adding product into cart and tried to map customer id,email to that quote
using the below code
$product_id = 123;
$qty = 1;
$product = Mage::getModel('catalog/product')->load($product_id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$superAttributeArray = array('151' => '3');
$params = array(
'product' => $product_id,
'qty' => $qty,
'super_attribute' => $superAttributeArray
);
$cart->addProduct($product, $params);
$cart->save();
$currenQuoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$store = Mage::getSingleton('core/store')->load(Mage::app()->getStore()->getId());
$quote = Mage::getModel('sales/quote')->setStore($store)->load($currenQuoteId);
$quote->setCustomerId('1')->setCustomerEmail('test#gmail.com')->setCustomerFirstname('firstname')->setCustomerLastname('lastname');
$quote->save();
When I try to set customerid,email,fname,lname am getting error as "Mage registry key "controller" already exists".
Can anyone help me in fixing this issue?
Something like this might work
$customerObj = Mage::getModel('customer/customer')->load($customerId);
$quoteObj = Mage::getModel('sales/quote')->assignCustomer($customerObj);
$storeId = Mage::app()->getStore()->getId();
$quoteObj->setStore(Mage::getSingleton('core/store')->load($storeId);
$productObj = Mage::getModel('catalog/product')->load($productId);
$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
$quoteItem->setQuote($quoteObj);
$quoteItem->setQty('1');
$quoteItem->setStoreId($storeId);
$quoteObj->addItem($quoteItem);
$quoteObj->setStoreId($storeId);
$quoteObj->collectTotals();
$quoteObj->save();
We're using the PayPal PHP SDK to create a "Recurring Payments Profile", but every profile is missing the "Buyer Information" (Name & Email) under "History" in our Sandbox account.
How can we add the buyer's name and email address to the request?
$firstName = $_POST[ 'firstName' ];
$lastName = $_POST[ 'lastName' ];
$email = $_POST[ 'email' ];
$installment_amount = ...;
$shippingAddress = new AddressType();
$shippingAddress->Name = $firstName . ' ' . $lastName;
$shippingAddress->Street1 = $_POST[ 'address1' ];
$shippingAddress->Street2 = $_POST[ 'address2' ];
$shippingAddress->CityName = $_POST[ 'city' ];
$shippingAddress->StateOrProvince = $_POST[ 'state' ];
$shippingAddress->PostalCode = $_POST[ 'zip' ];
$shippingAddress->Country = $_POST[ 'country' ];
$shippingAddress->Phone = $_POST[ 'phone' ];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $firstName . ' ' . $lastName;
$RPProfileDetails->BillingStartDate = date( DATE_ATOM );
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();
$activationDetails->InitialAmount = new BasicAmountType( 'USD', $installment_amount );
$activationDetails->FailedInitialAmountAction = 'CancelOnFailure';
$paymentBillingPeriod = new BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = 1;
$paymentBillingPeriod->BillingPeriod = 'Day';
$paymentBillingPeriod->TotalBillingCycles = 2;
$paymentBillingPeriod->Amount = new BasicAmountType( 'USD', $installment_amount );
$scheduleDetails = new ScheduleDetailsType();
$scheduleDetails->Description = ...;
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$scheduleDetails->MaxFailedPayments = 3;
$scheduleDetails->AutoBillOutstandingAmount = 'AddToNextBilling';
$createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
$cardDetails = new CreditCardDetailsType();
$cardDetails->CreditCardNumber = $_POST[ 'creditCardNumber' ];
$cardDetails->CreditCardType = $_POST[ 'creditCardType' ];
$cardDetails->ExpMonth = $_POST[ 'expDateMonth' ];
$cardDetails->ExpYear = $_POST[ 'expDateYear' ];
$cardDetails->CVV2 = $_POST[ 'cvv2Number' ];
$createRPProfileRequestDetail->CreditCard = $cardDetails;
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
$paypalService = new PayPalAPIInterfaceServiceService( ... );
try {
$createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile( $createRPProfileReq );
} catch ( Exception $exception ) {
...
}
As long as you are passing the shipping information in the Profile Details it should get passed into the transaction information in Sandbox. Billing address is not stored in the PayPal Transactions.
Your code looks like it should be passing the information correctly. As a just in case, look over the below sample code from GitHub. I didn't paste all of the code in.
Merchant SDK php Sample for Recurring Billing
$shippingAddress = new AddressType();
$shippingAddress->Name = $_REQUEST['shippingName'];
$shippingAddress->Street1 = $_REQUEST['shippingStreet1'];
$shippingAddress->Street2 = $_REQUEST['shippingStreet2'];
$shippingAddress->CityName = $_REQUEST['shippingCity'];
$shippingAddress->StateOrProvince = $_REQUEST['shippingState'];
$shippingAddress->PostalCode = $_REQUEST['shippingPostalCode'];
$shippingAddress->Country = $_REQUEST['shippingCountry'];
$shippingAddress->Phone = $_REQUEST['shippingPhone'];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $_REQUEST['subscriberName'];
$RPProfileDetails->BillingStartDate = $_REQUEST['billingStartDate'];
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();
I am using TYPO3 6.1 and try to login a FE user via Code (included via PHP and USER_INT).
This code does not work for me. :( Any ideas why?
// try to login the user now
$loginData = array(
'uname' => trim($postData['username']), //usernmae
'uident' => trim($postData['password']), //password
'status' => 'login'
);
// $GLOBALS['TSFE']->fe_user-checkPid=0; //do not use a particular pid
$GLOBALS['TSFE']->fe_user->checkPid = $this->feUserPid; // ''; //do not use a particular pid
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
//
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord(
$info['db_user'], $loginData['uname']
);
$ok = $GLOBALS['TSFE']->fe_user->compareUident($user, $loginData);
//
if($ok)
{
// login successfull
$GLOBALS['TSFE']->fe_user->createUserSession($user);
//
$content = '<h3 class="green">LOGIN OK!</h3>';
$content .= '<p>Sie sind eingeloggt als ' . $feUsername . ' und wurden nun weitergeleitet...</p>';
}
else
{
// login failed
$content = '<h3 class="red">LOGIN FAILED!</h3>';
}
Thanks for any hint!
Starting with TYPO3 4.7, you must use $loginData['uident_text'] instead of $loginData['uident'] for the password.
If the problem persists, please give more information what exactly is going wrong, what your log says etc.
Does compareUident() return TRUE for you?
I, fx have a case, where I automatically log in user that has just created themselves. And compareUident() didn't work for me for some reason, but as I know this same website visitor just created the user, I skip that function and continue on initiating all the session variables. The following is a working code on TYPO3 6.1:
$loginData = array(
'uname' => $postdata['username'],
'uident' => $postdata['password'],
'status' => 'login',
);
$GLOBALS['TSFE']->fe_user->checkPid = 0;
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'], $loginData['uname']);
//if($GLOBALS['TSFE']->fe_user->compareUident($user, $loginData)) {
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
$GLOBALS['TSFE']->loginUser = 1;
$GLOBALS['TSFE']->fe_user->fetchGroupData();
$GLOBALS['TSFE']->fe_user->start();
$GLOBALS['TSFE']->fe_user->createUserSession($user);
$GLOBALS['TSFE']->fe_user->loginSessionStarted = TRUE;
//}
Inspired by:
https://stackoverflow.com/a/7738383/445364
https://typo3.org/extensions/repository/view/dix_easylogin
Hy,
I have some problem vith Zend_Db_Select.
I have 2 variable : category and city. These 2 variables may have a value or they may be unset.
So I verify:
$status = '`p`.status = 1';
if($catID){
$catSQL = "`p`.parent = {$catID}";
}else{
$catSQL = '1=1';
}
if($city){
$citySQL = "`pm`.`meta_key` = 'oras' and `pm`.`meta_value` = {$city}";
$citySelect = array('pm' => 'postsmeta');
$condCity = "`p`.`ID` = `pm`.`parent_id`";
}else{
$citySQL = '1=1';
$citySelect = NULL;
$condCity = '1=1';
}
Now here is my query:
$select = $db->select()
->from( array('p' => 'posts'))
->from($citySelect)
->where($status)
->where($catSQL)
->where($condCity)
->where($citySQL)
;
The problem is that if city is empty I have something like
$select = $db->select()
->from( array('p' => 'posts'))
->from('')
->where(1=1)
->where(1=1)
->where(1=1)
->where(1=1)
;
The questions is how can I remove from('') from my query if city is empty.
Thank you!
Simply,
$select = $db->select()
->from( array('p' => 'posts'));
if($someConditionIsTrue) {
$select->join($table, $condition);
}
$select->where('field_value = ?', 'value1');
if($someConditionIsTrue) {
$select->where('another_field = ?', 'value 2');
}
Hope it helps.
Please use this syntax $select->where('another_field = ?', 'value 2'); for proper escaping values to prevent SQL injections.
please help..I'm newbies and try to learn Zend Framework, but have problem when uploading image.
The script at file Application.ini
uploads.uploadPath = APPLICATION_PATH "/../public/uploads"
Form to upload Image:
$this->setAction('/data/personil/create')
->setMethod('post');
//Item input untuk gambar
$images = new Zend_Form_Element_File('images');
$images->setMultiFile(3)
->addValidator('IsImage')
->addValidator('Size', false, '204800')
->addValidator('Extension', false, 'jpg,png,gif')
->addValidator('ImageSize', false, array(
'minwidth' => 150,
'minheight' => 150,
'maxwidth' => 700,
'maxheight' => 700
))
->setValueDisabled(true);
// attach element to form
$this->addElement($images);
// create display group for file elements
$this->addDisplayGroup(array('images'), 'files');
$this->getDisplayGroup('files')
->setOrder(40)
->setLegend('Images');
Controller action create :
public function createAction()
{
$form = new Pengadilan_Form_PersonilCreate();
$this->view->form = $form;
$flashMessenger = $this->_helper->FlashMessenger;
//SImpan kedatabase
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
$personil = new Pengadilan_Model_Personil();
$personil->fromArray($form->getValues());
$personil->RecordDate = date('Y-m-d', mktime());
$personil->DisplayStatus = 0;
$personil->DisplayUntil = null;
$personil->save();
$id = $personil->RecordId;
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
$form->images->setDestination($config['uploadPath']);
$adapter = $form->images->getTransferAdapter();
for($x=0; $x<$form->images->getMultiFile(); $x++) {
$xt = #pathinfo($adapter->getFileName('images_'.$x.'_'), PATHINFO_EXTENSION);
$adapter->clearFilters();
$adapter->addFilter('Rename', array(
'target' => sprintf('%d_%d.%s', $id, ($x+1), $xt),
'overwrite' => true
));
$adapter->receive('images_'.$x.'_');
}
$this->_helper->getHelper('FlashMessenger')->addMessage('Data sekses diinput ke database #' . $id . '. Admin akan segera merivew, jika diterima, akan ditampilkan dalam waktu 48 jam, Terima kasih.');
$this->_redirect('/data/personil/sukses');
}
}
}
Controller action display :
public function displayAction()
{
//Pertama setting filters
$filters = array(
'id' => array('HtmlEntities', 'StripTags', 'StringTrim')
);
$validators = array(
'id' => array('NotEmpty', 'Int')
);
$input = new Zend_Filter_Input($filters, $validators);
$input->setData($this->getRequest()->getParams());
if($input->isValid()){
$q = Doctrine_Query::create()
->from('Pengadilan_Model_Personil p')
->leftJoin('p.Pengadilan_Model_Jabatan j')
->leftJoin('p.Pengadilan_Model_Tupoksi t')
->leftJoin('p.Pengadilan_Model_Golongan g')
->leftJoin('p.Pengadilan_Model_Agama a')
->leftJoin('p.Pengadilan_Model_Kelamin k')
->where('p.RecordId = ?', $input->id)
->addWhere('p.DisplayStatus = 1')
->addWhere('p.DisplayUntil >= CURDATE()');
$result = $q->fetchArray();
if(count($result) == 1){
$this->view->personil = $result[0];
$this->view->images = array();
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
foreach (glob("{$config['uploadPath']}/{$this->view->item['RecordID']}_*") as $file) {
$this->view->images[] = basename($file);
}
}else{
throw new Zend_Exception('Maaf, halaman tidak ditemukan, 404');
}
}else{
throw new Zend_Exception('Kesalahan Input');
}
}
The last script at view : display.phtml
<div id="images">
<?php foreach ($this->images as $image): ?>
<img src="/uploads/<?php echo $this->escape($image); ?>" width="150" height="150" />
<?php endforeach; ?>
Image upload Destination at config is /public/uploads
in my case image at /public
Image succes to upload and renamed but outside the directory and
Image won't displayed at display.phtml
Many thanks for your help..
First you need to set your form encoding File element link$form->setAttrib('enctype', 'multipart/form-data');
Also you should probably finish setting up your image element before you POST the form not after. So move the setDestination stuff up to where you initialize the form, you may have a better chance of it working.
public function createAction()
{
$form = new Pengadilan_Form_PersonilCreate();
//set form encoding
$form->setAttrib('enctype', 'multipart/form-data');
//get path and set destination for image element
$config = $this->getInvokeArg('bootstrap')->getOption('uploads');
$form->images->setDestination($config['uploadPath']);
$this->view->form = $form;
//consider intializing flash messenger in the init() method
$flashMessenger = $this->_helper->FlashMessenger;
//SImpan kedatabase
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
//more code...
$adapter = $form->images->getTransferAdapter();
for($x=0; $x<$form->images->getMultiFile(); $x++) {
$xt = #pathinfo($adapter->getFileName('images_'.$x.'_'), PATHINFO_EXTENSION);
$adapter->clearFilters();
$adapter->addFilter('Rename', array(
'target' => sprintf('%d_%d.%s', $id, ($x+1), $xt),
'overwrite' => true
));
$adapter->receive('images_'.$x.'_');
}
$this->_helper->getHelper('FlashMessenger')->addMessage('Data sekses diinput ke database #' . $id . '. Admin akan segera merivew, jika diterima, akan ditampilkan dalam waktu 48 jam, Terima kasih.');
$this->_redirect('/data/personil/sukses');
}
}
}
not sure if this will fix everything but it should be a start...