I'm facing a rather strange problem with this..
I'm working on a Yellowpages website using Code Igniter and MySQL. Everything works fine on my local machine, but I face a problem when uploaded to my server.
The only problem being:
When I make change some changes and press the update button, the changes are immediately shown in the view (Have also checked that it gets updates in the Database). However, if I press the 'Edit' button again within say 5-10 seconds the changes are undone.
The most interesting fact being, even if I press update with the old changes...come and check in a few hours. I see the new values again.
I really don't know whats wrong.
Here are my codes :
Controller
function customerList()
{
$data = array();
$data = $this->footer_images();
$this->load->library('pagination');
if($this->session->userdata('user_role') == "Admin" || $this->session->userdata('user_role') == "Employee")
{
if($this->session->userdata('user_role') == "Admin")
$cond = array('enabled' => 1,'approve' => 1);
else if($this->session->userdata('user_role') == "Employee")
$cond = array('enabled' => 1,'approve' => 1,'branch' => $this->session->userdata('branch'));
$config = array();
$config["base_url"] = base_url() . "home/customerList";
$config["total_rows"] = $this->companies->count_entry($cond,"companies");
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$config["num_links"] = 3;
$config["full_tag_open"] = '';
$config["full_tag_close"] = '';
$config["cond"]=$cond;
$this->pagination->initialize($config);
$off=$this->uri->segment(3);
if($off=="" && !isset($_POST['off']))
$off=0;
else if(isset($_POST['off']))
$off=$this->input->post("off");
else
$off=$this->uri->segment(3);
$data["customers"] = $this->companies->get_data_with_cond_page($config["per_page"], $off, $config["cond"]);
$content_data['content'] = $this->load->view("customerList",$data,TRUE);
if($this->session->userdata('user_role') == "Admin")
$this->load->view('masterTemplate/adminTemplate',$content_data);
else if($this->session->userdata('user_role') == "Employee")
$this->load->view('masterTemplate/employeeTemplate',$content_data);
}
else
{
$data['signup_error'] = "OK";
$content_data['content'] = $this->load->view("home",$data,TRUE);
$this->load->view("masterTemplate/template",$content_data);
}
}
function editCompany()
{
$data = array();
$data = $this->footer_images();
$slno = $this->uri->segment(3);
$cond = array('slno' => $slno);
$data['results'] = $this->companies->get_data_with_cond($cond);
$data['category'] = $this->category->get_all_data();
//// $data['subcategory'] = $this->subcategories->get_all_data();
/* $data['makeColumns'] = $this->makeColumns1();
$data['getTotalData'] = $this->getTotalData("category","");
$data['perPage'] = $this->perPage(); */
$data['category'] = $this->category->get_all_data();
if($this->session->userdata('user_role') == "Admin")
{
$this->load->view('template/Admin/header');
$this->load->view("edit_company",$data);
$this->load->view('template/Admin/footer',$data);
}
}
function updateCompany()
{
$this->form_validation->set_rules('company_name', 'Company Name', 'required');
$this->form_validation->set_rules('category', 'Category', 'required');
if ($this->form_validation->run() == FALSE)
{
$sl = $this->input->post('slno');
redirect("home/editCompany/$sl?stat=err");
}
else
{
$data = array(
'company_name' => $this->input->post('company_name'),
'contact_person' => $this->input->post('contact_person'),
'address' => $this->input->post('address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'landmarks' => $this->input->post('landmarks'),
'pincode' => $this->input->post('pincode'),
'std_code' => $this->input->post('std_code'),
'mobile' => $this->input->post('mobile'),
'phone' => $this->input->post('phone'),
'fax' => $this->input->post('fax'),
'cmail' => $this->input->post('cemail'),
'website' => $this->input->post('website'),
'category_name' => $this->input->post('category')
);
$cond = array(
'slno' => $this->input->post('slno')
);
if($this->companies->update_data($cond,$data))
{
redirect("home/customerList?stat=ok");
}
else
{
redirect("home/customerList?stat=nok");
}
}
}
Model
function update_data($cond,$data)
{
$this->db->where($cond)->update('companies',$data);
return true;
}
An early help will be truly appreciated. Thanks! :)
It seems I had a problem with the Page Cache. Once I used the no-cache formula...it worked. Now, Running good too.
Try to press control+f5 to refresh cache after an update
Related
I have a simple question that needs to get an element when selecting that reference ID by an input form. I used the following code to do that.
$id2=$locationProducts[0]->inventory_update_stock_details_id;
But this code outs only the first element always. AS an exmple inventory_update_stock_details_id=36, inventory_update_stock_details_id=36, inventory_update_stock_details_id=36 and so on.
But I needs to select as inventory_update_stock_details_id=35, inventory_update_stock_details_id=345, inventory_update_stock_details_id=2 like that.
inventory_update_stock_details_id included ids as 1,2,3,4,5,......1000
The model as follows :
function getInventoryLocationProducts()
{
$this->db->select("*");
$this->db->from('store_inventory_update_stock_details');
$this->db->join('store_inventory_item', 'store_inventory_item.inventory_item_id=store_inventory_update_stock_details.inventory','left');
$this->db->join('store_inventory_location_update', 'store_inventory_location_update.inventory_update_stock_id=store_inventory_update_stock_details.inventory_update_stock_id','left');
$this->db->join('store_inventory_update_stock', 'store_inventory_update_stock.inventory_update_stock_id=store_inventory_location_update.inventory_update_stock_id','left');
$this->db->where('store_inventory_item.status=1');
$this->db->where('store_inventory_update_stock_details.serial_no NOT IN (select serial_no from store_inventory_location_update)');
$q = $this->db->get_where();
if ($q->num_rows() > 0) {
return $q->result();
}
return FALSE;
}
Controller
public function addInventoryLocation()
{
$this->checkPermissions('add', 'inventoryLocation');
$bc = array(array('link' => '#', 'page' => 'Inventory Locations'));
$meta = array('page_title' => 'Inventory Locations', 'bc' => $bc);
$this->data['branch'] = $this->Item_model->getBranch();
$this->data['office'] = $this->Item_model->getOffice();
$locationProducts = $this->Item_model->getInventoryLocationProducts();
$this->data['locationProducts'] = $locationProducts;
$this->data['auto_loc_no'] = $this->Item_model->generate_inv_loc_ref();
$count = $this->input->post('i');
$str = $this->input->post('auto_loc_no');
$auto_loc = preg_replace("/[^0-9]{1,4}/", '', $str);
$this->form_validation->set_rules('branch', 'Branch', 'required');
if ($this->form_validation->run() == true) {
$stock = array(
'office_id' => $this->input->post('office'),
'branch' => $this->input->post('branch'),
'l_date' => $this->input->post('l_date'),
'is_order_no' => $this->input->post('is_order_no'),
'loc_no' => $this->input->post('auto_loc_no'),
'auto_loc_no' => $auto_loc,
'user' => ucfirst($this->session->userdata('name')),
'order_status' => 'locate',
'status' => 1
);
$id = $this->Item_model->addInventoryLocation($stock);
}
$id2=$locationProducts[0]->inventory_update_stock_details_id;
dd($id2);
if ($this->form_validation->run() == true && $id2 != 0) {
$count = $this->input->post('i');
for ($x = 0; $x <= $count; $x++) {
$details[$x]['inventory_update_stock_id'] = $id2;
$details[$x]['inventory'] = $this->input->post('inventory' . $x);
$details[$x]['serial_no'] = $this->input->post('serial_no' . $x);
$details[$x]['item_code'] = $this->input->post('item_code' . $x);
$details[$x]['officer'] = $this->input->post('officer' . $x);
$details[$x]['qty'] = 1;
$details[$x]['status'] = 1;
$details[$x]['branch'] = $this->input->post('branch');
}
if ($this->Item_model->addInventoryLocationDetails($details)) {
echo("<meta http-equiv='refresh' content='1'>");
$this->session->set_flashdata('message', 'Successfully Added ..!!');
redirect('item/addInventoryLocation');
}
} else {
$this->session->set_flashdata('error', validation_errors());
$this->render('item/addInventoryLocation', $meta, $this->data);
}
}
View
<td style="width: 30%">
<input type="hidden" name="i" id="i" value="0">
<select name="inventory0" id="inventory0" class="form-control select2 inventory-select" required>
<option value=""></option>
<?php
if (!empty($locationProducts)) {
foreach ($locationProducts as $row) {
echo "<option value='".$row->inventory_update_stock_details_id."'> $row->inventory_update_stock_details_id - $row->inventory_item_name</option>";
?>
<?php
}
}
?>
</select>
</td>
What can modify my code line to do that. Can anyone help me ?
I'm not entirely sure what the intended logic is, but I think what you want is to add the InventoryLocationDetails to all InventoryLocationProducts.
If that is correct, you could perhaps do something like this:
if ($this->form_validation->run() == true) {
$details = [];
foreach ($locationProducts as $locationProduct) {
$id2 = $locationProduct->inventory_update_stock_details_id;
$count = $this->input->post('i');
for ($x = 0; $x <= $count; $x++) {
$details[] = [
'inventory_update_stock_id' => $id2,
'inventory' => $this->input->post('inventory' . $x),
'serial_no' => $this->input->post('serial_no' . $x),
'item_code' => $this->input->post('item_code' . $x),
'officer' => $this->input->post('officer' . $x);
'qty' => 1,
'status' => 1,
'branch' => $this->input->post('branch'),
];
}
}
if ($this->Item_model->addInventoryLocationDetails($details)) {
echo("<meta http-equiv='refresh' content='1'>");
$this->session->set_flashdata('message', 'Successfully Added ..!!');
redirect('item/addInventoryLocation');
}
}
This assumes that $locationProducts contains only those products that actually need to be updated. If you need to only update some of them, you can add the logic to determine which product to update inside the foreach loop.
Hello i have restaurant webapp and after i install it all things work there just the openregister thing no ... here is the webapp login details:
user:admin
pass:password
pos.php code
public function openregister($id = 0, $userRole)
{
if ($_POST) {
$cash = $this->input->post('cash');
$id = $this->input->post('store');
$waitersCach = $this->input->post('waitersCach');
$waitercc = '';
foreach ($waitersCach as $key => $value) {
$waitercc .= $value ? $key.','.$value.',' : '';
}
$data = array(
"status" => 1,
"user_id" => $this->session->userdata('user_id'),
"cash_inhand" => $cash,
"waiterscih" => $waitercc,
"store_id" => $id
);
$register = Register::create($data);
$store = Store::find($id);
$store->status = 1;
$store->save();
$CI = & get_instance();
$CI->session->set_userdata('register', $register->id);
$CI->session->set_userdata('store', $id);
redirect("", "location");
}
$open_reg = Register::find('first', array(
'conditions' => array(
'store_id = ? AND status= ?',
$id,
1
)
));
$CI = & get_instance();
$CI->session->set_userdata('register', $open_reg->id);
$CI->session->set_userdata('store', $id);
if($userRole === 'kitchen') {
redirect("kitchens", "location");
}else {
redirect("", "location");
}
}
I tryed findin the error,all things work there just that blank page that i actually dont know why it isnt working i hope somone can find the issue, thank you verymuch
I am using Laravel 5.2 Backpack in my new project where I have a select_from_array field in my form, depending upon the selected value I want data to be displayed in another select_from_array field. Don't know how to do that. Please help me with this. This is my code
Controller.php
public function __construct()
{
if (Request::segment(3) == 'create') {
$parentField1 = [
'name' => 'cat_id',
'label' => 'Category',
'type' => 'select_from_array',
'options' => $this->categories(),
'allows_null' => false,
];
$parentField = [
'name' => 'subCat_id',
'label' => 'SubCategory',
'type' => 'select_from_array',
'options' => $this->subcategories(),
'allows_null' => false,
];
array_unshift($this->crud['fields'], $parentField1,$parentField);
}
public function categories()
{
$cat = Request::get('cat_id');
$currentId = 0;
if (Request::segment(4) == 'edit' and is_numeric(Request::segment(3))) {
$currentId = Request::segment(3);
}
$entries = Category::where('translation_lang', config('app.locale'))->where('parent_id',0)->orderBy('lft')->get();
if (is_null($entries)) {
return [];
}
$tab = [];
$tab[0] = 'Root';
foreach ($entries as $entry) {
if ($entry->id != $currentId) {
$tab[$entry->translation_of] = '- ' . $entry->name;
}
}
return $tab;
}
public function subcategories()
{
$currentId = 0;
if (Request::segment(4) == 'edit' and is_numeric(Request::segment(3))) {
$currentId = Request::segment(3);
}
$entries = Category::where('translation_lang', config('app.locale'))->where('parent_id','!=' ,0)->orderBy('lft')->get();
if (is_null($entries)) {
return [];
}
$tab = [];
$tab[0] = 'Root';
foreach ($entries as $entry) {
if ($entry->id != $currentId) {
$tab[$entry->translation_of] = '- ' . $entry->name;
}
}
return $tab;
}
I want the id of selected option in the subcategories() where I can use the id to get the data.
I think the best way for you is to create a custom field type for this particular purpose, that includes both selects. Follow this procedure. Start from the select2.blade.php file and add the javascript you need to achieve your goal (on change event on first select2, change the options in the next select2).
I am trying to push,delete or update some data into L5 session array.
My code:
$id = $request->input('id');
$type = $request->input('type');
$removeEvent = $request->input('removeEvent');
if($request->session()->has('event')){
$events = $request->session()->get('event');
$request->session()->forget('event'); //forget and create new session
for($i=0; $i<count($events['id']); $i++){
if($events['id'][$i] == $id&& $events['type'][$i] == $type && $removeEvent == 'true'){ //delete
}elseif($events['id'][$i] == $id&& $events['type'][$i] != $type){ //update
$request->session()->push('event.id', $events['id'][$i]);
$request->session()->push('event.type', $type);
}else{
$request->session()->push('event.id', $id);
$request->session()->push('event.type', $type);
}
}
}else{
$request->session()->push('event.id', $id);
$request->session()->push('event.type', $type);
}**
$request->session()->save();
When I am going to post id and type, if id is on session and type is different, I want to update it or removeEvent is true then delete, if it is not on session push it. So, do I have to search whole array or is there any quick way for these actions?
Update:
I did a quick way for this whole code.
$check = $request->session()->has('event.'.$id);
if ($check == 1 && $removeEvent == "true") {
$request->session()->forget('event.'.$id);
} elseif ($check == 1){
$request->session()->put('event.'.$id, $type);
} else {
$request->session()->put('event',
array_add($event= $request->session()->get('event'), $id, $type));
}
This how you can keep all your events in 1 session.
/* I'm using the event ID as keys for easy query.
$events = [
64543 => ['id' => 64543, 'type' => 'A'],
345345 => ['id' => 345345, 'type' => 'B']
];
*/
$id = $request->input('id');
$type = $request->input('type');
$removeEvent = $request->input('removeEvent', false); // false by default
$sessionkey = 'events';
$events = Session::get($sessionkey);
// Remove an event or add/update
if ($removeEvent)
unset($events[$id]);
else
$events[$id] = ['id' => $id, 'type' => $type];
Session::put($key, $events);
I have a form and it's been bugging for a while now, when i have all the information filled up in the forms it seems to insert it very quick, however if one or more fields are empty it doesn't work at all
the query i am using to insert into the database is. i am trying to figure out if i can use Insert_delay and maybe it will solve the problem? any possible solutions or changes i need to do
function student($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect('login', 'refresh');
if ($param1 == 'create') {
$data['name'] = $this->input->post('name');
$data['sex'] = $this->input->post('sex');
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('email');
$data['password'] = $this->input->post('password');
$data['year'] = $this->input->post('year');
$data['rate'] = $this->input->post('rate');
$data['class_id'] = $this->input->post('class_id');
$data['class_id2'] = $this->input->post('class_id2');
$data['class_id3'] = $this->input->post('class_id3');
$data['class_id4'] = $this->input->post('class_id4');
$data['parent_id'] = $this->input->post('parent_id');
$data['roll'] = $this->input->post('roll');
$this->db->insert_('student', $data);
$student_id = $this->db->insert_id();
$this->session->set_flashdata('flash_message' , get_phrase('Student_added_successfully'));
$this->email_model->account_opening_email('student', $data['email']); //SEND EMAIL ACCOUNT OPENING EMAIL
redirect(base_url() . 'index.php?admin/student_add/' . $data['class_id'], 'refresh');
In controller
function student($param1, $param2 $param3 )
{
if ($this->session->userdata('admin_login') != 1)
{
redirect('login', 'refresh');
}
else
{
if($param1 == 'create') {
$result = $this->model_name->insert_data();
if ($result != FALSE) {
$email => $this->input->post('email');
$confirm = $this->email_model->account_opening_email('student', $email); # do same as insert
if ($confirm != FALSE) {
$this->session->set_flashdata('flash_message' , get_phrase('Student_added_successfully'));
redirect(base_url() . 'index.php?admin/student_add/' . $data['class_id'], 'refresh');
}
else
{
echo "Mail send failed";
}
}
else
{
echo "param1 is not create";
}
}
}
}
In Model
public function insert_data()
{
# to isert data, I add them in to one array
$data = array(
'name' => $this->input->post('name'),
'sex' => $this->input->post('sex'),
'address' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'year' => $this->input->post('year'),
'rate' => $this->input->post('rate'),
'class_id' => $this->input->post('class_id'),
'class_id2' => $this->input->post('class_id2'),
'class_id3' => $this->input->post('class_id3'),
'class_id4' => $this->input->post('class_id4'),
'parent_id' => $this->input->post('parent_id'),
'roll' => $this->input->post('roll')
);
if (!$this->db->insert('student', $data)) {
# insert FAILED
return FALSE;
}
else{
# insert SUCCESS
$slast_id = $this->db->insert_id(); # get last insert ID
return = $slast_id;
}
}