Opencart 2x Request multiple rows data - php

I try to make a simple image module. No errors, the only problem is data not saved(maybe)/not loaded everytime I visit this module back. Here's my code in controller:
if (isset($this->request->post['photo_image'])) {
$photo_images = $this->request->post['photo_image'];
} elseif (isset($this->request->get['photo_image'])) {
$photo_images = $this->model_module_photo->getProductImages($this->request->get['photo_image']);
} else {
$photo_images = array();
}
$data['photo_images'] = array();
foreach ($photo_images as $photo_image) {
if (is_file(DIR_IMAGE . $photo_image['image'])) {
$image = $photo_image['image'];
$thumb = $photo_image['image'];
} else {
$image = '';
$thumb = 'no_image.png';
}
$data['photo_images'][] = array(
'image' => $image,
'thumb' => $this->model_tool_image->resize($thumb, 100, 100)
);
}
I'm not sure about isset($this->request->get['photo_image']) code above. Because I took from product images controller. I think I miss on data request. Someone can help me figured it out?
Thanks a lot.

Your code is fine but the problem seems in getting the module (edit module). Make sure you have set correct url for edit link. And also check whether variable photo_image exist in url or not. The url would be like yoursite address/admin/....&photo_image=idOfmodule

Related

JSON is overwriting the old data how to keep on adding data with new ID

so, I am working on a JSON file that should keep on incrementing IDs.
However I get stuck at id:0 and when I insert new data the old data will be replaced by the new one (it keeps id:0).
I am not entirely sure what code is related and what not, so I will post whatever I think should be related and if someone with more knowledge related to JSON could adjust (in case it needs any) it, I would appreciate it a lot.
The include database_json.php contains the following code:
$databaseFile = file_get_contents('json_files/database.json');
$databaseJson = json_decode($databaseFile, true);
$database = $databaseJson['data'];
// below starts a new page, the page that submits the form called saveJson.php
include_once('database_json.php');
$data = $_POST;
//Setup an empty array.
$errors = array();
if (isset($data)) {
$newExerciseData = $data;
$exerciseArray = $data['main_object'];
$databaseFile = 'json_files/database.json';
$textContent = file_get_contents($databaseFile);
$database = json_decode($textContent, true);
if ($data['id'] === 'new') {
if (count($database['data']) == 0) {
$ID = 0;
} else {
$maxID = max($database['data']);
$ID = ++$maxID["id"];
}
$newJsonFile = 'jsonData_' . $ID . '.json';
$newJsonFilePath = 'json_files/' . $newJsonFile;
//Create new database exercise_txt
$newArrayData = array(
'id' => $ID,
// a lot of variables that aren't related to the problem
);
$database['data'][] = $newArrayData;
file_put_contents($databaseFile, json_encode($database, JSON_UNESCAPED_UNICODE, JSON_PRETTY_PRINT));
file_put_contents($newJsonFilePath, json_encode($newExerciseData, JSON_UNESCAPED_UNICODE, JSON_PRETTY_PRINT));
} else {
$index = array_search((int) $_POST['id'], array_column($database['data'], 'id'));
$correctJsonFile = 'json_files/jsonData_' . $_POST['id'] . '.json';
$newJsonFile = 'jsonData_' . $_POST['id'] . '.json';
$newJsonFilePath = 'json_files/' . $newJsonFile;
//Create new database exercise_txt
$newArrayData2 = array(
'id' => (int) $_POST['id'],
// more not related to problem variables
);
$database['data'][$index] = $newArrayData2;
file_put_contents($databaseFile, json_encode($database, JSON_UNESCAPED_UNICODE));
file_put_contents($newJsonFilePath, json_encode($newExerciseData, JSON_UNESCAPED_UNICODE));
}
echo json_encode($newExerciseData, JSON_UNESCAPED_UNICODE);
}
EDIT: someone wanted me to post how the JSON itself looked like... so this is how it looks:
The file is called: database.json
{
"data":
[
{
"id":0,
"exercisetitle":"Test300520180924",
"exerciseWord":["huiswerk"],
"syllables":["Huis","werk"],
"file":"jsonData_.json",
"audio":null,"language":null
}
]
}
(do not mind the audio and language, that's something for later on.
The best I could do was this, yes I read the stuff about making a post and how to properly format stuff etc. but I people would often say I need to include certain code etc etc. and it mostly would turn out messy as hell, so I would rather have a bit too much code (the code I think is related) then not have enough.
Cheers!

Put a variable SESSION in an other variable, delete SESSION content variable

I've an application in PHP 4.3.9 and I've a problem with SESSION.
When I put a variable SESSION in an other variable, like this :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] content is removed.
I don't understand why. Is a PHP4 particularity ?
EDIT
I tried many case to found where exactly I lose my content and this is in a foreach :
reset($tempInsInscription);
foreach($tempInsInscription as $key => $ins_inscription){
if(is_array($ins_inscription)){
reset($ins_inscription);
foreach($ins_inscription as $key_etape => $etape){
$_SESSION["dossier"][$key_etape]=$etape;
}
}else{
$_SESSION["dossier"][$key]=$ins_inscription;
}
}
SOLUTION
I found a solution to solve my problem. here my new code & it's works perfectly :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;
reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
if(is_array($ins_inscription)){
reset($ins_inscription);
while(list($key_etape, $value_etape) = each($ins_inscription)) {
$dossier[$key_etape]=$value_etape;
}
}else{
$dossier[$key]=$ins_inscription;
}
}
SOLUTION
I found a solution to solve my problem. here my new code & it's works perfectly :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;
reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
if(is_array($ins_inscription)){
reset($ins_inscription);
while(list($key_etape, $value_etape) = each($ins_inscription)) {
$dossier[$key_etape]=$value_etape;
}
}else{
$dossier[$key]=$ins_inscription;
}
}

