I had a problem with ActiveRecords - CI add brackets to the table names - so oracle returns errors.
Here is some info how to fix it :)
first configure your database
My old dns config looks like this
$dsn = array(
'phptype' => 'oci8',
'hostspec' => '192.xx.215.xx',
'service' => 'yyyyy',
'port' => '1521',
'username' => 'zzzzz',
'password' => 'aaaaa'
);
So I added in application\config\database.php this:
$db['oracle']['hostname'] = "192.xx.215.xx/yyyyy";
$db['oracle']['username'] = "zzzzz";
$db['oracle']['password'] = "ttttt";
$db['oracle']['database'] = "dbname.table";
$db['oracle']['dbdriver'] = "oci8";
$db['oracle']['dbprefix'] = "";
$db['oracle']['pconnect'] = FALSE; //must be false
$db['oracle']['db_debug'] = TRUE;
$db['oracle']['cache_on'] = FALSE;
$db['oracle']['cachedir'] = "";
$db['oracle']['char_set'] = "utf8";
$db['oracle']['dbcollat'] = "utf8_general_ci";
in system\database\drivers\oci8\oci8_driver.php replace line
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
with
// remove duplicates if the user already included the escape
$str = preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
$str = rtrim($str,'"');
$str = ltrim($str,'"');
$str = str_replace('"."', '.', $str);
return $str;
Now i your model you can call
$this->oracle = $this->load->database('oracle', TRUE);
Now Oracle and Ci should works! :)
Related
I am uses validation for gst and adhar but when its error free i am updating value but value can not updating. I am giving updating code in else part. what is mistake done by me? need a solution. In if part i am checking validation and in else part if error is not coming, i am updating value from table but i can not work.
public function profile_update(Request $req,$id)
{
$mytime = Carbon::now();
$fullname = $req->input('fullname');
$email = $req->input('email');
$mobile = $req->input('mobile');
$gender = $req->input('gender');
$gstnumber = $req->input('gst_number');
$adharnumber = $req->input('aadhar_number');
$password = $req->input('password');
$cpassword = $req->input('c_password');
$updated_at = $mytime->toDateTimeString();
$created_at = $mytime->toDateTimeString();
$validator = Validator::make($req->all(), [
'email' => 'email|unique:users,email',
'aadhar_number' => 'unique:users,aadhar_number' ,
'gst_number' => 'regex:^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$^|unique:users,gst_number'
]);
if($validator->fails())
{
//dd("hello");
$messages = $validator->messages();
//return Redirect::to('/customer')->with('message', 'Register Failed');
return redirect('/profile')
->withErrors($validator)
->withInput();
}
else
{
if ($req->hasFile('update_image'))
{
$image = $req->file('update_image');
$filename = $image->getClientOriginalName();
$destinationPath = public_path('/images/users_profile/');
$image->move($destinationPath, $filename);
DB::update(
'update users set name = ?,email = ?,mobile = ?,image = ?,gender = ?,gst_number=?,aadhar_number=?,password = ?,cpassword = ? where id = ?',
[$fullname, $email, $mobile, $filename, $gender, $gstnumber, $adharnumber, $password, $cpassword, $id]
);
}
else
{
DB::update(
'update users set name = ?,email = ?,mobile = ?,gender = ?,gst_number=?,aadhar_number=?,password = ?,cpassword = ? where id = ?',
[$fullname, $email, $mobile, $gender, $gstnumber, $adharnumber, $password, $cpassword, $id]
);
}
return redirect('/profile');
}
}
you dont need the if else statement
$req->validate([
'email' => 'email|unique:users,email',
'aadhar_number' => 'unique:users,aadhar_number' ,
'gst_number' => 'regex:^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$^|unique:users,gst_number'
// continue your update code here
]);
Simply do this and it will do the needfull for you
if your conditions are not met by the values it will return to the previous view and if the conditions are met, it will continue to run the codes.
for updating the data
$data = user::find(id);
$data->name = $name;
$data->email = $email;
.
.
.
.
//update all the fields
$data->save();
hello i have this function insertion works very well
function add_post(){
$this->form_validation->set_rules('user_id','User Id','trim|required');
//set msg if form validation false
if($this->form_validation->run() == FALSE){
$response = array('status' => FAIL, 'message' => strip_tags(validation_errors()));
$this->response($response);
}
$is_exist = $this->common_model->getsingle(USERS,array('userId'=>$this->post('user_id')));
if($is_exist){
$is_active = $this->common_model->getsingle(USER_COUPON,array('user_id'=>$is_exist->userId,'status'=>1));
$data['user_id'] = $is_exist->userId;
$data['user_coupon_id'] = $is_active->userCouponId;
$data['email'] = $is_exist->email;
$result = $this->common_model->insertData(USER_COUPON_SCAN,$data);
$response = array('status' => SUCCESS, 'message' => "success");
$this->response($response);
}
$response = array('status' => FAIL,'message' =>"No record found please try again");
$this->response($response);
}
the function recovers a single value user_id,I want to get a new value send by post (name admin_id) and isert in user_coupan_scan table
If you are sure that your code is working well, You can receive posted admin_id in following way.
function add_post(){
$this->form_validation->set_rules('user_id','User Id','trim|required');
//set msg if form validation false
if($this->form_validation->run() == FALSE){
$response = array('status' => FAIL, 'message' => strip_tags(validation_errors()));
$this->response($response);
}
$is_exist = $this->common_model->getsingle(USERS,array('userId'=>$this->post('user_id'))); // You may need to change $this->post('user_id') to $this->input->post('user_id')
if($is_exist){
$is_active = $this->common_model->getsingle(USER_COUPON,array('user_id'=>$is_exist->userId,'status'=>1));
$data['admin_id'] = $this->input->post('admin_id'); // make sure that the column name in your table is admin_id
$data['user_id'] = $is_exist->userId;
$data['user_coupon_id'] = $is_active->userCouponId;
$data['email'] = $is_exist->email;
$result = $this->common_model->insertData(USER_COUPON_SCAN,$data);
$response = array('status' => SUCCESS, 'message' => "success");
$this->response($response);
}
$response = array('status' => FAIL,'message' =>"No record found please try again");
$this->response($response);
}
In above answer, I have added one line i.e. receiving admin_id in post data.
$data['column_name_in_your_table'] = $this->input->post('name_in_post_data');
To receive data from post method you can do it like this
$some_name = $this->input-post('name');
Hope it helps.
i am using drupal_validate_form on a node listing page .
it is validating it correctly only for 1st item after that it is not checking validation.
here is my code
foreach($result as $r){
$node_form = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#submit'] = array('#type' => 'submit', '#value' => t('Next'));
$old_fs = #unserialize($r->form_state);
$old_fs['values']['uid'] = $user->uid;
$node = (object) array(
'uid' => $user->uid,
'type' => 'MY_CONTENT_TYPE',
'language' => LANGUAGE_NONE,
);
node_object_prepare($node);
$form_state = array();
$form_state['build_info']['args'] = array($node);
$form_state['values'] = $old_fs['values'];
$form_state['values']['op'] = t('Save');
$form_state['submitted'] = 1;
$form_state['complete form'] = array();
$form_state['triggering_element'] = array('#parents'=>array('next'),'#button_type'=>'submit');
unset($form['#token']);
drupal_validate_form('MY_CONTENT_TYPE_node_form', $form, $form_state);
$errors = form_get_errors();
$noOfError = 'empty';
if (!empty($errors)) {
$noOfError = count($errors);
}
form_clear_error();
}
thank You in advance
Finally i have to reset need_validation in $form .
Because every time form get for validation it will chack $form['#needs_validation'] in _form_validate();
so i added another line after
$form = drupal_get_form('MY_CONTENT_TYPE_node_form',$node_form);
$form['#needs_validation'] = TRUE;
and it will validate every form in that loop
I am at my wits end and don't know why my code is not working . Everything seems good to me .. I have implemented a captcha in my user review function and added a verification method using callback_ .
The captcha is showing in the view and i have dumped the session data and the input field data and they are both working.
The form validation is also working in case of captcha input field but seems like the callback_check_captcha parameter is not working but the function seems fine to me .
Here is my controller
function user_review($id = null , $start = 0){
$check_id = $this->mdl_phone->get_phone_feature($id);
if ($check_id == null ) {
$data['phone_model'] = $this->get_phone_models();
$data['feature'] = null;
$data['title'] = 'Nothing Found';
$data['main_content']= 'phone/error';
echo Modules::run('templates/main',$data);
} else{
$data['phone_model'] = $this->get_phone_models();
$data['success'] = null;
$data['errors'] = null;
if($this->input->server("REQUEST_METHOD") === 'POST' ){
$this->load->library('form_validation');
$this->form_validation->set_rules('text','Review','required|xss_clean');
$this->form_validation->set_rules('captcha', 'Captcha','trim|required|callback_check_captcha');
if($this->form_validation->run() == FALSE){
$data['errors'] = validation_errors();
}else{
$user = $this->ion_auth->user()->row();
$user_id = $user->id;
$data = array(
'phone_id' => $id,
'user_id' => $user_id,
'text' => strip_tags($this->input->post('text')),
);
$this->db->insert('user_review' ,$data);
$data['phone_model'] = $this->get_phone_models();
$data['success'] = 'Your Review has been successfully posted ';
$data['errors']= null;
}
}
// Initilize all Data at once by $id
$data['feature'] = $this->mdl_phone->get_phone_feature($id);
//$data['rating'] = $this->mdl_phone->get_user_rating($id);
$data['user_review'] = $this->mdl_phone->get_user_review($id , 5 , $start);
$this->load->library('pagination');
$config['base_url'] = base_url().'phone/user_review/'.$id;
$config['total_rows'] = $this->mdl_phone->get_user_review_count($id);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$config['anchor_class'] = 'class="page" ';
$this->pagination->initialize($config);
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'img_width' => 150,
'img_height' => 30,
);
$cap = create_captcha($vals);
$this->session->set_userdata('captcha',$cap['word']);
$data['captcha'] = $cap['image'];
$data['title'] = $this->mdl_phone->get_phone_title($id)." User Review , Rating and Popularity";
$data['main_content'] = 'phone/user_review';
echo Modules::run('templates/main',$data);
}
}
function check_captcha($cap)
{
if($this->session->userdata('captcha') == $cap )
{
return true;
}
else{
$this->form_validation->set_message('check_captcha', 'Security number does not match.');
return false;
}
}
The bellow CAPTHA working properly refer this code
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . '/captcha/'
);
$cap = create_captcha($vals);
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$this->session->set_userdata($data);
$data['cap_img'] = $cap['image'];
I think your image url problem or you are not giving a file permission to the captha folder .
In Magento Admin: Under Reports/Shopping Cart/Products in Cart.
I would like to add "Color" attribute column under "Products in Cart" grid. Assuming all products in webshop are configurable products.
i.e; If from Webshop - Customer selects Test Product(configurable product) with Color "Red" option, then this attribute value should be displayed in the report.
Please suggest the best possible way to achieve this!
copy \app\code\core\Mage\Reports\Model\Resource\Quote\Collection.php and paste in app\code\local\Mage\Reports\Model\Resource\Quote\Collection.php
Override public function prepareForProductsInCarts() function
public function prepareForProductsInCarts()
{
$productEntity = Mage::getResourceSingleton('catalog/product_collection');
$productAttrName = $productEntity->getAttribute('name');
$productAttrNameId = (int) $productAttrName->getAttributeId();
$productAttrNameTable = $productAttrName->getBackend()->getTable();
$productAttrPrice = $productEntity->getAttribute('price');
$productAttrPriceId = (int) $productAttrPrice->getAttributeId();
$productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
$ordersSubSelect = clone $this->getSelect();
$ordersSubSelect->reset()
->from(
array('oi' => $this->getTable('sales/order_item')),
array(
'orders' => new Zend_Db_Expr('COUNT(1)'),
'product_id'))
->group('oi.product_id');
$this->getSelect()
->useStraightJoin(true)
->reset(Zend_Db_Select::COLUMNS)
->joinInner(
array('quote_items' => $this->getTable('sales/quote_item')),
'quote_items.quote_id = main_table.entity_id',
null)
->joinInner(
array('e' => $this->getTable('catalog/product')),
'e.entity_id = quote_items.product_id',
null)
->joinInner(
array('product_name' => $productAttrNameTable),
"product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}",
array('name'=>'product_name.value'))
->joinInner(
array('product_price' => $productAttrPriceTable),
"product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
array('price' => new Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')))
->joinLeft(
array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))),
'order_items.product_id = e.entity_id',
array()
)
->columns('e.*')
->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)')))
->columns('order_items.orders')
->where('main_table.is_active = ?', 1)
->group('quote_items.product_id');
return $this;
}
And replace with below function.
public function prepareForProductsInCarts()
{
$productEntity = Mage::getResourceSingleton('catalog/product_collection');
$productAttrName = $productEntity->getAttribute('name');
$productAttrNameId = (int) $productAttrName->getAttributeId();
$productAttrNameTable = $productAttrName->getBackend()->getTable();
$productAttrPrice = $productEntity->getAttribute('price');
$productAttrPriceId = (int) $productAttrPrice->getAttributeId();
$productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
$ordersSubSelect = clone $this->getSelect();
$ordersSubSelect->reset()
->from(
array('oi' => $this->getTable('sales/order_item')),
array(
'orders' => new Zend_Db_Expr('COUNT(1)'),
'product_id'))
->group('oi.product_id');
$this->getSelect()
->useStraightJoin(true)
->reset(Zend_Db_Select::COLUMNS)
->joinInner(
array('quote_items' => $this->getTable('sales/quote_item')),
'quote_items.quote_id = main_table.entity_id',
null)
->joinInner(
array('e' => $this->getTable('catalog/product')),
'e.entity_id = quote_items.product_id',
null)
->joinInner(
array('product_name' => $productAttrNameTable),
"product_name.entity_id = e.entity_id AND product_name.attribute_id = {$productAttrNameId}",
array('name'=>'product_name.value'))
->joinInner(
array('product_price' => $productAttrPriceTable),
"product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
array('price' => new Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')))
### Newly added script ###
->joinLeft(
array('cpei' => 'catalog_product_entity_int'),
'cpei.entity_id = e.entity_id AND cpei.attribute_id = 92',
array()
)
->joinLeft(
array('eaov' => 'eav_attribute_option_value'),
'eaov.option_id = cpei.value',
array('color'=>'eaov.value')
)
### End script ###
->joinLeft(
array('order_items' => new Zend_Db_Expr(sprintf('(%s)', $ordersSubSelect))),
'order_items.product_id = e.entity_id',
array()
)
->columns('e.*')
->columns(array('carts' => new Zend_Db_Expr('COUNT(quote_items.item_id)')))
->columns('order_items.orders')
->where('main_table.is_active = ?', 1)
->group('quote_items.product_id');
return $this;
}
Here cpei.attribute_id = 92 is my "color" attribute id. You can change as per your requirement.
Also put below code in
\app\code\core\Mage\Adminhtml\Block\Report\Shopcart\Product\grid.php file.
$this->addColumn('color', array(
'header' =>Mage::helper('reports')->__('Color'),
'index' =>'color',
Yes we can copy grid.php file from core to local folder.
Works and tested in magento 1.7