Howto disable/hide Navigation-Tab 'Status' in phpMyAdmin4 multi-user environment

I need to disable the Navigation-Tab 'Status' in a phpMyAdmin4 multi-user environment. This post explains how to do it but it seems as it is for previous versions of phpMyAdmin.
As explained in the above link there should be a file named 'server_links.inc.php'. Under 'usr/share/phpmyadmin/libraries/' there does not exist such file... These are my server_* files:
server_bin_log.lib.php
server_collations.lib.php
server_common.inc.php
server_common.lib.php
server_databases.lib.php
server_engines.lib.php
server_plugins.lib.php
server_privileges.lib.php
server_status.lib.php
server_status_advisor.lib.php
server_status_monitor.lib.php
server_status_queries.lib.php
server_status_variables.lib.php
server_user_groups.lib.php
server_users.lib.php
server_variables.lib.php
In which file is the tab-navigation stored?
How can I disable/hide the 'Status'-Tab?
How can I restrict access for SQL Queries like 'SHOW STATUS' after hiding the 'Status'-Tab?
If you want to change the menu tabs without touching the code, the user groups feature will do just that; see http://docs.phpmyadmin.net/en/latest/config.html?highlight=usergroup#cfg_Servers_usergroups.
You can can also change the code, in libraries/Menu.class.php.
This is my working code for hiding the tab 'Status' in /phpmyadmin/libraries/Menu.class.php:
if ($is_superuser) {
$tabs['status']['icon'] = 's_status.png';
$tabs['status']['link'] = 'server_status.php';
$tabs['status']['text'] = __('Status');
$tabs['status']['active'] = in_array(
basename($GLOBALS['PMA_PHP_SELF']),
array(
'server_status.php',
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php'
)
);
}
This is my working code in /phpmyadmin/server_status.php to deny access anyway if not superuser:
if (!$GLOBALS['dbi']->isSuperuser()) {
$msg = PMA_Message::error(__('No Privileges'));
$msg->display();
exit;
}
Note that the other files belonging to server_status.php should also contain the superuser check, so that no one can access these files directly:
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php'.
for newest phpmyadmin, you can edit at
libraries/classes/menu.php
refer to function _getMenu()
if (strlen((string) $this->_table) > 0) {
$tabs = $this->_getTableTabs();
$url_params['db'] = $this->_db;
$url_params['table'] = $this->_table;
$level = 'table';
} elseif (strlen($this->_db) > 0) {
$tabs = $this->_getDbTabs();
$url_params['db'] = $this->_db;
$level = 'db';
} else {
$tabs = $this->_getServerTabs();
$level = 'server';
}
and then you can modify menu you wanted to, let say edit menu table tabs, then edit function _getTableTabs. eg. you wanted to make menu export hide permanently then comment this code bellow
$tabs['export']['icon'] = 'b_tblexport';
$tabs['export']['link'] = 'tbl_export.php';
$tabs['export']['args']['single_table'] = 'true';
$tabs['export']['text'] = __('Export');
PS. this solution only for permanently hide

How to change the default profile picture (in Wordpress) for users who don't have a Gravatar

I want to replace the default "Mystery Man" profile picture with a different picture.
As you know, you can access someone's Facebook profile picture by going to http://graph.facebook.com//picture (replace with the UID of the requested account.
So what I basically did was adding my theme's function file these few lines:
add_filter( 'avatar_defaults', 'newgravatar' );
function newgravatar ($avatar_defaults) {
$myavatar = 'http://graph.facebook.com/'.get_current_user_id().'/picture';
$avatar_defaults[$myavatar] = "FB Profile Picture";
return $avatar_defaults;
}
The problem is that wordpress doesn't show this URL directly. It stores the picture on WordPress.com's servers. As a result, the picture is always the same picture and doesn't change when a different user logs in.
Is there any way to prevent WordPress from caching the picture on their servers? Or is there any other way to do what I want to do?
If someone has a gmail account with a custom avatar and that email address is used to register it will auto use that avatar. I know this might not be exactly what you're looking for but I thought it was pretty useful to know.
UPDATE:
Found your answer here:
http://buildinternet.com/2009/02/how-to-change-the-default-gravatar-in-wordpress/
I finally managed to fix it by using this filter:
add_filter('get_avatar', 'new_fb_insert_avatar', 1, 5);
function new_fb_insert_avatar($avatar = '', $id_or_email, $size = 96, $default = '', $alt = false) {
$id = 0;
if (is_numeric($id_or_email)) {
$id = $id_or_email;
} else if (is_string($id_or_email)) {
$u = get_user_by('email', $id_or_email);
$id = $u->id;
} else if (is_object($id_or_email)) {
$id = $id_or_email->user_id;
}
if ($id == 0) return $avatar;
$pic = get_user_meta($id, 'fb_profile_picture', true);
if (!$pic || $pic == '') return $avatar;
$avatar = preg_replace('/src=("|\').*?("|\')/i', 'src=\'' . $pic . '\'', $avatar);
return $avatar;
}
the get_user_meta($id, 'fb_profile_picture', true); brings the user's custom avatar picture. Every user has a different picture, and it is stored in his user-meta information.

Multiple save on upload plus save on database errors

I have set of questions have you ever encounter some issues when multiple save on database?my problem is this, i have a database called "album" where fields are 'album_id,album_title,album_user'.
The html output would be there is a login section where there is a input type file where you want to add more and once you have uploaded it. and array of set of names will be stored and that array will be our que to save the file on the multiple format the problem is that. it says and error on the database whichs is sql specified twice.Do you have an idea on how to save in multiple using php?
code will be like this.
<?php
class Album extends olib{
function __construct(){
parent::olib();
}
function upload_submit() {
$allow = array("jpg","png","gif");
$directory = "upload";
$pictures = array();
$counter = 0;
$error = '';
if($this->jpost('upload')) {
for($getupload = 0;$getupload<count($_FILES['uploadpictures']['name']);$getupload++){
$extension = end(explode(".",$_FILES['uploadpictures']['name'][$getupload]));
if(in_array(strtolower($extension),$allow)){
if(move_uploaded_file($_FILES['uploadpictures']['tmp_name'][$getupload],$directory."/".$_FILES['uploadpictures']['name'][$getupload])){
$pictures[$getupload] = $_FILES['uploadpictures']['name'][$getupload];
$counter++;
// $this->save_user_album($_FILES['uploadpictures']['name'][$getupload],$this->setSession('user_id'));
}else{
$error[$getupload] = "Sorry seems some of the data invalid";
}
}else{
$error = '1';
}
}
print_r($pictures);
print_r($error);
foreach($pictures as $urpics){
$this->save_user_album($urpics,$this->setSession('user_id'));
}
}
}
function save_user_album($albumtitle,$session){
$_firewall = ($this->setSession('user_id') !=="") ? $this->setSession('user_id') : "";
$this->jfields('album_pics_title',$albumtitle);
// $this->jfields('album_pics_user',$session);
return $this->jSave('album_pics');
}
}
any response will greatly appreciated!!
Hi I'm sorry seems i have a solution for this i have unset after it has been save..
unset($this->jfields); problem has been solved

Categories