Merge branch 'develop' into master
Deploy to Development and Production / deploy (push) Successful in 12s
Details
Deploy to Development and Production / deploy (push) Successful in 12s
Details
This commit is contained in:
commit
473378bf0d
|
|
@ -1,87 +0,0 @@
|
||||||
name: Deploy to Production Server
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set SSH key permissions
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
# Izpis trenutne delovne mape in seznama datotek
|
|
||||||
pwd
|
|
||||||
ls -la
|
|
||||||
|
|
||||||
# Uporabimo SSH ključ iz skrivnosti
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa_gitea
|
|
||||||
chmod 600 ~/.ssh/id_rsa_gitea
|
|
||||||
echo "SSH ključ ustvarjen iz skrivnosti"
|
|
||||||
|
|
||||||
- name: Install rsync
|
|
||||||
shell: bash
|
|
||||||
continue-on-error: true
|
|
||||||
run: |
|
|
||||||
# Najprej preverimo, ali je rsync že nameščen
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "rsync je že nameščen, verzija:"
|
|
||||||
rsync --version | head -n 1
|
|
||||||
else
|
|
||||||
# Če rsync ni nameščen, ga poskušamo namestiti
|
|
||||||
echo "rsync ni nameščen, poskušam namestiti..."
|
|
||||||
if command -v apt-get &> /dev/null; then
|
|
||||||
echo "Poskušam namestiti rsync z apt-get..."
|
|
||||||
sudo apt-get update && sudo apt-get install -y rsync || echo "Ni mogoče namestiti rsync z apt-get"
|
|
||||||
elif command -v yum &> /dev/null; then
|
|
||||||
echo "Poskušam namestiti rsync z yum..."
|
|
||||||
sudo yum install -y rsync || echo "Ni mogoče namestiti rsync z yum"
|
|
||||||
else
|
|
||||||
echo "Ni mogoče namestiti rsync - manjka paketni upravljalnik"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ponovno preverimo, ali je namestitev uspela
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "rsync je uspešno nameščen, verzija:"
|
|
||||||
rsync --version | head -n 1
|
|
||||||
else
|
|
||||||
echo "rsync ni uspešno nameščen, uporabili bomo tar"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vedno vrnemo uspešno kodo za izhod, da korak ne bo označen kot neuspešen
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
- name: Deploy to production server
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
SSH_KEY="~/.ssh/id_rsa_gitea"
|
|
||||||
|
|
||||||
echo "Uporabljam SSH ključ: $SSH_KEY"
|
|
||||||
|
|
||||||
# Testiranje SSH povezave
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "echo 'SSH povezava uspešna'"
|
|
||||||
|
|
||||||
# Izbrišemo obstoječo vsebino v mapi vtičnika v produkcijskem okolju
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "rm -rf public_html/wp-content/plugins/custom_wheel\ 2/*"
|
|
||||||
|
|
||||||
# Poskusimo najprej z rsync, če je nameščen
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "Prenašanje datotek z rsync..."
|
|
||||||
rsync -avz -e "ssh -p 5050 -i $SSH_KEY -o StrictHostKeyChecking=no" --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ forexana@152.89.234.215:public_html/wp-content/plugins/custom_wheel\ 2/
|
|
||||||
else
|
|
||||||
# Alternativna metoda prenosa z uporabo tar preko SSH
|
|
||||||
echo "Prenašanje datotek s tar preko SSH..."
|
|
||||||
tar czf - --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ | ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "tar xzf - -C public_html/wp-content/plugins/custom_wheel\ 2/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Nastavimo pravilna dovoljenja
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "chmod -R 755 public_html/wp-content/plugins/custom_wheel\ 2/"
|
|
||||||
|
|
||||||
echo "Production deployment completed successfully!"
|
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
name: Deploy to Test Server
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- develop
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set SSH key permissions
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
# Izpis trenutne delovne mape in seznama datotek
|
|
||||||
pwd
|
|
||||||
ls -la
|
|
||||||
ls -la .gitea/runner/ || echo "Mapa runner ne obstaja"
|
|
||||||
|
|
||||||
# Poskusimo najti SSH ključ
|
|
||||||
find . -name "id_rsa_gitea*" -type f
|
|
||||||
|
|
||||||
# Uporabimo SSH ključ v bazi repozitorija
|
|
||||||
if [ -f ".gitea/runner/id_rsa_gitea" ]; then
|
|
||||||
chmod 600 .gitea/runner/id_rsa_gitea
|
|
||||||
echo "SSH ključ najden in nastavljen"
|
|
||||||
else
|
|
||||||
echo "SSH ključ ni bil najden na pričakovani lokaciji!"
|
|
||||||
# Ustvarimo SSH ključ iz kodiranega besedila
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa_gitea
|
|
||||||
chmod 600 ~/.ssh/id_rsa_gitea
|
|
||||||
echo "SSH ključ ustvarjen iz skrivnosti"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Install rsync
|
|
||||||
shell: bash
|
|
||||||
continue-on-error: true
|
|
||||||
run: |
|
|
||||||
# Najprej preverimo, ali je rsync že nameščen
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "rsync je že nameščen, verzija:"
|
|
||||||
rsync --version | head -n 1
|
|
||||||
else
|
|
||||||
# Če rsync ni nameščen, ga poskušamo namestiti
|
|
||||||
echo "rsync ni nameščen, poskušam namestiti..."
|
|
||||||
if command -v apt-get &> /dev/null; then
|
|
||||||
echo "Poskušam namestiti rsync z apt-get..."
|
|
||||||
sudo apt-get update && sudo apt-get install -y rsync || echo "Ni mogoče namestiti rsync z apt-get"
|
|
||||||
elif command -v yum &> /dev/null; then
|
|
||||||
echo "Poskušam namestiti rsync z yum..."
|
|
||||||
sudo yum install -y rsync || echo "Ni mogoče namestiti rsync z yum"
|
|
||||||
else
|
|
||||||
echo "Ni mogoče namestiti rsync - manjka paketni upravljalnik"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ponovno preverimo, ali je namestitev uspela
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "rsync je uspešno nameščen, verzija:"
|
|
||||||
rsync --version | head -n 1
|
|
||||||
else
|
|
||||||
echo "rsync ni uspešno nameščen, uporabili bomo tar"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vedno vrnemo uspešno kodo za izhod, da korak ne bo označen kot neuspešen
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
- name: Deploy to test server
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
# Najprej preverimo SSH povezavo
|
|
||||||
if [ -f ".gitea/runner/id_rsa_gitea" ]; then
|
|
||||||
SSH_KEY=".gitea/runner/id_rsa_gitea"
|
|
||||||
else
|
|
||||||
SSH_KEY="~/.ssh/id_rsa_gitea"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Uporabljam SSH ključ: $SSH_KEY"
|
|
||||||
|
|
||||||
# Testiranje SSH povezave
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "echo 'SSH povezava uspešna'"
|
|
||||||
|
|
||||||
# Izbrišemo obstoječo vsebino v mapi vtičnika
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "rm -rf test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/*"
|
|
||||||
|
|
||||||
# Poskusimo najprej z rsync, če je nameščen
|
|
||||||
if command -v rsync &> /dev/null; then
|
|
||||||
echo "Prenašanje datotek z rsync..."
|
|
||||||
rsync -avz -e "ssh -p 5050 -i $SSH_KEY -o StrictHostKeyChecking=no" --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ forexana@152.89.234.215:test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/
|
|
||||||
else
|
|
||||||
# Alternativna metoda prenosa z uporabo tar preko SSH
|
|
||||||
echo "Prenašanje datotek s tar preko SSH..."
|
|
||||||
tar czf - --exclude=".git" --exclude=".gitea" --exclude="id_rsa_gitea*" ./ | ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "tar xzf - -C test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Nastavimo pravilna dovoljenja
|
|
||||||
ssh -p 5050 -i "$SSH_KEY" -o StrictHostKeyChecking=no forexana@152.89.234.215 "chmod -R 755 test.forexanalysis.com/wp-content/plugins/custom_wheel\ 2/"
|
|
||||||
|
|
||||||
echo "Deployment completed successfully!"
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
name: Deploy to Development and Production
|
||||||
|
|
||||||
|
# 1. EN trigger, ki se sproži ob potisku na OBE veji
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
- master
|
||||||
|
|
||||||
|
# 2. EN jobs blok
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# Ta korak se vedno izvede
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Preveri, ali je rsync nameščen, sicer ga namesti
|
||||||
|
- name: Ensure rsync is installed
|
||||||
|
run: |
|
||||||
|
if ! command -v rsync >/dev/null; then
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y rsync
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ta korak se vedno izvede - priprava SSH ključa
|
||||||
|
- name: Setup SSH
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
# 3. KORAK ZA DEVELOP: Izvede se samo, če je veja 'develop'
|
||||||
|
- name: Deploy to Development Server
|
||||||
|
if: gitea.ref_name == 'develop'
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deploying to Development..."
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude=".git/" \
|
||||||
|
--exclude=".gitea/" \
|
||||||
|
--exclude=".gitignore" \
|
||||||
|
-e "ssh -p ${{ secrets.SSH_PORT }} -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no" \
|
||||||
|
./ \
|
||||||
|
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.TARGET_DIR }}
|
||||||
|
|
||||||
|
# 4. KORAK ZA MASTER: Izvede se samo, če je veja 'master'
|
||||||
|
- name: Deploy to Production Server
|
||||||
|
if: gitea.ref_name == 'master'
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deploying to Production..."
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude=".git/" \
|
||||||
|
--exclude=".gitea/" \
|
||||||
|
--exclude=".gitignore" \
|
||||||
|
-e "ssh -p ${{ secrets.SSH_PORT }} -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no" \
|
||||||
|
./ \
|
||||||
|
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.TARGET_MASTER_DIR }}
|
||||||
|
|
@ -41,4 +41,5 @@ vendor/
|
||||||
*.tar
|
*.tar
|
||||||
*.bak
|
*.bak
|
||||||
*.swp
|
*.swp
|
||||||
*.tmp
|
*.tmp
|
||||||
|
code_export.txt
|
||||||
|
|
|
||||||
856
README.md
856
README.md
|
|
@ -1,748 +1,154 @@
|
||||||
# Wheel of Fortune Plugin
|
# Wheel of Fortune za WooCommerce (Kolo Sreče)
|
||||||
|
|
||||||
Test posodobitve za preverjanje Gitea workflow.
|
**Wheel of Fortune** je napreden WordPress/WooCommerce vtičnik, ki omogoča gamifikacijo spletne trgovine. Kupcem omogoča, da z nakupom določenih izdelkov pridobijo "vrtljaje" (spins) in zavrtijo kolo sreče za priboritev nagrad (popusti, kuponi, fizična darila ali sporočila).
|
||||||
|
|
||||||
# Wheel of Fortune - WordPress Plugin
|
Vtičnik podpira več različnih koles, napredno upravljanje verjetnosti, samodejno ustvarjanje WooCommerce kuponov, pošiljanje e-poštnih obvestil (SMTP) in dnevne nagrade (Cron job).
|
||||||
|
|
||||||
Vtičnik "Kolo Sreče" (Wheel of Fortune) omogoča uporabnikom vrtenje kolesa za nagrade. Povezan je z WooCommerce za dodeljevanje spinov ob nakupu izdelkov.
|
## 🚀 Glavne funkcionalnosti
|
||||||
|
|
||||||
## Funkcionalnosti
|
* **Več koles:** Ustvarite lahko neomejeno število različnih koles za različne priložnosti.
|
||||||
|
* **Povezava z WooCommerce:** Določite, kateri izdelki prinašajo vrtljaje in koliko.
|
||||||
|
* **Napredne nagrade:**
|
||||||
|
* Avtomatsko ustvarjanje kuponov za popuste (odstotni popust).
|
||||||
|
* Fizične nagrade.
|
||||||
|
* "Poskusi znova" (Try Again) polja.
|
||||||
|
* Nastavljanje verjetnosti dobitka (uteženo).
|
||||||
|
* **Uporabniški račun:** Beleženje zgodovine vrtljajev in preostalih vrtljajev za vsakega uporabnika.
|
||||||
|
* **Dnevni vrtljaji:** Možnost nastavitve, da vsak uporabnik prejme 1 brezplačen vrtljaj vsakih 24 ur.
|
||||||
|
* **E-poštna obvestila:** Integriran SMTP klient za zanesljivo pošiljanje obvestil o nagradah.
|
||||||
|
* **Diagnostika:** Orodje za testiranje generiranja kuponov in pošiljanja e-pošte.
|
||||||
|
|
||||||
- Prikaz interaktivnega kolesa sreče preko kratke kode [wheel_of_fortune]
|
---
|
||||||
- Povezava z WooCommerce za dodeljevanje spinov ob nakupu izdelkov
|
|
||||||
- Upravljanje z nagradami, verjetnostmi in barvami
|
|
||||||
- Statistika vrtljajev in zadetkov
|
|
||||||
|
|
||||||
## Namestitev
|
## 📂 Struktura map in datotek
|
||||||
|
|
||||||
1. Prenesite datoteke vtičnika v mapo `/wp-content/plugins/wheel-of-fortune/`
|
Spodaj je podroben opis vseh datotek v projektu in njihov namen.
|
||||||
2. Aktivirajte vtičnik preko menija 'Vtičniki' v WordPress skrbniški plošči
|
|
||||||
3. Nastavite vtičnik preko menija 'Kolo sreče' v skrbniški plošči
|
|
||||||
|
|
||||||
## Uporaba
|
### root (koren mape)
|
||||||
|
* **`wheel-of-fortune.php`**:
|
||||||
|
* Glavna datoteka vtičnika.
|
||||||
|
* Inicializira vtičnik, registrira 'hooks' (akcije in filtre).
|
||||||
|
* Ustvari in posodablja podatkovne baze (`dbDelta`).
|
||||||
|
* Registrira REST API endpoint (`/wp-json/wheel-of-fortune/v1/spin`) za varno izvedbo vrtljaja.
|
||||||
|
* Obravnava logiko dodeljevanja spinov ob zaključku WooCommerce naročila (`woocommerce_order_status_completed`).
|
||||||
|
* Vsebuje logiko za pošiljanje e-pošte in generiranje SVG kolesa.
|
||||||
|
|
||||||
### Osnovna uporaba
|
### `/admin` (Administracija)
|
||||||
|
Vsebuje logiko za backend vmesnik v WP Adminu.
|
||||||
|
|
||||||
Vstavite kratko kodo `[wheel_of_fortune]` na katerokoli stran ali prispevek, kjer želite prikazati kolo sreče.
|
* **`coupon-test.php`**:
|
||||||
|
* Diagnostično orodje. Preizkusi 4 različne metode ustvarjanja WooCommerce kuponov (API, programsko, DB insert), da najde tisto, ki deluje na strežniku, in jo shrani kot privzeto.
|
||||||
|
* **`wheels-page.php`**:
|
||||||
|
* Prikazuje seznam vseh ustvarjenih koles.
|
||||||
|
* Omogoča dodajanje novih koles in brisanje obstoječih.
|
||||||
|
* **`edit-wheel-page.php`**:
|
||||||
|
* Glavni urejevalnik za posamezno kolo.
|
||||||
|
* Upravljanje nagrad (CRUD): dodajanje, urejanje, verjetnosti, barve, template e-pošte.
|
||||||
|
* Povezovanje WooCommerce izdelkov s tem kolesom (koliko spinov prinese izdelek).
|
||||||
|
* **`settings-page.php`**:
|
||||||
|
* Globalne nastavitve: SMTP podatki, Cron nastavitve za dnevne spine, "cooldown" čas.
|
||||||
|
* Vsebuje orodja za ročno dodajanje spinov in testiranje e-pošte.
|
||||||
|
* **`stats-page.php`**:
|
||||||
|
* Analitika: Kdo je vrtel, kaj je zadel, kdaj.
|
||||||
|
* Filtriranje uporabnikov glede na preostale spine.
|
||||||
|
* **`users-page.php`**:
|
||||||
|
* Pregled uporabnikov in njihovih spinov.
|
||||||
|
* Možnost ročnega resetiranja ali dodajanja spinov specifičnemu uporabniku.
|
||||||
|
* **`partials/prize-form-fields.php`**:
|
||||||
|
* HTML delček (partial) za obrazec nagrade, ki se uporablja pri dodajanju in urejanju, da se koda ne podvaja.
|
||||||
|
* **`js/admin.js`**:
|
||||||
|
* jQuery skripte za admin vmesnik (odpiranje modalov, AJAX klici za shranjevanje nagrad, testiranje e-pošte).
|
||||||
|
* **`js/wheel.js`** (Admin preview):
|
||||||
|
* Skripta za animacijo kolesa v predogledu v administraciji.
|
||||||
|
|
||||||
### Parametri kratke kode
|
### `/assets` (Sredstva)
|
||||||
|
Datoteke, ki se nalagajo na frontend-u (in delno v adminu za stilizacijo).
|
||||||
|
|
||||||
Kratka koda sprejme naslednje parametre:
|
* **`css/admin.css`**:
|
||||||
|
* Stili za WP Admin (kartice, tabele, gumbi, postavitev urejevalnika).
|
||||||
|
* **`css/wheel.css`**:
|
||||||
|
* CSS za izgled kolesa na spletni strani.
|
||||||
|
* Vsebuje animacije (utripanje lučk), senčenje (SVG filtri) in odzivnost (responsive design) za mobilne naprave.
|
||||||
|
* **`js/wheel.js`**:
|
||||||
|
* **Glavna frontend logika.**
|
||||||
|
* Komunicira z REST API-jem za pridobitev rezultata vrtljaja (rezultat se določi na strežniku, ne v brskalniku zaradi varnosti).
|
||||||
|
* Izvaja animacijo vrtenja (easing functions) in prikaže "popup" z rezultatom.
|
||||||
|
|
||||||
- `size`: Velikost kolesa (možnosti: `small`, `medium`, `large`, privzeto: `medium`)
|
### `/languages`
|
||||||
- `theme`: Tema kolesa (možnosti: `light`, `dark`, privzeto: `light`)
|
* **`wheel-of-fortune.pot`**:
|
||||||
- `scale`: Dodatno prilagajanje velikosti (možnosti: `scale-90`, `scale-80`, `scale-70`, `scale-60`, `scale-50`, privzeto: prazen)
|
* Predloga za prevajanje vtičnika v druge jezike (npr. v slovenščino).
|
||||||
|
|
||||||
#### Primeri
|
### `/public`
|
||||||
|
* **`shortcode-template.php`**:
|
||||||
|
* HTML predloga, ki se izpiše, ko na stran vstavite `[wheel_of_fortune]`. Vsebuje kontejner za SVG kolo in gumb za vrtenje.
|
||||||
|
|
||||||
|
### `/templates`
|
||||||
|
* **`wheel.php`**:
|
||||||
|
* Alternativna ali starejša PHP predloga za generiranje SVG strukture (gradienti, filtri).
|
||||||
|
* **`emails/default-prize-email.html`**:
|
||||||
|
* HTML predloga za e-poštno sporočilo, ki ga prejme uporabnik ob zadetku. Vsebuje "placeholders" kot so `{user_name}`, `{prize_name}`, itd.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗄️ Podatkovna baza
|
||||||
|
|
||||||
|
Vtičnik ustvari naslednje tabele v bazi:
|
||||||
|
1. `wp_wof_wheels`: Seznam koles.
|
||||||
|
2. `wp_wheel_prizes`: Nagrade povezane s kolesi (verjetnost, tip nagrade).
|
||||||
|
3. `wp_wheel_spins`: Stanje spinov za vsakega uporabnika (ločeno po kolesih).
|
||||||
|
4. `wp_wheel_log`: Zgodovina vseh vrtljajev (log).
|
||||||
|
5. `wp_wheel_of_fortune_products`: Povezovalna tabela med WC izdelki in kolesi.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Navodila za uporabo
|
||||||
|
|
||||||
|
### 1. Namestitev in Aktivacija
|
||||||
|
1. Naložite mapo `wheel-of-fortune` v mapo `wp-content/plugins/` ali namestite preko ZIP datoteke v WP Adminu.
|
||||||
|
2. Aktivirajte vtičnik. Ob aktivaciji se bodo ustvarile potrebne tabele.
|
||||||
|
|
||||||
|
### 2. Ustvarjanje Kolesa
|
||||||
|
1. Pojdite na **Wheels of Fortune > Wheels**.
|
||||||
|
2. Vnesite ime kolesa in kliknite "Add New Wheel".
|
||||||
|
3. Kliknite na ime kolesa ali "Edit" za urejanje.
|
||||||
|
|
||||||
|
### 3. Dodajanje Nagrad (Prizes)
|
||||||
|
V urejevalniku kolesa:
|
||||||
|
1. Kliknite "Add New Prize".
|
||||||
|
2. Izpolnite podatke:
|
||||||
|
* **Probability:** Verjetnost med 0 in 1 (npr. 0.1 je 10%). *Pomembno: Vsota vseh verjetnosti naj bo 1.*
|
||||||
|
* **Is Discount?:** Če označite, vpišite odstotek. Sistem bo avtomatsko generiral unikatno kodo kupona.
|
||||||
|
* **Is Try Again?:** Če uporabnik ne zadene ničesar, a lahko vrti ponovno.
|
||||||
|
3. Shranite nagrado.
|
||||||
|
|
||||||
|
### 4. Povezava z Izdelki (Kako do spinov?)
|
||||||
|
Na isti strani urejanja kolesa (spodaj):
|
||||||
|
1. V sekciji "Produkti & spini" izberite WooCommerce izdelek.
|
||||||
|
2. Določite "Število spinov na nakup" (npr. 1).
|
||||||
|
3. Kliknite "Dodaj". Ko kupec kupi ta izdelek (status naročila: Completed/Processing), bo prejel spine.
|
||||||
|
|
||||||
|
### 5. Prikaz na spletni strani
|
||||||
|
Na katerokoli stran ali prispevek dodajte shortcode:
|
||||||
```
|
```
|
||||||
[wheel_of_fortune]
|
[wheel_of_fortune id="1"]
|
||||||
[wheel_of_fortune size="large" theme="dark"]
|
|
||||||
[wheel_of_fortune size="medium" theme="light" scale="scale-80"]
|
|
||||||
```
|
```
|
||||||
|
*Zamenjajte `1` z ID-jem vašega kolesa.*
|
||||||
|
|
||||||
## Vsebina
|
### 6. Nastavitve SMTP in Dnevni Spin
|
||||||
1. [Namen vtičnika](#namen-vtičnika)
|
Pojdite na **Wheels of Fortune > Settings**:
|
||||||
2. [Ključne funkcionalnosti](#ključne-funkcionalnosti)
|
* **SMTP:** Vnesite podatke vašega mail strežnika za zanesljivo dostavo nagrad.
|
||||||
3. [Tehnični opis](#tehnični-opis)
|
* **Daily Spin:** Izberite kolo, ki se uporablja za dnevne nagrade. Uporabniki bodo avtomatsko prejeli 1 spin vsakih 24h za to kolo.
|
||||||
4. [Logika delovanja](#logika-delovanja)
|
* **Coupon Test:** Če se kuponi ne generirajo, zaženite "Testiraj ustvarjanje kuponov" in shranite delujočo metodo.
|
||||||
5. [Administratorske nastavitve](#administratorske-nastavitve)
|
|
||||||
6. [Kratka koda](#kratka-koda)
|
|
||||||
7. [Varnost in integracije](#varnost-in-integracije)
|
|
||||||
8. [Možne razširitve](#možne-razširitve)
|
|
||||||
9. [Implementacija kolesa](#implementacija-kolesa)
|
|
||||||
10. [Namestitev in uporaba](#namestitev-in-uporaba)
|
|
||||||
|
|
||||||
## Namen vtičnika
|
---
|
||||||
|
|
||||||
Vtičnik »Kolo Sreče« omogoča obiskovalcem spletne strani, da zavrtijo interaktivno kolo in prejmejo naključno nagrado. Vrtljaji so vezani na nakupe določenih izdelkov in uporabniške račune, kar omogoča gamificirano izkušnjo zvestobe in nagrajevanja.
|
## ⚠️ Pomembna opozorila
|
||||||
|
|
||||||
## Ključne funkcionalnosti
|
* **DEBUG mode:** V datoteki `wheel-of-fortune.php` je konstanta `WHEEL_OF_FORTUNE_DEBUG` nastavljena na `true`. Za produkcijo jo nastavite na `false`, da ne polnite `debug.log` datoteke.
|
||||||
|
* **Varnost:** Vtičnik uporablja "Nonce" preverjanje za vse AJAX in REST klice, zato je varen pred CSRF napadi.
|
||||||
|
* **Login:** Kolo se prikaže samo prijavljenim uporabnikom. Neprijavljeni vidijo obvestilo za prijavo.
|
||||||
|
|
||||||
- 🎯 Naključni izbor nagrade ob vrtenju kolesa
|
---
|
||||||
- 🔐 Vezava spinov (vrtljajev) na uporabniški račun
|
|
||||||
- 🛒 Samodejna dodelitev spinov ob nakupu določenih izdelkov
|
|
||||||
- 🧠 Nastavljive nagrade in verjetnosti zadetkov
|
|
||||||
- 📊 Spremljanje števila preostalih spinov
|
|
||||||
- 🎛️ Kratka koda za vključitev kolesa kjerkoli v WordPress vsebino
|
|
||||||
- 📬 Email obvestila ob zadetkih (opcijsko)
|
|
||||||
- 📈 Administratorska statistika: število zadetkov, porabljenih spinov ipd.
|
|
||||||
|
|
||||||
## Tehnični opis
|
**Avtor:** Mark Poljansek
|
||||||
|
**Verzija:** 1.0.1
|
||||||
### Arhitektura
|
|
||||||
- WordPress Plugin: zgrajen po WordPress standardih (object-oriented, namespacing, varnostni hooki)
|
|
||||||
- Frontend: JavaScript za animacijo kolesa, AJAX za komunikacijo z backendom
|
|
||||||
- Backend: PHP (WP REST API), povezano z WP uporabniki in WooCommerce naročili
|
|
||||||
- Baza podatkov: uporaba wp_usermeta, lastne tabele wp_wheel_spins in wp_wheel_prizes
|
|
||||||
|
|
||||||
### Tabele podatkovne baze
|
|
||||||
|
|
||||||
#### wp_wheel_spins
|
|
||||||
|
|
||||||
| Polje | Tip | Opis |
|
|
||||||
|-------|-----|------|
|
|
||||||
| id | INT | Primarni ključ |
|
|
||||||
| user_id | INT | ID uporabnika (WordPress) |
|
|
||||||
| spins_available | INT | Število razpoložljivih spinov |
|
|
||||||
| last_spin_date | DATETIME | Datum zadnjega vrtenja |
|
|
||||||
|
|
||||||
#### wp_wheel_prizes
|
|
||||||
|
|
||||||
| Polje | Tip | Opis |
|
|
||||||
|-------|-----|------|
|
|
||||||
| id | INT | Primarni ključ |
|
|
||||||
| name | VARCHAR(255) | Ime nagrade |
|
|
||||||
| description | TEXT | Opis nagrade |
|
|
||||||
| probability | FLOAT | Verjetnost zadetka (0-1) |
|
|
||||||
| color | VARCHAR(20) | Barva segmenta (HEX ali RGB) |
|
|
||||||
| is_active | TINYINT | Ali je nagrada aktivna |
|
|
||||||
| image_url | VARCHAR(255) | URL do slike nagrade (opcijsko) |
|
|
||||||
|
|
||||||
#### wp_wheel_log
|
|
||||||
|
|
||||||
| Polje | Tip | Opis |
|
|
||||||
|-------|-----|------|
|
|
||||||
| id | INT | Primarni ključ |
|
|
||||||
| user_id | INT | ID uporabnika |
|
|
||||||
| prize_id | INT | ID zadete nagrade |
|
|
||||||
| spin_date | DATETIME | Datum in čas vrtenja |
|
|
||||||
| redeemed | TINYINT | Ali je nagrada unovčena |
|
|
||||||
|
|
||||||
## Logika delovanja
|
|
||||||
|
|
||||||
### Podeljevanje spinov
|
|
||||||
|
|
||||||
Ob zaključenem nakupu določenega izdelka (npr. ID = 123), WooCommerce hook (woocommerce_order_status_completed) sproži funkcijo za dodelitev spinov.
|
|
||||||
|
|
||||||
```php
|
|
||||||
function assign_spins_on_purchase($order_id) {
|
|
||||||
$order = wc_get_order($order_id);
|
|
||||||
foreach ($order->get_items() as $item) {
|
|
||||||
$product_id = $item->get_product_id();
|
|
||||||
$spin_products = get_option('wheel_spin_products', array());
|
|
||||||
|
|
||||||
if (array_key_exists($product_id, $spin_products)) {
|
|
||||||
$user_id = $order->get_user_id();
|
|
||||||
$current_spins = get_user_meta($user_id, '_wheel_spins', true) ?: 0;
|
|
||||||
$new_spins = $current_spins + $spin_products[$product_id];
|
|
||||||
update_user_meta($user_id, '_wheel_spins', $new_spins);
|
|
||||||
|
|
||||||
// Posodobi tudi v tabeli wp_wheel_spins
|
|
||||||
global $wpdb;
|
|
||||||
$table_name = $wpdb->prefix . 'wheel_spins';
|
|
||||||
|
|
||||||
$existing = $wpdb->get_var($wpdb->prepare(
|
|
||||||
"SELECT id FROM $table_name WHERE user_id = %d",
|
|
||||||
$user_id
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($existing) {
|
|
||||||
$wpdb->update(
|
|
||||||
$table_name,
|
|
||||||
array('spins_available' => $new_spins),
|
|
||||||
array('user_id' => $user_id)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$wpdb->insert(
|
|
||||||
$table_name,
|
|
||||||
array(
|
|
||||||
'user_id' => $user_id,
|
|
||||||
'spins_available' => $new_spins,
|
|
||||||
'last_spin_date' => current_time('mysql')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('woocommerce_order_status_completed', 'assign_spins_on_purchase');
|
|
||||||
```
|
|
||||||
|
|
||||||
### Vrtenje kolesa
|
|
||||||
|
|
||||||
1. Uporabnik klikne gumb "Zavrti"
|
|
||||||
2. JS animira kolo (CSS transformacija)
|
|
||||||
3. Medtem AJAX zahteva iz strežnika rezultat
|
|
||||||
4. PHP backend izbere nagrado glede na verjetnosti
|
|
||||||
5. Backend zabeleži zadetek, zmanjša število spinov
|
|
||||||
|
|
||||||
```php
|
|
||||||
// REST API endpoint za vrtenje kolesa
|
|
||||||
function spin_wheel_endpoint() {
|
|
||||||
register_rest_route('wheel-of-fortune/v1', '/spin', array(
|
|
||||||
'methods' => 'POST',
|
|
||||||
'callback' => 'process_wheel_spin',
|
|
||||||
'permission_callback' => function() {
|
|
||||||
return is_user_logged_in();
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
|
||||||
add_action('rest_api_init', 'spin_wheel_endpoint');
|
|
||||||
|
|
||||||
function process_wheel_spin($request) {
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
$spins = get_user_meta($user_id, '_wheel_spins', true) ?: 0;
|
|
||||||
|
|
||||||
if ($spins <= 0) {
|
|
||||||
return new WP_Error('no_spins', 'Nimate več razpoložljivih vrtljajev', array('status' => 403));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preveri časovni interval med vrtljaji
|
|
||||||
global $wpdb;
|
|
||||||
$table_name = $wpdb->prefix . 'wheel_spins';
|
|
||||||
$last_spin = $wpdb->get_var($wpdb->prepare(
|
|
||||||
"SELECT last_spin_date FROM $table_name WHERE user_id = %d",
|
|
||||||
$user_id
|
|
||||||
));
|
|
||||||
|
|
||||||
$cooldown_minutes = get_option('wheel_cooldown_minutes', 0);
|
|
||||||
if ($cooldown_minutes > 0 && $last_spin) {
|
|
||||||
$time_diff = (strtotime(current_time('mysql')) - strtotime($last_spin)) / 60;
|
|
||||||
if ($time_diff < $cooldown_minutes) {
|
|
||||||
return new WP_Error(
|
|
||||||
'cooldown',
|
|
||||||
sprintf('Počakajte še %d minut pred naslednjim vrtenjem', ceil($cooldown_minutes - $time_diff)),
|
|
||||||
array('status' => 403)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Izberi nagrado glede na verjetnosti
|
|
||||||
$prize = select_random_prize($prizes);
|
|
||||||
|
|
||||||
// Posodobi število spinov
|
|
||||||
update_user_meta($user_id, '_wheel_spins', $spins - 1);
|
|
||||||
|
|
||||||
// Posodobi tabelo wp_wheel_spins
|
|
||||||
$wpdb->update(
|
|
||||||
$table_name,
|
|
||||||
array(
|
|
||||||
'spins_available' => $spins - 1,
|
|
||||||
'last_spin_date' => current_time('mysql')
|
|
||||||
),
|
|
||||||
array('user_id' => $user_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Zabeleži zadetek
|
|
||||||
$log_table = $wpdb->prefix . 'wheel_log';
|
|
||||||
$wpdb->insert(
|
|
||||||
$log_table,
|
|
||||||
array(
|
|
||||||
'user_id' => $user_id,
|
|
||||||
'prize_id' => $prize['id'],
|
|
||||||
'spin_date' => current_time('mysql'),
|
|
||||||
'redeemed' => 0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Pošlji email obvestilo (če je vključeno)
|
|
||||||
if (get_option('wheel_send_emails', false)) {
|
|
||||||
send_prize_email($user_id, $prize);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'success' => true,
|
|
||||||
'prize' => $prize,
|
|
||||||
'remaining_spins' => $spins - 1,
|
|
||||||
'degree' => calculate_prize_degree($prize['id'], $prizes)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculate_prize_degree($prize_id, $prizes) {
|
|
||||||
// Izračunaj stopinje za animacijo kolesa
|
|
||||||
$prize_index = 0;
|
|
||||||
foreach ($prizes as $index => $prize) {
|
|
||||||
if ($prize['id'] == $prize_id) {
|
|
||||||
$prize_index = $index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$segment_size = 360 / count($prizes);
|
|
||||||
$degree = 360 - ($prize_index * $segment_size + $segment_size / 2);
|
|
||||||
// Dodaj naključno odstopanje znotraj segmenta
|
|
||||||
$degree += mt_rand(-($segment_size / 4), $segment_size / 4);
|
|
||||||
// Dodaj še nekaj obratov
|
|
||||||
$degree += 360 * 5;
|
|
||||||
|
|
||||||
return $degree;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Administratorske nastavitve
|
|
||||||
|
|
||||||
- 📦 Seznam izdelkov, ki podeljujejo spin (ID + št. spinov)
|
|
||||||
- 🎁 Nastavitev nagrad (ime, opis, slika, verjetnost, barva)
|
|
||||||
- 🗳️ Max. spinov na uporabnika
|
|
||||||
- 🕒 Časovna omejitev (1 spin na X minut)
|
|
||||||
- 🔧 Reset spinov / bonus kampanje
|
|
||||||
- 📧 Nastavitve email obvestil
|
|
||||||
|
|
||||||
```php
|
|
||||||
function wheel_admin_menu() {
|
|
||||||
add_menu_page(
|
|
||||||
'Kolo Sreče',
|
|
||||||
'Kolo Sreče',
|
|
||||||
'manage_options',
|
|
||||||
'wheel-of-fortune',
|
|
||||||
'wheel_settings_page',
|
|
||||||
'dashicons-marker',
|
|
||||||
30
|
|
||||||
);
|
|
||||||
|
|
||||||
add_submenu_page(
|
|
||||||
'wheel-of-fortune',
|
|
||||||
'Nastavitve',
|
|
||||||
'Nastavitve',
|
|
||||||
'manage_options',
|
|
||||||
'wheel-of-fortune',
|
|
||||||
'wheel_settings_page'
|
|
||||||
);
|
|
||||||
|
|
||||||
add_submenu_page(
|
|
||||||
'wheel-of-fortune',
|
|
||||||
'Nagrade',
|
|
||||||
'Nagrade',
|
|
||||||
'manage_options',
|
|
||||||
'wheel-prizes',
|
|
||||||
'wheel_prizes_page'
|
|
||||||
);
|
|
||||||
|
|
||||||
add_submenu_page(
|
|
||||||
'wheel-of-fortune',
|
|
||||||
'Statistika',
|
|
||||||
'Statistika',
|
|
||||||
'manage_options',
|
|
||||||
'wheel-stats',
|
|
||||||
'wheel_stats_page'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
add_action('admin_menu', 'wheel_admin_menu');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Kratka koda
|
|
||||||
|
|
||||||
Kolo lahko prikažemo kjerkoli s pomočjo:
|
|
||||||
|
|
||||||
```
|
|
||||||
[wheel_of_fortune]
|
|
||||||
```
|
|
||||||
|
|
||||||
Možne opcije:
|
|
||||||
|
|
||||||
```
|
|
||||||
[wheel_of_fortune size="large" theme="dark"]
|
|
||||||
```
|
|
||||||
|
|
||||||
Implementacija kratke kode:
|
|
||||||
|
|
||||||
```php
|
|
||||||
function wheel_shortcode($atts) {
|
|
||||||
$atts = shortcode_atts(array(
|
|
||||||
'size' => 'medium', // small, medium, large
|
|
||||||
'theme' => 'light', // light, dark
|
|
||||||
), $atts);
|
|
||||||
|
|
||||||
// Preveri, če je uporabnik prijavljen
|
|
||||||
if (!is_user_logged_in()) {
|
|
||||||
return '<div class="wheel-login-required">Za sodelovanje v nagradni igri se morate <a href="' . wp_login_url(get_permalink()) . '">prijaviti</a>.</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Preveri, če ima uporabnik na voljo spine
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
$spins = get_user_meta($user_id, '_wheel_spins', true) ?: 0;
|
|
||||||
|
|
||||||
if ($spins <= 0) {
|
|
||||||
return '<div class="wheel-no-spins">Trenutno nimate razpoložljivih vrtljajev. Kupite izdelke za pridobitev novih vrtljajev.</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Naloži potrebne skripte in stile
|
|
||||||
wp_enqueue_style('wheel-of-fortune-css', plugin_dir_url(__FILE__) . 'assets/css/wheel.css');
|
|
||||||
wp_enqueue_script('wheel-of-fortune-js', plugin_dir_url(__FILE__) . 'assets/js/wheel.js', array('jquery'), '1.0', true);
|
|
||||||
|
|
||||||
wp_localize_script('wheel-of-fortune-js', 'wheelSettings', array(
|
|
||||||
'ajaxUrl' => rest_url('wheel-of-fortune/v1/spin'),
|
|
||||||
'nonce' => wp_create_nonce('wp_rest'),
|
|
||||||
'prizes' => get_wheel_prizes(),
|
|
||||||
'remainingSpins' => $spins
|
|
||||||
));
|
|
||||||
|
|
||||||
// Vrni HTML za kolo
|
|
||||||
ob_start();
|
|
||||||
include plugin_dir_path(__FILE__) . 'templates/wheel.php';
|
|
||||||
return ob_get_clean();
|
|
||||||
}
|
|
||||||
add_shortcode('wheel_of_fortune', 'wheel_shortcode');
|
|
||||||
```
|
|
||||||
|
|
||||||
## Varnost in integracije
|
|
||||||
|
|
||||||
- CSRF zaščita za AJAX klice (WordPress nonce)
|
|
||||||
- Preverjanje uporabniške prijave
|
|
||||||
- Integracija z WooCommerce
|
|
||||||
- Možna integracija z emailing sistemom (npr. MailPoet, Sendinblue)
|
|
||||||
- Preverjanje vlog in pravic uporabnikov
|
|
||||||
- Sanitizacija vnosov in validacija podatkov
|
|
||||||
|
|
||||||
## Možne razširitve
|
|
||||||
|
|
||||||
- 🎟️ Shranjevanje zgodovine zadetkov (WP tabelo wp_wheel_log)
|
|
||||||
- 🏆 Leaderboard: največ zadetkov / spinov
|
|
||||||
- 🔗 Integracija z zvestobnim sistemom (CLIP)
|
|
||||||
- 📱 Mobilna verzija (PWA)
|
|
||||||
- 🔔 Push obvestila za bonus spin
|
|
||||||
- 📊 Napredna analitika in poročila
|
|
||||||
- 🌐 Večjezična podpora
|
|
||||||
|
|
||||||
## Implementacija kolesa
|
|
||||||
|
|
||||||
Glede na priloženo sliko, bo kolo implementirano kot interaktivna SVG ali Canvas komponenta z naslednjimi lastnostmi:
|
|
||||||
|
|
||||||
### Struktura kolesa
|
|
||||||
- Kolo je razdeljeno na več segmentov (8-12)
|
|
||||||
- Vsak segment ima svojo barvo (modra, rdeča, siva)
|
|
||||||
- Segmenti vsebujejo besedilo z nagrado
|
|
||||||
- Kazalec na vrhu označuje zmagovalni segment
|
|
||||||
|
|
||||||
### CSS in JS implementacija
|
|
||||||
|
|
||||||
```css
|
|
||||||
.wheel-container {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 500px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel {
|
|
||||||
width: 100%;
|
|
||||||
height: auto;
|
|
||||||
transform-origin: center;
|
|
||||||
transition: transform 5s cubic-bezier(0.17, 0.67, 0.83, 0.67);
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-pointer {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 50%;
|
|
||||||
transform: translateX(-50%);
|
|
||||||
width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-segment {
|
|
||||||
transform-origin: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-segment-blue {
|
|
||||||
fill: #5DADE2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-segment-red {
|
|
||||||
fill: #E74C3C;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-segment-gray {
|
|
||||||
fill: #D5D8DC;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-text {
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: bold;
|
|
||||||
fill: white;
|
|
||||||
text-anchor: middle;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-button {
|
|
||||||
display: block;
|
|
||||||
margin: 20px auto;
|
|
||||||
padding: 10px 20px;
|
|
||||||
background-color: #E74C3C;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-button:disabled {
|
|
||||||
background-color: #D5D8DC;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-spins-counter {
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-result {
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 20px;
|
|
||||||
padding: 15px;
|
|
||||||
border-radius: 5px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wheel-result.win {
|
|
||||||
background-color: #D5F5E3;
|
|
||||||
border: 1px solid #2ECC71;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
jQuery(document).ready(function($) {
|
|
||||||
var wheel = $('.wheel');
|
|
||||||
var button = $('.wheel-button');
|
|
||||||
var result = $('.wheel-result');
|
|
||||||
var spinning = false;
|
|
||||||
|
|
||||||
button.on('click', function() {
|
|
||||||
if (spinning) return;
|
|
||||||
|
|
||||||
spinning = true;
|
|
||||||
button.prop('disabled', true);
|
|
||||||
result.hide();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: wheelSettings.ajaxUrl,
|
|
||||||
method: 'POST',
|
|
||||||
beforeSend: function(xhr) {
|
|
||||||
xhr.setRequestHeader('X-WP-Nonce', wheelSettings.nonce);
|
|
||||||
},
|
|
||||||
success: function(response) {
|
|
||||||
if (response.success) {
|
|
||||||
// Animiraj kolo
|
|
||||||
wheel.css({
|
|
||||||
'transform': 'rotate(' + response.degree + 'deg)'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Posodobi števec spinov
|
|
||||||
$('.wheel-spins-counter span').text(response.remaining_spins);
|
|
||||||
|
|
||||||
// Prikaži rezultat po končani animaciji
|
|
||||||
setTimeout(function() {
|
|
||||||
result.html('<h3>Čestitamo!</h3><p>Zadeli ste: ' + response.prize.name + '</p>');
|
|
||||||
result.addClass('win').show();
|
|
||||||
spinning = false;
|
|
||||||
|
|
||||||
if (response.remaining_spins > 0) {
|
|
||||||
button.prop('disabled', false);
|
|
||||||
}
|
|
||||||
}, 5500);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(xhr) {
|
|
||||||
var errorMsg = 'Prišlo je do napake.';
|
|
||||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
|
||||||
errorMsg = xhr.responseJSON.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.html('<p>' + errorMsg + '</p>');
|
|
||||||
result.removeClass('win').show();
|
|
||||||
spinning = false;
|
|
||||||
button.prop('disabled', false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### SVG implementacija kolesa
|
|
||||||
|
|
||||||
```php
|
|
||||||
function generate_wheel_svg($prizes) {
|
|
||||||
$num_prizes = count($prizes);
|
|
||||||
$angle = 360 / $num_prizes;
|
|
||||||
$svg = '<svg viewBox="0 0 500 500" class="wheel">';
|
|
||||||
|
|
||||||
// Center point
|
|
||||||
$cx = 250;
|
|
||||||
$cy = 250;
|
|
||||||
$radius = 240;
|
|
||||||
|
|
||||||
// Generate segments
|
|
||||||
for ($i = 0; $i < $num_prizes; $i++) {
|
|
||||||
$prize = $prizes[$i];
|
|
||||||
$start_angle = $i * $angle;
|
|
||||||
$end_angle = ($i + 1) * $angle;
|
|
||||||
|
|
||||||
$start_rad = deg2rad($start_angle);
|
|
||||||
$end_rad = deg2rad($end_angle);
|
|
||||||
|
|
||||||
$x1 = $cx + $radius * cos($start_rad);
|
|
||||||
$y1 = $cy + $radius * sin($start_rad);
|
|
||||||
$x2 = $cx + $radius * cos($end_rad);
|
|
||||||
$y2 = $cy + $radius * sin($end_rad);
|
|
||||||
|
|
||||||
// Determine if the arc should be drawn as a large arc
|
|
||||||
$large_arc = $end_angle - $start_angle > 180 ? 1 : 0;
|
|
||||||
|
|
||||||
// Create the path for the segment
|
|
||||||
$path = "M{$cx},{$cy} L{$x1},{$y1} A{$radius},{$radius} 0 {$large_arc},1 {$x2},{$y2} Z";
|
|
||||||
|
|
||||||
// Determine the color class
|
|
||||||
$color_class = '';
|
|
||||||
switch ($prize['color']) {
|
|
||||||
case 'blue':
|
|
||||||
$color_class = 'wheel-segment-blue';
|
|
||||||
break;
|
|
||||||
case 'red':
|
|
||||||
$color_class = 'wheel-segment-red';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$color_class = 'wheel-segment-gray';
|
|
||||||
}
|
|
||||||
|
|
||||||
$svg .= "<path d='{$path}' class='wheel-segment {$color_class}' />";
|
|
||||||
|
|
||||||
// Add text to the segment
|
|
||||||
$text_angle = $start_angle + ($angle / 2);
|
|
||||||
$text_rad = deg2rad($text_angle);
|
|
||||||
$text_x = $cx + ($radius * 0.75) * cos($text_rad);
|
|
||||||
$text_y = $cy + ($radius * 0.75) * sin($text_rad);
|
|
||||||
|
|
||||||
// Rotate text to be readable
|
|
||||||
$text_rotate = $text_angle;
|
|
||||||
if ($text_angle > 90 && $text_angle < 270) {
|
|
||||||
$text_rotate += 180;
|
|
||||||
}
|
|
||||||
|
|
||||||
$svg .= "<text x='{$text_x}' y='{$text_y}' class='wheel-text' transform='rotate({$text_rotate}, {$text_x}, {$text_y})'>{$prize['name']}</text>";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add center circle
|
|
||||||
$svg .= "<circle cx='{$cx}' cy='{$cy}' r='50' fill='white' />";
|
|
||||||
|
|
||||||
$svg .= '</svg>';
|
|
||||||
return $svg;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Namestitev in uporaba
|
|
||||||
|
|
||||||
### Namestitev vtičnika
|
|
||||||
|
|
||||||
1. Prenesite ZIP datoteko vtičnika
|
|
||||||
2. V WordPress administratorski plošči pojdite na "Vtičniki" > "Dodaj nov"
|
|
||||||
3. Kliknite "Naloži vtičnik" in izberite preneseno ZIP datoteko
|
|
||||||
4. Aktivirajte vtičnik
|
|
||||||
|
|
||||||
### Konfiguracija
|
|
||||||
|
|
||||||
1. V administratorski plošči pojdite na "Kolo Sreče" > "Nastavitve"
|
|
||||||
2. Konfigurirajte izdelke, ki podeljujejo spine
|
|
||||||
3. Nastavite časovne omejitve in druge možnosti
|
|
||||||
|
|
||||||
### Dodajanje nagrad
|
|
||||||
|
|
||||||
1. Pojdite na "Kolo Sreče" > "Nagrade"
|
|
||||||
2. Dodajte nove nagrade z imenom, opisom, verjetnostjo in barvo
|
|
||||||
3. Zagotovite, da skupna vsota verjetnosti ne presega 1.0
|
|
||||||
|
|
||||||
### Prikaz kolesa na strani
|
|
||||||
|
|
||||||
Dodajte kratko kodo `[wheel_of_fortune]` na želeno stran ali prispevek.
|
|
||||||
|
|
||||||
Za prilagoditev videza uporabite dodatne parametre:
|
|
||||||
```
|
|
||||||
[wheel_of_fortune size="large" theme="dark"]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Prilagajanje velikosti kolesa
|
|
||||||
|
|
||||||
Če želite dodatno prilagoditi velikost kolesa, da bo vse prišlo na zaslon, lahko uporabite parameter `scale`:
|
|
||||||
|
|
||||||
- `scale-90`: Zmanjša kolo na 90% privzete velikosti
|
|
||||||
- `scale-80`: Zmanjša kolo na 80% privzete velikosti
|
|
||||||
- `scale-70`: Zmanjša kolo na 70% privzete velikosti
|
|
||||||
- `scale-60`: Zmanjša kolo na 60% privzete velikosti
|
|
||||||
- `scale-50`: Zmanjša kolo na 50% privzete velikosti
|
|
||||||
|
|
||||||
Primer: `[wheel_of_fortune scale="scale-70"]`
|
|
||||||
|
|
||||||
### Dodeljevanje spinov uporabnikom
|
|
||||||
|
|
||||||
Spine lahko uporabnikom dodelite na naslednje načine:
|
|
||||||
|
|
||||||
1. **Avtomatsko ob nakupu**: Nastavite število spinov za posamezne izdelke v nastavitvah vtičnika
|
|
||||||
2. **Ročno**: Uporabite stran "Uporabniki" v meniju "Kolo sreče" za ročno dodeljevanje spinov
|
|
||||||
|
|
||||||
## Nastavitve
|
|
||||||
|
|
||||||
### Splošne nastavitve
|
|
||||||
|
|
||||||
- **Zahtevaj prijavo**: Če je omogočeno, morajo biti uporabniki prijavljeni za vrtenje kolesa
|
|
||||||
- **Dovoli samo en spin na dan**: Če je omogočeno, lahko uporabniki zavrtijo kolo samo enkrat na dan
|
|
||||||
- **Pošlji e-pošto ob zmagi**: Če je omogočeno, se uporabniku pošlje e-pošta ob zmagi
|
|
||||||
|
|
||||||
### Nagrade
|
|
||||||
|
|
||||||
Upravljajte z nagradami, ki jih lahko uporabniki zadanejo:
|
|
||||||
|
|
||||||
- **Ime**: Ime nagrade
|
|
||||||
- **Opis**: Opis nagrade
|
|
||||||
- **Verjetnost**: Verjetnost, da uporabnik zadane to nagrado (v odstotkih)
|
|
||||||
- **Barva**: Barva segmenta na kolesu
|
|
||||||
- **Aktivna**: Ali je nagrada aktivna
|
|
||||||
|
|
||||||
### Izdelki
|
|
||||||
|
|
||||||
Nastavite število spinov, ki jih uporabnik prejme ob nakupu določenih izdelkov:
|
|
||||||
|
|
||||||
1. Vnesite ID izdelka
|
|
||||||
2. Nastavite število spinov
|
|
||||||
3. Kliknite "Dodaj izdelek"
|
|
||||||
|
|
||||||
## Statistika
|
|
||||||
|
|
||||||
Spremljajte statistiko vrtljajev in zadetkov:
|
|
||||||
|
|
||||||
- **Skupno število vrtljajev**: Skupno število vrtljajev vseh uporabnikov
|
|
||||||
- **Zadetki po nagradah**: Število zadetkov za vsako nagrado
|
|
||||||
- **Uporabniki z največ vrtljaji**: Seznam uporabnikov z največ vrtljaji
|
|
||||||
|
|
||||||
## Razvijalcem
|
|
||||||
|
|
||||||
### Filtri
|
|
||||||
|
|
||||||
Vtičnik ponuja naslednje filtre za prilagajanje:
|
|
||||||
|
|
||||||
- `wheel_of_fortune_prizes`: Prilagodite seznam nagrad
|
|
||||||
- `wheel_of_fortune_spin_result`: Prilagodite rezultat vrtljaja
|
|
||||||
- `wheel_of_fortune_email_content`: Prilagodite vsebino e-pošte ob zmagi
|
|
||||||
|
|
||||||
### Akcije
|
|
||||||
|
|
||||||
Vtičnik ponuja naslednje akcije:
|
|
||||||
|
|
||||||
- `wheel_of_fortune_before_spin`: Izvede se pred vrtljajem
|
|
||||||
- `wheel_of_fortune_after_spin`: Izvede se po vrtljaju
|
|
||||||
- `wheel_of_fortune_prize_won`: Izvede se, ko uporabnik zadane nagrado
|
|
||||||
|
|
||||||
## Pogosta vprašanja
|
|
||||||
|
|
||||||
### Kolo se ne prikaže na strani
|
|
||||||
|
|
||||||
Preverite naslednje:
|
|
||||||
|
|
||||||
1. Ali je kratka koda pravilno vstavljena?
|
|
||||||
2. Ali so nagrade nastavljene in aktivne?
|
|
||||||
3. Ali je uporabnik prijavljen (če je to zahtevano)?
|
|
||||||
4. Ali ima uporabnik na voljo spine?
|
|
||||||
5. Poskusite zmanjšati velikost kolesa z uporabo parametra `scale`: `[wheel_of_fortune scale="scale-80"]`
|
|
||||||
|
|
||||||
### Uporabnik ne prejme spinov ob nakupu
|
|
||||||
|
|
||||||
Preverite naslednje:
|
|
||||||
|
|
||||||
1. Ali je WooCommerce aktiviran?
|
|
||||||
2. Ali je izdelek pravilno nastavljen v nastavitvah vtičnika?
|
|
||||||
3. Ali je naročilo označeno kot "Zaključeno"?
|
|
||||||
|
|
||||||
## Podpora
|
|
||||||
|
|
||||||
Za podporo nas kontaktirajte na support@example.com
|
|
||||||
|
|
@ -20,6 +20,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||||
|
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||||
|
|
||||||
if (!empty($name) && $wheel_id > 0) {
|
if (!empty($name) && $wheel_id > 0) {
|
||||||
$result = $wpdb->insert(
|
$result = $wpdb->insert(
|
||||||
|
|
@ -35,8 +36,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
'discount_value' => $discount_value,
|
'discount_value' => $discount_value,
|
||||||
'email_subject' => $email_subject,
|
'email_subject' => $email_subject,
|
||||||
'email_template' => $email_template,
|
'email_template' => $email_template,
|
||||||
|
'is_try_again' => $is_try_again
|
||||||
],
|
],
|
||||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s']
|
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d']
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
|
|
@ -62,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
$discount_value = isset($_POST['prize_discount_value']) ? floatval($_POST['prize_discount_value']) : 0;
|
||||||
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
$email_subject = isset($_POST['prize_email_subject']) ? sanitize_text_field($_POST['prize_email_subject']) : '';
|
||||||
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
$email_template = isset($_POST['prize_email_template']) ? wp_kses_post($_POST['prize_email_template']) : '';
|
||||||
|
$is_try_again = isset($_POST['prize_is_try_again']) ? 1 : 0;
|
||||||
|
|
||||||
if (!empty($name) && $prize_id > 0 && $wheel_id > 0) {
|
if (!empty($name) && $prize_id > 0 && $wheel_id > 0) {
|
||||||
$result = $wpdb->update(
|
$result = $wpdb->update(
|
||||||
|
|
@ -77,9 +80,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
||||||
'discount_value' => $discount_value,
|
'discount_value' => $discount_value,
|
||||||
'email_subject' => $email_subject,
|
'email_subject' => $email_subject,
|
||||||
'email_template' => $email_template,
|
'email_template' => $email_template,
|
||||||
|
'is_try_again' => $is_try_again
|
||||||
],
|
],
|
||||||
['id' => $prize_id],
|
['id' => $prize_id],
|
||||||
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s'],
|
['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%f', '%s', '%s', '%d'],
|
||||||
['%d']
|
['%d']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -231,6 +235,17 @@ if (class_exists('WooCommerce')) {
|
||||||
|
|
||||||
<hr class="wp-header-end">
|
<hr class="wp-header-end">
|
||||||
|
|
||||||
|
<!-- Gumb za migracijo is_try_again stolpca -->
|
||||||
|
<div class="notice notice-info">
|
||||||
|
<p><strong><?php _e('Database Migration', 'wheel-of-fortune'); ?>:</strong>
|
||||||
|
<?php _e('If you encounter "Unknown column is_try_again" error, click the button below to add the missing column to the database.', 'wheel-of-fortune'); ?>
|
||||||
|
<button id="migrate-try-again-btn" class="button button-secondary" style="margin-left: 10px;">
|
||||||
|
<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>
|
||||||
|
</button>
|
||||||
|
<span id="migrate-result" style="margin-left: 10px;"></span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="wheel-card">
|
<div class="wheel-card">
|
||||||
<h2><?php echo esc_html__('Prizes for this Wheel', 'wheel-of-fortune'); ?></h2>
|
<h2><?php echo esc_html__('Prizes for this Wheel', 'wheel-of-fortune'); ?></h2>
|
||||||
|
|
||||||
|
|
@ -359,6 +374,7 @@ if (class_exists('WooCommerce')) {
|
||||||
<tr><th scope="row"><label for="edit-prize-redemption-code"><?php _e('Redemption Code', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-redemption-code" name="prize_redemption_code" class="regular-text"><p class="description"><?php _e('Optional code for the user to redeem the prize.', 'wheel-of-fortune'); ?></p></td></tr>
|
<tr><th scope="row"><label for="edit-prize-redemption-code"><?php _e('Redemption Code', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-redemption-code" name="prize_redemption_code" class="regular-text"><p class="description"><?php _e('Optional code for the user to redeem the prize.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||||
<tr><th scope="row"><label for="edit-prize-is-discount"><?php _e('Is Discount?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-discount" name="prize_is_discount" value="1"><p class="description"><?php _e('Check if the prize is a discount.', 'wheel-of-fortune'); ?></p></td></tr>
|
<tr><th scope="row"><label for="edit-prize-is-discount"><?php _e('Is Discount?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-discount" name="prize_is_discount" value="1"><p class="description"><?php _e('Check if the prize is a discount.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||||
<tr><th scope="row"><label for="edit-prize-discount-value"><?php _e('Discount Value (%)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-discount-value" name="prize_discount_value" step="0.01" min="0" max="100"><p class="description"><?php _e('Enter the discount value in %.', 'wheel-of-fortune'); ?></p></td></tr>
|
<tr><th scope="row"><label for="edit-prize-discount-value"><?php _e('Discount Value (%)', 'wheel-of-fortune'); ?></label></th><td><input type="number" id="edit-prize-discount-value" name="prize_discount_value" step="0.01" min="0" max="100"><p class="description"><?php _e('Enter the discount value in %.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||||
|
<tr><th scope="row"><label for="edit-prize-is-try-again"><?php _e('Is Try Again?', 'wheel-of-fortune'); ?></label></th><td><input type="checkbox" id="edit-prize-is-try-again" name="prize_is_try_again" value="1"><p class="description"><?php _e('Check if the prize is a try again.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||||
<tr><th scope="row"><label for="edit-prize-email-subject"><?php _e('Email Subject', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-email-subject" name="prize_email_subject" class="large-text"><p class="description"><?php _e('Subject for this prize\'s email. If empty, the default subject will be used.', 'wheel-of-fortune'); ?></p></td></tr>
|
<tr><th scope="row"><label for="edit-prize-email-subject"><?php _e('Email Subject', 'wheel-of-fortune'); ?></label></th><td><input type="text" id="edit-prize-email-subject" name="prize_email_subject" class="large-text"><p class="description"><?php _e('Subject for this prize\'s email. If empty, the default subject will be used.', 'wheel-of-fortune'); ?></p></td></tr>
|
||||||
<tr><th scope="row"><label for="edit-prize-email-template"><?php _e('Email Template', 'wheel-of-fortune'); ?></label></th><td><textarea id="edit-prize-email-template" name="prize_email_template" rows="10" class="large-text code"></textarea><p class="description"><?php _e('Available template tags:', 'wheel-of-fortune'); ?> <code>{user_name}</code>, <code>{prize_name}</code>, etc.</p></td></tr>
|
<tr><th scope="row"><label for="edit-prize-email-template"><?php _e('Email Template', 'wheel-of-fortune'); ?></label></th><td><textarea id="edit-prize-email-template" name="prize_email_template" rows="10" class="large-text code"></textarea><p class="description"><?php _e('Available template tags:', 'wheel-of-fortune'); ?> <code>{user_name}</code>, <code>{prize_name}</code>, etc.</p></td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -417,4 +433,41 @@ jQuery(document).ready(function($) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
jQuery(document).ready(function($) {
|
||||||
|
// Gumb za migracijo is_try_again stolpca
|
||||||
|
$('#migrate-try-again-btn').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const button = $(this);
|
||||||
|
const resultSpan = $('#migrate-result');
|
||||||
|
|
||||||
|
button.prop('disabled', true).text('<?php _e('Running migration...', 'wheel-of-fortune'); ?>');
|
||||||
|
resultSpan.html('');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: ajaxurl,
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
action: 'wheel_migrate_try_again',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce('wheel_admin_nonce'); ?>'
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
resultSpan.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
|
||||||
|
button.text('<?php _e('Migration Completed', 'wheel-of-fortune'); ?>').addClass('button-primary');
|
||||||
|
} else {
|
||||||
|
resultSpan.html('<span style="color: red;">✗ ' + (response.data.message || '<?php _e('Migration failed', 'wheel-of-fortune'); ?>') + '</span>');
|
||||||
|
button.prop('disabled', false).text('<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
resultSpan.html('<span style="color: red;">✗ <?php _e('Network error occurred', 'wheel-of-fortune'); ?></span>');
|
||||||
|
button.prop('disabled', false).text('<?php _e('Add is_try_again Column', 'wheel-of-fortune'); ?>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -71,6 +71,7 @@ jQuery(document).ready(function($) {
|
||||||
$('#edit-prize-discount-value').val(prize.discount_value);
|
$('#edit-prize-discount-value').val(prize.discount_value);
|
||||||
$('#edit-prize-email-subject').val(prize.email_subject);
|
$('#edit-prize-email-subject').val(prize.email_subject);
|
||||||
$('#edit-prize-email-template').val(prize.email_template);
|
$('#edit-prize-email-template').val(prize.email_template);
|
||||||
|
$('#edit-prize-is-try-again').prop('checked', parseInt(prize.is_try_again, 10));
|
||||||
|
|
||||||
modal.show();
|
modal.show();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -100,6 +101,7 @@ jQuery(document).ready(function($) {
|
||||||
discount_value: $('#edit-prize-discount-value').val(),
|
discount_value: $('#edit-prize-discount-value').val(),
|
||||||
email_subject: $('#edit-prize-email-subject').val(),
|
email_subject: $('#edit-prize-email-subject').val(),
|
||||||
email_template: $('#edit-prize-email-template').val(),
|
email_template: $('#edit-prize-email-template').val(),
|
||||||
|
is_try_again: $('#edit-prize-is-try-again').is(':checked') ? 1 : 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Debug: preveri wheel_id
|
// Debug: preveri wheel_id
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,11 @@ if (!defined('ABSPATH')) exit;
|
||||||
<input type="number" id="prize_discount_value" name="prize_discount_value" step="0.01" min="0" max="100">
|
<input type="number" id="prize_discount_value" name="prize_discount_value" step="0.01" min="0" max="100">
|
||||||
<p class="description"><?php _e('Vnesi vrednost popusta v %.', 'wheel-of-fortune'); ?></p>
|
<p class="description"><?php _e('Vnesi vrednost popusta v %.', 'wheel-of-fortune'); ?></p>
|
||||||
</td>
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row"><label for="prize_is_try_again"><?php _e('Try Again?', 'wheel-of-fortune'); ?></label></th>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" id="prize_is_try_again" name="prize_is_try_again" value="1">
|
||||||
|
<p class="description"><?php _e('Označi, če je ta nagrada "Try Again" (ponovni poskus).', 'wheel-of-fortune'); ?></p>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -8,6 +8,8 @@ if (!defined('ABSPATH')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
// Preveri, če ima uporabnik pravice za dostop
|
// Preveri, če ima uporabnik pravice za dostop
|
||||||
if (!current_user_can('manage_options')) {
|
if (!current_user_can('manage_options')) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -67,6 +69,10 @@ if (isset($_POST['wheel_save_settings']) && check_admin_referer('wheel_settings_
|
||||||
}
|
}
|
||||||
update_option('wheel_spin_products', $spin_products);
|
update_option('wheel_spin_products', $spin_products);
|
||||||
|
|
||||||
|
// Dnevni spin - shrani izbrano kolo
|
||||||
|
$daily_spin_wheel_id = isset($_POST['wof_daily_spin_wheel_id']) ? intval($_POST['wof_daily_spin_wheel_id']) : '';
|
||||||
|
update_option('wof_daily_spin_wheel_id', $daily_spin_wheel_id);
|
||||||
|
|
||||||
// Prikaži sporočilo o uspehu
|
// Prikaži sporočilo o uspehu
|
||||||
add_settings_error('wheel_settings', 'settings_updated', __('Nastavitve so bile uspešno shranjene.', 'wheel-of-fortune'), 'updated');
|
add_settings_error('wheel_settings', 'settings_updated', __('Nastavitve so bile uspešno shranjene.', 'wheel-of-fortune'), 'updated');
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +85,11 @@ $max_spins = get_option('wheel_max_spins', 0);
|
||||||
$send_emails = get_option('wheel_send_emails', false);
|
$send_emails = get_option('wheel_send_emails', false);
|
||||||
$spin_products = get_option('wheel_spin_products', array());
|
$spin_products = get_option('wheel_spin_products', array());
|
||||||
|
|
||||||
|
// Pridobi vsa kolesa za dropdown
|
||||||
|
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||||
|
$wheels = $wpdb->get_results("SELECT * FROM $wheels_table ORDER BY id ASC", ARRAY_A);
|
||||||
|
$daily_spin_wheel_id = get_option('wof_daily_spin_wheel_id', '');
|
||||||
|
|
||||||
// Prikaži sporočila o napakah/uspehu
|
// Prikaži sporočila o napakah/uspehu
|
||||||
settings_errors('wheel_settings');
|
settings_errors('wheel_settings');
|
||||||
?>
|
?>
|
||||||
|
|
@ -118,6 +129,20 @@ settings_errors('wheel_settings');
|
||||||
<p class="description"><?php echo esc_html__('Maksimalno število spinov, ki jih lahko ima uporabnik. Vrednost 0 pomeni brez omejitve.', 'wheel-of-fortune'); ?></p>
|
<p class="description"><?php echo esc_html__('Maksimalno število spinov, ki jih lahko ima uporabnik. Vrednost 0 pomeni brez omejitve.', 'wheel-of-fortune'); ?></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">
|
||||||
|
<label for="wof_daily_spin_wheel_id"><?php echo esc_html__('Kolo za dnevni spin', 'wheel-of-fortune'); ?></label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<select id="wof_daily_spin_wheel_id" name="wof_daily_spin_wheel_id">
|
||||||
|
<option value=""><?php echo esc_html__('Izberi kolo', 'wheel-of-fortune'); ?></option>
|
||||||
|
<?php foreach ($wheels as $wheel): ?>
|
||||||
|
<option value="<?php echo esc_attr($wheel['id']); ?>" <?php selected($daily_spin_wheel_id, $wheel['id']); ?>><?php echo esc_html($wheel['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<p class="description"><?php echo esc_html__('Vsi registrirani uporabniki bodo vsakih 24 ur prejeli 1 spin na izbranem kolesu.', 'wheel-of-fortune'); ?></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<!-- Možnost za pošiljanje e-pošte je odstranjena, saj se e-pošta pošlje vedno -->
|
<!-- Možnost za pošiljanje e-pošte je odstranjena, saj se e-pošta pošlje vedno -->
|
||||||
<input type="hidden" name="wheel_send_emails" value="1" />
|
<input type="hidden" name="wheel_send_emails" value="1" />
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,41 @@ if (isset($_POST['mark_redeemed']) && isset($_POST['prize_id'])) {
|
||||||
'</p></div>';
|
'</p></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ponastavi spine na 0 za vse uporabnike na izbranem kolesu
|
||||||
|
if (isset($_POST['reset_all_spins_wheel']) && isset($_POST['wheel_id'])) {
|
||||||
|
check_admin_referer('reset_spins_wheel_nonce', 'reset_spins_wheel_nonce');
|
||||||
|
|
||||||
|
$wheel_id = intval($_POST['wheel_id']);
|
||||||
|
|
||||||
|
// Preveri, če kolo obstaja
|
||||||
|
$wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wheels_table WHERE id = %d", $wheel_id));
|
||||||
|
|
||||||
|
if ($wheel_exists) {
|
||||||
|
// Ponastavi spine na 0 za vse uporabnike na tem kolesu
|
||||||
|
$result = $wpdb->update(
|
||||||
|
$spins_table,
|
||||||
|
array('spins_available' => 0),
|
||||||
|
array('wheel_id' => $wheel_id),
|
||||||
|
array('%d'),
|
||||||
|
array('%d')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result !== false) {
|
||||||
|
echo '<div class="notice notice-success is-dismissible"><p>' .
|
||||||
|
sprintf(__('Vsi spini za kolo ID %d so bili uspešno ponastavljeni na 0.', 'wheel-of-fortune'), $wheel_id) .
|
||||||
|
'</p></div>';
|
||||||
|
} else {
|
||||||
|
echo '<div class="notice notice-error is-dismissible"><p>' .
|
||||||
|
__('Prišlo je do napake pri ponastavitvi spinov.', 'wheel-of-fortune') .
|
||||||
|
'</p></div>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '<div class="notice notice-error is-dismissible"><p>' .
|
||||||
|
__('Izbrano kolo ne obstaja.', 'wheel-of-fortune') .
|
||||||
|
'</p></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Izberi uporabnika za podrobnosti
|
// Izberi uporabnika za podrobnosti
|
||||||
$selected_user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
|
$selected_user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
|
||||||
|
|
||||||
|
|
@ -106,6 +141,22 @@ if ($selected_user_id > 0) {
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h1><?php echo esc_html__('Statistika Kolesa Sreče', 'wheel-of-fortune'); ?></h1>
|
<h1><?php echo esc_html__('Statistika Kolesa Sreče', 'wheel-of-fortune'); ?></h1>
|
||||||
|
|
||||||
|
<!-- Gumb za ponastavitev spinov za izbrano kolo -->
|
||||||
|
<div class="notice notice-warning" style="margin: 20px 0;">
|
||||||
|
<p>
|
||||||
|
<strong><?php echo esc_html__('Ponastavitev spinov', 'wheel-of-fortune'); ?>:</strong>
|
||||||
|
<?php echo esc_html__('To dejanje bo ponastavilo vse spine na 0 za vse uporabnike na izbranem kolesu. To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune'); ?>
|
||||||
|
<form method="post" style="display: inline-block; margin-left: 10px;">
|
||||||
|
<?php wp_nonce_field('reset_spins_wheel_nonce', 'reset_spins_wheel_nonce'); ?>
|
||||||
|
<input type="hidden" name="wheel_id" value="<?php echo esc_attr($selected_wheel_id); ?>">
|
||||||
|
<button type="submit" name="reset_all_spins_wheel" class="button button-secondary"
|
||||||
|
onclick="return confirm('<?php echo esc_js(__('Ste prepričani, da želite ponastaviti vse spine na 0 za vse uporabnike na tem kolesu? To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune')); ?>')">
|
||||||
|
<?php echo esc_html__('Ponastavi vse spine na 0 za to kolo', 'wheel-of-fortune'); ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Izbira kolesa -->
|
<!-- Izbira kolesa -->
|
||||||
<div class="tablenav top">
|
<div class="tablenav top">
|
||||||
<div class="alignleft actions">
|
<div class="alignleft actions">
|
||||||
|
|
@ -132,9 +183,45 @@ if ($selected_user_id > 0) {
|
||||||
<br class="clear">
|
<br class="clear">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h2><?php echo sprintf(esc_html__('Seznam uporabnikov s spini za kolo: %s', 'wheel-of-fortune'), esc_html($selected_wheel['name'])); ?></h2>
|
<h2><?php echo sprintf(esc_html__('Seznam uporabnikov s spini za kolo: %s', 'wheel-of-fortune'), esc_html($selected_wheel['name'])); ?></h2>
|
||||||
|
|
||||||
<table class="wp-list-table widefat fixed striped">
|
<!-- Filtriranje uporabnikov -->
|
||||||
|
<div class="user-filters" style="margin: 20px 0; padding: 15px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 5px;">
|
||||||
|
<h4><?php echo esc_html__('Filtriranje uporabnikov', 'wheel-of-fortune'); ?></h4>
|
||||||
|
<div style="display: flex; gap: 15px; align-items: center; flex-wrap: wrap;">
|
||||||
|
<div>
|
||||||
|
<label for="filter-spins"><?php echo esc_html__('Preostali spini:', 'wheel-of-fortune'); ?></label>
|
||||||
|
<select id="filter-spins" style="margin-left: 5px;">
|
||||||
|
<option value=""><?php echo esc_html__('Vsi', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="0"><?php echo esc_html__('0 spinov (porabili)', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="1"><?php echo esc_html__('1 spin', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="2"><?php echo esc_html__('2 spina', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="3"><?php echo esc_html__('3 spini', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="4"><?php echo esc_html__('4 spini', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="5"><?php echo esc_html__('5+ spinov', 'wheel-of-fortune'); ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="filter-total-spins"><?php echo esc_html__('Skupno spinov:', 'wheel-of-fortune'); ?></label>
|
||||||
|
<select id="filter-total-spins" style="margin-left: 5px;">
|
||||||
|
<option value=""><?php echo esc_html__('Vsi', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="0"><?php echo esc_html__('0', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="1"><?php echo esc_html__('1', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="2-5"><?php echo esc_html__('2-5', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="6-10"><?php echo esc_html__('6-10', 'wheel-of-fortune'); ?></option>
|
||||||
|
<option value="11+"><?php echo esc_html__('11+', 'wheel-of-fortune'); ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button type="button" onclick="filterUsers()" class="button button-primary"><?php echo esc_html__('Potrdi filtriranje', 'wheel-of-fortune'); ?></button>
|
||||||
|
<button type="button" onclick="clearFilters()" class="button" style="margin-left: 10px;"><?php echo esc_html__('Počisti filtre', 'wheel-of-fortune'); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="filter-results" style="margin-top: 10px; font-weight: bold; color: #0073aa;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="wp-list-table widefat fixed striped" id="users-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"><?php echo esc_html__('ID', 'wheel-of-fortune'); ?></th>
|
<th scope="col"><?php echo esc_html__('ID', 'wheel-of-fortune'); ?></th>
|
||||||
|
|
@ -254,4 +341,200 @@ if ($selected_user_id > 0) {
|
||||||
<p><?php echo esc_html__('Uporabnik ni bil najden.', 'wheel-of-fortune'); ?></p>
|
<p><?php echo esc_html__('Uporabnik ni bil najden.', 'wheel-of-fortune'); ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Funkcija za filtriranje uporabnikov
|
||||||
|
function filterUsers() {
|
||||||
|
const filterSpins = document.getElementById('filter-spins').value;
|
||||||
|
const filterTotalSpins = document.getElementById('filter-total-spins').value;
|
||||||
|
const table = document.getElementById('users-table');
|
||||||
|
const tbody = table.getElementsByTagName('tbody')[0];
|
||||||
|
|
||||||
|
if (!tbody) {
|
||||||
|
console.error('Tabela ni najdena');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = tbody.getElementsByTagName('tr');
|
||||||
|
let visibleCount = 0;
|
||||||
|
|
||||||
|
console.log('Filtriranje uporabnikov:', { filterSpins, filterTotalSpins, totalRows: rows.length });
|
||||||
|
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const row = rows[i];
|
||||||
|
const cells = row.getElementsByTagName('td');
|
||||||
|
|
||||||
|
if (cells.length < 4) {
|
||||||
|
console.log('Preskočena vrstica (premalo stolpcev):', cells.length);
|
||||||
|
continue; // Preskoči header vrstice ali vrstice brez dovolj stolpcev
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug: prikaži vsebino vseh stolpcev
|
||||||
|
console.log(`Vrstica ${i} stolpci:`, {
|
||||||
|
stolpec0: cells[0] ? cells[0].textContent.trim() : 'N/A',
|
||||||
|
stolpec1: cells[1] ? cells[1].textContent.trim() : 'N/A',
|
||||||
|
stolpec2: cells[2] ? cells[2].textContent.trim() : 'N/A',
|
||||||
|
stolpec3: cells[3] ? cells[3].textContent.trim() : 'N/A',
|
||||||
|
stolpec4: cells[4] ? cells[4].textContent.trim() : 'N/A',
|
||||||
|
stolpec5: cells[5] ? cells[5].textContent.trim() : 'N/A'
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentSpins = parseInt(cells[3].textContent.trim()) || 0; // Preostali spini (4. stolpec)
|
||||||
|
const totalSpins = parseInt(cells[2].textContent.trim()) || 0; // Skupno št. spinov (3. stolpec)
|
||||||
|
|
||||||
|
console.log(`Vrstica ${i}: currentSpins=${currentSpins}, totalSpins=${totalSpins}`);
|
||||||
|
|
||||||
|
let showRow = true;
|
||||||
|
|
||||||
|
// Filtriranje po preostalih spinih
|
||||||
|
if (filterSpins !== '') {
|
||||||
|
if (filterSpins === '0') {
|
||||||
|
showRow = showRow && (currentSpins === 0);
|
||||||
|
} else if (filterSpins === '1') {
|
||||||
|
showRow = showRow && (currentSpins === 1);
|
||||||
|
} else if (filterSpins === '2') {
|
||||||
|
showRow = showRow && (currentSpins === 2);
|
||||||
|
} else if (filterSpins === '3') {
|
||||||
|
showRow = showRow && (currentSpins === 3);
|
||||||
|
} else if (filterSpins === '4') {
|
||||||
|
showRow = showRow && (currentSpins === 4);
|
||||||
|
} else if (filterSpins === '5') {
|
||||||
|
showRow = showRow && (currentSpins >= 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtriranje po skupnem številu spinov
|
||||||
|
if (filterTotalSpins !== '') {
|
||||||
|
if (filterTotalSpins === '0') {
|
||||||
|
showRow = showRow && (totalSpins === 0);
|
||||||
|
} else if (filterTotalSpins === '1') {
|
||||||
|
showRow = showRow && (totalSpins === 1);
|
||||||
|
} else if (filterTotalSpins === '2-5') {
|
||||||
|
showRow = showRow && (totalSpins >= 2 && totalSpins <= 5);
|
||||||
|
} else if (filterTotalSpins === '6-10') {
|
||||||
|
showRow = showRow && (totalSpins >= 6 && totalSpins <= 10);
|
||||||
|
} else if (filterTotalSpins === '11+') {
|
||||||
|
showRow = showRow && (totalSpins >= 11);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prikaži/skrij vrstico
|
||||||
|
if (showRow) {
|
||||||
|
row.style.display = '';
|
||||||
|
visibleCount++;
|
||||||
|
console.log(`Prikazana vrstica ${i}`);
|
||||||
|
} else {
|
||||||
|
row.style.display = 'none';
|
||||||
|
console.log(`Skrita vrstica ${i}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Filtriranje končano: ${visibleCount} od ${rows.length} vrstic prikazanih`);
|
||||||
|
|
||||||
|
// Posodobi števec rezultatov
|
||||||
|
updateFilterResults(visibleCount, rows.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearFilters() {
|
||||||
|
document.getElementById('filter-spins').value = '';
|
||||||
|
document.getElementById('filter-total-spins').value = '';
|
||||||
|
filterUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFilterResults(visible, total) {
|
||||||
|
const resultsDiv = document.getElementById('filter-results');
|
||||||
|
if (visible === total) {
|
||||||
|
resultsDiv.innerHTML = '<?php echo esc_js(__('Prikazani vsi uporabniki:', 'wheel-of-fortune')); ?> ' + total;
|
||||||
|
} else {
|
||||||
|
resultsDiv.innerHTML = '<?php echo esc_js(__('Prikazano:', 'wheel-of-fortune')); ?> ' + visible + ' <?php echo esc_js(__('od', 'wheel-of-fortune')); ?> ' + total + ' <?php echo esc_js(__('uporabnikov', 'wheel-of-fortune')); ?>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testna funkcija za preverjanje strukture tabele
|
||||||
|
function testTableStructure() {
|
||||||
|
const table = document.getElementById('users-table');
|
||||||
|
if (!table) {
|
||||||
|
console.log('Tabela ni najdena!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tbody = table.getElementsByTagName('tbody')[0];
|
||||||
|
if (!tbody) {
|
||||||
|
console.log('Tbody ni najden!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = tbody.getElementsByTagName('tr');
|
||||||
|
console.log(`Najdenih ${rows.length} vrstic v tabeli`);
|
||||||
|
|
||||||
|
if (rows.length > 0) {
|
||||||
|
const firstRow = rows[0];
|
||||||
|
const cells = firstRow.getElementsByTagName('td');
|
||||||
|
console.log(`Prva vrstica ima ${cells.length} stolpcev`);
|
||||||
|
|
||||||
|
for (let i = 0; i < cells.length; i++) {
|
||||||
|
console.log(`Stolpec ${i}: "${cells[i].textContent.trim()}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializiraj števec rezultatov ob nalaganju strani
|
||||||
|
jQuery(document).ready(function($) {
|
||||||
|
// Gumb za ponastavitev spinov preko AJAX
|
||||||
|
$('button[name="reset_all_spins_wheel"]').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const button = $(this);
|
||||||
|
const originalText = button.text();
|
||||||
|
const wheelId = $('input[name="wheel_id"]').val();
|
||||||
|
|
||||||
|
if (!confirm('<?php echo esc_js(__('Ste prepričani, da želite ponastaviti vse spine na 0 za vse uporabnike na tem kolesu? To dejanje ni mogoče razveljaviti.', 'wheel-of-fortune')); ?>')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.prop('disabled', true).text('<?php echo esc_js(__('Ponastavljam spine...', 'wheel-of-fortune')); ?>');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: ajaxurl,
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
action: 'wheel_reset_spins_wheel',
|
||||||
|
wheel_id: wheelId,
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce('wheel_admin_nonce'); ?>'
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
// Prikaži uspešno sporočilo
|
||||||
|
$('<div class="notice notice-success is-dismissible"><p>' + response.data.message + '</p></div>')
|
||||||
|
.insertAfter('h1')
|
||||||
|
.delay(3000)
|
||||||
|
.fadeOut();
|
||||||
|
|
||||||
|
// Osveži stran po 2 sekundah
|
||||||
|
setTimeout(function() {
|
||||||
|
location.reload();
|
||||||
|
}, 2000);
|
||||||
|
} else {
|
||||||
|
alert(response.data.message || '<?php echo esc_js(__('Prišlo je do napake.', 'wheel-of-fortune')); ?>');
|
||||||
|
button.prop('disabled', false).text(originalText);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('<?php echo esc_js(__('Prišlo je do napake pri komunikaciji s strežnikom.', 'wheel-of-fortune')); ?>');
|
||||||
|
button.prop('disabled', false).text(originalText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Posodobi števec rezultatov ob nalaganju strani
|
||||||
|
const table = document.getElementById('users-table');
|
||||||
|
if (table) {
|
||||||
|
const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
||||||
|
updateFilterResults(rows.length, rows.length);
|
||||||
|
|
||||||
|
// Testiraj strukturo tabele
|
||||||
|
testTableStructure();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
@ -128,12 +128,12 @@
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simple gradients for cross-browser compatibility */
|
/* Simple solid fills for segment color classes */
|
||||||
.wheel-segment-yellow { fill: #ffdd00; }
|
.wheel-segment-red { fill: #ff3131; }
|
||||||
.wheel-segment-green { fill: #88ff00; }
|
.wheel-segment-green { fill: #7ed957; }
|
||||||
.wheel-segment-red { fill: #ff5500; }
|
.wheel-segment-purple { fill: #8c52ff; }
|
||||||
.wheel-segment-pink { fill: #ff44aa; }
|
.wheel-segment-orange { fill: #ff914d; }
|
||||||
.wheel-segment-blue { fill: #00ccff; }
|
.wheel-segment-blue { fill: #1da3e7; }
|
||||||
|
|
||||||
/* Divider between segments */
|
/* Divider between segments */
|
||||||
.wheel-divider {
|
.wheel-divider {
|
||||||
|
|
@ -301,7 +301,7 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 20px auto 0 auto;
|
margin: 20px auto 0 auto;
|
||||||
padding: 0 40px;
|
padding: 0 40px !important;
|
||||||
background: linear-gradient(135deg, #ff00c4, #00dfe9);
|
background: linear-gradient(135deg, #ff00c4, #00dfe9);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
@ -316,7 +316,15 @@
|
||||||
height: 56px;
|
height: 56px;
|
||||||
min-width: 140px;
|
min-width: 140px;
|
||||||
letter-spacing: 2px;
|
letter-spacing: 2px;
|
||||||
|
line-height: normal !important;
|
||||||
text-shadow: 0 2px 8px #000, 0 0 10px #0cf101;
|
text-shadow: 0 2px 8px #000, 0 0 10px #0cf101;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prevent accidental <br> tags inside the button from breaking centering */
|
||||||
|
.wheel-button br {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Button hover effect */
|
/* Button hover effect */
|
||||||
|
|
@ -631,4 +639,4 @@
|
||||||
|
|
||||||
.wheel-container.scale-50 {
|
.wheel-container.scale-50 {
|
||||||
transform: scale(0.5);
|
transform: scale(0.5);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,13 @@ jQuery(document).ready(function($) {
|
||||||
|
|
||||||
// Prikaz nagrade
|
// Prikaz nagrade
|
||||||
function showPrizePopup(prize) {
|
function showPrizePopup(prize) {
|
||||||
var html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
var isTryAgain = window.wof_spin_result.is_try_again === 1 || prize.is_try_again === 1;
|
||||||
|
var html = '';
|
||||||
|
if (isTryAgain) {
|
||||||
|
html = '<p><strong>' + prize.name + '</strong></p>';
|
||||||
|
} else {
|
||||||
|
html = '<h3>' + l10n.congratulations + '</h3><p>' + l10n.you_won + ' <strong>' + prize.name + '</strong></p>';
|
||||||
|
}
|
||||||
if (window.wof_spin_result.discount_code) {
|
if (window.wof_spin_result.discount_code) {
|
||||||
html += '<p>' + l10n.discount_code_sent + '</p>';
|
html += '<p>' + l10n.discount_code_sent + '</p>';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6876
code_export.txt
6876
code_export.txt
File diff suppressed because it is too large
Load Diff
|
|
@ -1,26 +1,58 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Set the output file
|
# Nastavitev imena izhodne datoteke
|
||||||
OUTPUT_FILE="code_export.txt"
|
OUTPUT_FILE="code_export.txt"
|
||||||
|
|
||||||
# Remove the output file if it exists
|
# Odstrani izhodno datoteko, če že obstaja, da začnemo s čisto datoteko
|
||||||
if [ -f "$OUTPUT_FILE" ]; then
|
if [ -f "$OUTPUT_FILE" ]; then
|
||||||
rm "$OUTPUT_FILE"
|
rm "$OUTPUT_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Find all files except hidden files and directories
|
# Poišči vse datoteke, razen skritih datotek in določenih map (npr. node_modules).
|
||||||
find . -type f -not -path "*/\.*" -not -path "*node_modules*" -not -path "*vendor*" | sort | while read -r file; do
|
# Dodane so izjeme za slike, videoposnetke, PDF-je, arhive in druge binarne datoteke
|
||||||
# Skip the output file itself and this script
|
# neposredno v ukaz 'find' za boljšo zmogljivost.
|
||||||
|
find . -type f \
|
||||||
|
-not -path "*/\.*" \
|
||||||
|
-not -path "*node_modules*" \
|
||||||
|
-not -path "*vendor*" \
|
||||||
|
-not -path "*dist*" \
|
||||||
|
-not -path "*build*" \
|
||||||
|
-not -path "*/images/*" \
|
||||||
|
-not -iname "*.jpg" -not -iname "*.jpeg" \
|
||||||
|
-not -iname "*.png" -not -iname "*.gif" \
|
||||||
|
-not -iname "*.bmp" -not -iname "*.tiff" \
|
||||||
|
-not -iname "*.svg" -not -iname "*.ico" \
|
||||||
|
-not -iname "*.webp" \
|
||||||
|
-not -iname "*.mp4" -not -iname "*.mov" \
|
||||||
|
-not -iname "*.avi" -not -iname "*.mkv" \
|
||||||
|
-not -iname "*.webm" \
|
||||||
|
-not -iname "*.mp3" -not -iname "*.wav" \
|
||||||
|
-not -iname "*.ogg" -not -iname "*.flac" \
|
||||||
|
-not -iname "*.pdf" \
|
||||||
|
-not -iname "*.zip" \
|
||||||
|
-not -iname "*.tar" \
|
||||||
|
-not -iname "*.gz" \
|
||||||
|
-not -iname "*.bz2" \
|
||||||
|
-not -iname "*.rar" \
|
||||||
|
-not -iname "*.7z" \
|
||||||
|
-not -iname "*.doc" -not -iname "*.docx" \
|
||||||
|
-not -iname "*.xls" -not -iname "*.xlsx" \
|
||||||
|
-not -iname "*.ppt" -not -iname "*.pptx" \
|
||||||
|
-not -iname "*.eot" -not -iname "*.ttf" \
|
||||||
|
-not -iname "*.woff" -not -iname "*.woff2" \
|
||||||
|
| sort | while read -r file; do
|
||||||
|
|
||||||
|
# Preskoči samo izhodno datoteko in to skripto
|
||||||
if [[ "$file" == "./$OUTPUT_FILE" || "$file" == "./export_code.sh" ]]; then
|
if [[ "$file" == "./$OUTPUT_FILE" || "$file" == "./export_code.sh" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Skip binary files and the output file itself
|
# Dodatna varnostna preverba: preskoči slikovne datoteke po MIME tipu
|
||||||
if file "$file" | grep -q "binary"; then
|
if file --mime-type -b "$file" | grep -qiE '^(image)/'; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the filename and content to the output file
|
# Dodaj ime datoteke in njeno vsebino v izhodno datoteko
|
||||||
echo "\"$file\" : " >> "$OUTPUT_FILE"
|
echo "\"$file\" : " >> "$OUTPUT_FILE"
|
||||||
echo "\"\"\"" >> "$OUTPUT_FILE"
|
echo "\"\"\"" >> "$OUTPUT_FILE"
|
||||||
cat "$file" >> "$OUTPUT_FILE"
|
cat "$file" >> "$OUTPUT_FILE"
|
||||||
|
|
@ -29,4 +61,4 @@ find . -type f -not -path "*/\.*" -not -path "*node_modules*" -not -path "*vendo
|
||||||
echo "" >> "$OUTPUT_FILE"
|
echo "" >> "$OUTPUT_FILE"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Code export completed. Output saved to $OUTPUT_FILE"
|
echo "Izvoz kode končan. Vsebina je shranjena v datoteko $OUTPUT_FILE"
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,12 @@ class WheelOfFortune {
|
||||||
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
||||||
register_activation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'activate'));
|
register_activation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'activate'));
|
||||||
register_deactivation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'deactivate'));
|
register_deactivation_hook(WHEEL_OF_FORTUNE_PLUGIN_FILE, array($this, 'deactivate'));
|
||||||
|
|
||||||
|
// --- CRON: filter in akcija vedno aktivna ---
|
||||||
|
add_filter('cron_schedules', array($this, 'add_custom_cron_schedules'));
|
||||||
|
add_action('wof_daily_spin_event', array($this, 'execute_daily_spin_cron'));
|
||||||
|
// ------------------------------------------
|
||||||
|
|
||||||
add_action('admin_menu', array($this, 'admin_menu'));
|
add_action('admin_menu', array($this, 'admin_menu'));
|
||||||
add_action('rest_api_init', array($this, 'register_rest_routes'));
|
add_action('rest_api_init', array($this, 'register_rest_routes'));
|
||||||
add_shortcode('wheel_of_fortune', array($this, 'shortcode'));
|
add_shortcode('wheel_of_fortune', array($this, 'shortcode'));
|
||||||
|
|
@ -125,8 +131,10 @@ class WheelOfFortune {
|
||||||
add_action('wp_ajax_wheel_get_product', array($this, 'ajax_get_product'));
|
add_action('wp_ajax_wheel_get_product', array($this, 'ajax_get_product'));
|
||||||
add_action('wp_ajax_wheel_test_email', array($this, 'ajax_test_email'));
|
add_action('wp_ajax_wheel_test_email', array($this, 'ajax_test_email'));
|
||||||
add_action('wp_ajax_wheel_get_prizes', array($this, 'ajax_get_prizes'));
|
add_action('wp_ajax_wheel_get_prizes', array($this, 'ajax_get_prizes'));
|
||||||
|
add_action('wp_ajax_ajax_update_wheel_product_spins', array($this, 'ajax_update_wheel_product_spins'));
|
||||||
add_action('wp_ajax_wof_delete_wheel_product', array($this, 'ajax_delete_wheel_product'));
|
add_action('wp_ajax_wof_delete_wheel_product', array($this, 'ajax_delete_wheel_product'));
|
||||||
add_action('wp_ajax_wof_update_wheel_product_spins', array($this, 'ajax_update_wheel_product_spins'));
|
add_action('wp_ajax_wheel_migrate_try_again', array($this, 'ajax_migrate_try_again'));
|
||||||
|
add_action('wp_ajax_wheel_reset_spins_wheel', array($this, 'ajax_reset_spins_wheel'));
|
||||||
|
|
||||||
// Vključi testno skripto za kupone
|
// Vključi testno skripto za kupone
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
|
|
@ -226,35 +234,22 @@ class WheelOfFortune {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function activate() {
|
public function activate() {
|
||||||
error_log("Wheel of Fortune: Aktivacija plugina...");
|
|
||||||
$this->create_database_tables();
|
$this->create_database_tables();
|
||||||
$this->run_migration();
|
$this->run_migration();
|
||||||
$this->set_default_options();
|
$this->set_default_options();
|
||||||
$this->add_default_prizes();
|
|
||||||
|
|
||||||
// Debug: Preveri, ali se tabela za kolesa ustvari
|
// Dodaj cron opravilo za dnevne spine
|
||||||
global $wpdb;
|
if (!wp_next_scheduled('wheel_daily_spins_cron')) {
|
||||||
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
wp_schedule_event(time(), 'wheel_daily', 'wheel_daily_spins_cron');
|
||||||
$wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products';
|
|
||||||
|
|
||||||
$wheels_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheels_table'") == $wheels_table;
|
|
||||||
$products_exists = $wpdb->get_var("SHOW TABLES LIKE '$wheel_products_table'") == $wheel_products_table;
|
|
||||||
|
|
||||||
error_log("=== ACTIVATION DEBUG ===");
|
|
||||||
error_log("Wheels table exists: " . ($wheels_exists ? 'YES' : 'NO'));
|
|
||||||
error_log("Products table exists: " . ($products_exists ? 'YES' : 'NO'));
|
|
||||||
|
|
||||||
if (!$wheels_exists) {
|
|
||||||
error_log('Wheel of Fortune: Wheels table was not created properly during activation.');
|
|
||||||
} else {
|
|
||||||
error_log('Wheel of Fortune: Wheels table created successfully.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_rewrite_rules();
|
// Izvedi migracijo za is_try_again stolpec
|
||||||
error_log("Wheel of Fortune: Aktivacija končana.");
|
$this->migrate_add_is_try_again_column();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deactivate() {
|
public function deactivate() {
|
||||||
|
wp_clear_scheduled_hook('wof_daily_spin_event');
|
||||||
|
error_log("Wheel of Fortune: Cron job 'wof_daily_spin_event' cleared.");
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,6 +321,7 @@ class WheelOfFortune {
|
||||||
redemption_code varchar(100) DEFAULT '',
|
redemption_code varchar(100) DEFAULT '',
|
||||||
is_discount tinyint(1) NOT NULL DEFAULT 0,
|
is_discount tinyint(1) NOT NULL DEFAULT 0,
|
||||||
discount_value float DEFAULT 0,
|
discount_value float DEFAULT 0,
|
||||||
|
is_try_again tinyint(1) NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
KEY wheel_id (wheel_id)
|
KEY wheel_id (wheel_id)
|
||||||
) $charset_collate;";
|
) $charset_collate;";
|
||||||
|
|
@ -385,6 +381,29 @@ class WheelOfFortune {
|
||||||
} else {
|
} else {
|
||||||
error_log("Wheel of Fortune: Tabela $wheel_products_table uspešno ustvarjena.");
|
error_log("Wheel of Fortune: Tabela $wheel_products_table uspešno ustvarjena.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migracija: dodaj stolpec is_try_again v obstoječe tabele
|
||||||
|
$this->migrate_add_is_try_again_column();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function migrate_add_is_try_again_column() {
|
||||||
|
global $wpdb;
|
||||||
|
$table_prizes = $wpdb->prefix . 'wheel_prizes';
|
||||||
|
|
||||||
|
// Preveri, če stolpec is_try_again že obstaja
|
||||||
|
$column_exists = $wpdb->get_results("SHOW COLUMNS FROM $table_prizes LIKE 'is_try_again'");
|
||||||
|
|
||||||
|
if (empty($column_exists)) {
|
||||||
|
// Dodaj stolpec is_try_again
|
||||||
|
$result = $wpdb->query("ALTER TABLE $table_prizes ADD COLUMN is_try_again tinyint(1) NOT NULL DEFAULT 0");
|
||||||
|
if ($result !== false) {
|
||||||
|
error_log("Wheel of Fortune: Stolpec is_try_again uspešno dodan v tabelo $table_prizes");
|
||||||
|
} else {
|
||||||
|
error_log("Wheel of Fortune: Napaka pri dodajanju stolpca is_try_again v tabelo $table_prizes");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error_log("Wheel of Fortune: Stolpec is_try_again že obstaja v tabeli $table_prizes");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function run_migration() {
|
private function run_migration() {
|
||||||
|
|
@ -537,11 +556,26 @@ class WheelOfFortune {
|
||||||
array($this, 'edit_wheel_page')
|
array($this, 'edit_wheel_page')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Dodam podstran za nastavitve
|
||||||
|
add_submenu_page(
|
||||||
|
'wof-wheels',
|
||||||
|
__('Settings', 'wheel-of-fortune'),
|
||||||
|
__('Settings', 'wheel-of-fortune'),
|
||||||
|
'manage_options',
|
||||||
|
'wof-settings',
|
||||||
|
array($this, 'settings_page')
|
||||||
|
);
|
||||||
|
|
||||||
// Statistika in uporabniki
|
// Statistika in uporabniki
|
||||||
add_submenu_page('wof-wheels', __('Statistics', 'wheel-of-fortune'), __('Statistics', 'wheel-of-fortune'), 'manage_options', 'wof-stats', array($this, 'stats_page'));
|
add_submenu_page('wof-wheels', __('Statistics', 'wheel-of-fortune'), __('Statistics', 'wheel-of-fortune'), 'manage_options', 'wof-stats', array($this, 'stats_page'));
|
||||||
add_submenu_page('wof-wheels', __('Users & Spins', 'wheel-of-fortune'), __('Users & Spins', 'wheel-of-fortune'), 'manage_options', 'wof-users', array($this, 'users_page'));
|
add_submenu_page('wof-wheels', __('Users & Spins', 'wheel-of-fortune'), __('Users & Spins', 'wheel-of-fortune'), 'manage_options', 'wof-users', array($this, 'users_page'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dodam funkcijo za prikaz strani z nastavitvami
|
||||||
|
public function settings_page() {
|
||||||
|
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/settings-page.php';
|
||||||
|
}
|
||||||
|
|
||||||
public function wheels_page() {
|
public function wheels_page() {
|
||||||
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/wheels-page.php';
|
require_once WHEEL_OF_FORTUNE_PLUGIN_DIR . 'admin/wheels-page.php';
|
||||||
}
|
}
|
||||||
|
|
@ -621,11 +655,18 @@ class WheelOfFortune {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_option('wheel_send_emails', true)) {
|
// Pošlji email samo, če ni "try again" nagrada
|
||||||
|
if (get_option('wheel_send_emails', true) && (!isset($prize['is_try_again']) || $prize['is_try_again'] != 1)) {
|
||||||
$this->send_prize_email($user_id, $prize);
|
$this->send_prize_email($user_id, $prize);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response_data = [ 'prize' => $prize, 'degree' => $degree, 'remaining_spins' => $new_spins, 'discount_code' => $redemption_code ];
|
$response_data = [
|
||||||
|
'prize' => $prize,
|
||||||
|
'degree' => $degree,
|
||||||
|
'remaining_spins' => $new_spins,
|
||||||
|
'discount_code' => $redemption_code,
|
||||||
|
'is_try_again' => isset($prize['is_try_again']) ? (int)$prize['is_try_again'] : 0
|
||||||
|
];
|
||||||
|
|
||||||
return new WP_REST_Response(['success' => true, 'data' => $response_data], 200);
|
return new WP_REST_Response(['success' => true, 'data' => $response_data], 200);
|
||||||
}
|
}
|
||||||
|
|
@ -830,7 +871,8 @@ class WheelOfFortune {
|
||||||
$text_paths = '';
|
$text_paths = '';
|
||||||
|
|
||||||
// Generate segments and text paths
|
// Generate segments and text paths
|
||||||
$segment_colors = ['#00dfe9', '#ff00c4', '#0cf101'];
|
// Updated segment color palette
|
||||||
|
$segment_colors = ['#ff3131', '#7ed957', '#8c52ff', '#ff914d', '#1da3e7'];
|
||||||
for ($i = 0; $i < $num_prizes; $i++) {
|
for ($i = 0; $i < $num_prizes; $i++) {
|
||||||
$prize = $prizes[$i];
|
$prize = $prizes[$i];
|
||||||
$start_angle = $i * $angle;
|
$start_angle = $i * $angle;
|
||||||
|
|
@ -936,6 +978,7 @@ class WheelOfFortune {
|
||||||
$email_subject = isset($_POST['email_subject']) ? sanitize_text_field($_POST['email_subject']) : '';
|
$email_subject = isset($_POST['email_subject']) ? sanitize_text_field($_POST['email_subject']) : '';
|
||||||
$email_template = isset($_POST['email_template']) ? wp_kses_post($_POST['email_template']) : '';
|
$email_template = isset($_POST['email_template']) ? wp_kses_post($_POST['email_template']) : '';
|
||||||
$discount_value = isset($_POST['discount_value']) ? floatval($_POST['discount_value']) : 0;
|
$discount_value = isset($_POST['discount_value']) ? floatval($_POST['discount_value']) : 0;
|
||||||
|
$is_try_again = isset($_POST['is_try_again']) ? intval($_POST['is_try_again']) : 0;
|
||||||
|
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
wp_send_json_error(['message' => __('Prize name is required.', 'wheel-of-fortune')]);
|
wp_send_json_error(['message' => __('Prize name is required.', 'wheel-of-fortune')]);
|
||||||
|
|
@ -963,9 +1006,10 @@ class WheelOfFortune {
|
||||||
'email_subject' => $email_subject,
|
'email_subject' => $email_subject,
|
||||||
'email_template' => $email_template,
|
'email_template' => $email_template,
|
||||||
'discount_value' => $discount_value,
|
'discount_value' => $discount_value,
|
||||||
|
'is_try_again' => $is_try_again,
|
||||||
];
|
];
|
||||||
|
|
||||||
$format = ['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%s', '%s', '%f'];
|
$format = ['%d', '%s', '%s', '%f', '%d', '%s', '%d', '%s', '%s', '%f', '%d'];
|
||||||
|
|
||||||
if ($prize_id > 0) {
|
if ($prize_id > 0) {
|
||||||
$result = $wpdb->update($table_name, $data, ['id' => $prize_id], $format, ['%d']);
|
$result = $wpdb->update($table_name, $data, ['id' => $prize_id], $format, ['%d']);
|
||||||
|
|
@ -1270,7 +1314,8 @@ class WheelOfFortune {
|
||||||
update_post_meta($coupon_id, 'usage_limit_per_user', '1');
|
update_post_meta($coupon_id, 'usage_limit_per_user', '1');
|
||||||
update_post_meta($coupon_id, 'customer_email', array($user->user_email));
|
update_post_meta($coupon_id, 'customer_email', array($user->user_email));
|
||||||
update_post_meta($coupon_id, 'description', __('Wheel of Fortune', 'wheel-of-fortune'));
|
update_post_meta($coupon_id, 'description', __('Wheel of Fortune', 'wheel-of-fortune'));
|
||||||
|
// Nastavi veljavnost 10 dni
|
||||||
|
update_post_meta($coupon_id, 'date_expires', strtotime('+10 days'));
|
||||||
return $coupon_id;
|
return $coupon_id;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
@ -1298,12 +1343,9 @@ class WheelOfFortune {
|
||||||
$coupon->set_usage_limit(1);
|
$coupon->set_usage_limit(1);
|
||||||
$coupon->set_usage_limit_per_user(1);
|
$coupon->set_usage_limit_per_user(1);
|
||||||
$coupon->set_email_restrictions(array($user->user_email));
|
$coupon->set_email_restrictions(array($user->user_email));
|
||||||
|
// Nastavi veljavnost 10 dni
|
||||||
// Dodatna nastavitev
|
$coupon->set_date_expires(strtotime('+10 days'));
|
||||||
$coupon->set_date_expires(strtotime('+30 days'));
|
|
||||||
|
|
||||||
$coupon_id = $coupon->save();
|
$coupon_id = $coupon->save();
|
||||||
|
|
||||||
// Preveri, ali je kupon res ustvarjen
|
// Preveri, ali je kupon res ustvarjen
|
||||||
if ($coupon_id) {
|
if ($coupon_id) {
|
||||||
$verification_id = wc_get_coupon_id_by_code($code);
|
$verification_id = wc_get_coupon_id_by_code($code);
|
||||||
|
|
@ -1320,7 +1362,6 @@ class WheelOfFortune {
|
||||||
// Metoda 4: Neposredno vstavljanje v podatkovno bazo
|
// Metoda 4: Neposredno vstavljanje v podatkovno bazo
|
||||||
try {
|
try {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// Ustvari nov post tipa shop_coupon
|
// Ustvari nov post tipa shop_coupon
|
||||||
$wpdb->insert(
|
$wpdb->insert(
|
||||||
$wpdb->posts,
|
$wpdb->posts,
|
||||||
|
|
@ -1335,9 +1376,7 @@ class WheelOfFortune {
|
||||||
'post_date_gmt' => current_time('mysql', 1)
|
'post_date_gmt' => current_time('mysql', 1)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$coupon_id = $wpdb->insert_id;
|
$coupon_id = $wpdb->insert_id;
|
||||||
|
|
||||||
if ($coupon_id) {
|
if ($coupon_id) {
|
||||||
// Dodaj meta podatke za kupon
|
// Dodaj meta podatke za kupon
|
||||||
$meta_data = array(
|
$meta_data = array(
|
||||||
|
|
@ -1347,9 +1386,10 @@ class WheelOfFortune {
|
||||||
'usage_limit' => '1',
|
'usage_limit' => '1',
|
||||||
'usage_limit_per_user' => '1',
|
'usage_limit_per_user' => '1',
|
||||||
'customer_email' => serialize(array($user->user_email)),
|
'customer_email' => serialize(array($user->user_email)),
|
||||||
'description' => __('Wheel of Fortune', 'wheel-of-fortune')
|
'description' => __('Wheel of Fortune', 'wheel-of-fortune'),
|
||||||
|
// Nastavi veljavnost 10 dni
|
||||||
|
'date_expires' => strtotime('+10 days')
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($meta_data as $meta_key => $meta_value) {
|
foreach ($meta_data as $meta_key => $meta_value) {
|
||||||
$wpdb->insert(
|
$wpdb->insert(
|
||||||
$wpdb->postmeta,
|
$wpdb->postmeta,
|
||||||
|
|
@ -1360,7 +1400,6 @@ class WheelOfFortune {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $coupon_id;
|
return $coupon_id;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
@ -1381,8 +1420,9 @@ class WheelOfFortune {
|
||||||
$coupon->set_usage_limit(1);
|
$coupon->set_usage_limit(1);
|
||||||
$coupon->set_usage_limit_per_user(1);
|
$coupon->set_usage_limit_per_user(1);
|
||||||
$coupon->set_email_restrictions(array($user->user_email));
|
$coupon->set_email_restrictions(array($user->user_email));
|
||||||
|
// Nastavi veljavnost 10 dni
|
||||||
|
$coupon->set_date_expires(strtotime('+10 days'));
|
||||||
$coupon_id = $coupon->save();
|
$coupon_id = $coupon->save();
|
||||||
|
|
||||||
if ($coupon_id) {
|
if ($coupon_id) {
|
||||||
return $coupon_id;
|
return $coupon_id;
|
||||||
}
|
}
|
||||||
|
|
@ -1403,6 +1443,12 @@ class WheelOfFortune {
|
||||||
* @param array $prize The prize details array.
|
* @param array $prize The prize details array.
|
||||||
*/
|
*/
|
||||||
public function send_prize_email($user_id, $prize) {
|
public function send_prize_email($user_id, $prize) {
|
||||||
|
// Ne pošlji emaila, če je nagrada "try again"
|
||||||
|
if (isset($prize['is_try_again']) && $prize['is_try_again'] == 1) {
|
||||||
|
wheel_of_fortune_debug_log("send_prize_email: Email ni poslan za 'try again' nagrado: {$prize['name']}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$user = get_userdata($user_id);
|
$user = get_userdata($user_id);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
wheel_of_fortune_debug_log("send_prize_email: Uporabnik z ID {$user_id} ni bil najden.");
|
wheel_of_fortune_debug_log("send_prize_email: Uporabnik z ID {$user_id} ni bil najden.");
|
||||||
|
|
@ -1524,33 +1570,123 @@ class WheelOfFortune {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajax_delete_wheel_product() {
|
public function ajax_delete_wheel_product() {
|
||||||
check_ajax_referer('wof_delete_wheel_product');
|
check_ajax_referer('wof_delete_wheel_product', '_ajax_nonce');
|
||||||
|
|
||||||
if (!current_user_can('manage_options')) {
|
if (!current_user_can('manage_options')) {
|
||||||
wp_send_json_error(__('Nimaš dovoljenja.', 'wheel-of-fortune'));
|
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||||
}
|
}
|
||||||
global $wpdb;
|
|
||||||
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
||||||
|
|
||||||
// Debug informacije
|
if (!$id) {
|
||||||
error_log("=== AJAX DELETE WHEEL PRODUCT DEBUG ===");
|
wp_send_json_error(['message' => __('Invalid ID.', 'wheel-of-fortune')]);
|
||||||
error_log("POST data: " . print_r($_POST, true));
|
}
|
||||||
error_log("ID to delete: " . $id);
|
|
||||||
|
|
||||||
if ($id > 0) {
|
global $wpdb;
|
||||||
$table = $wpdb->prefix . 'wheel_of_fortune_products';
|
$table_name = $wpdb->prefix . 'wheel_of_fortune_products';
|
||||||
error_log("Table: " . $table);
|
|
||||||
|
$result = $wpdb->delete($table_name, ['id' => $id]);
|
||||||
$result = $wpdb->delete($table, ['id' => $id], ['%d']);
|
|
||||||
error_log("Delete result: " . $result);
|
if ($result !== false) {
|
||||||
error_log("Last SQL query: " . $wpdb->last_query);
|
wp_send_json_success(['message' => __('Product deleted successfully.', 'wheel-of-fortune')]);
|
||||||
error_log("Last SQL error: " . $wpdb->last_error);
|
} else {
|
||||||
|
wp_send_json_error(['message' => __('Failed to delete product.', 'wheel-of-fortune')]);
|
||||||
if ($result !== false) {
|
}
|
||||||
wp_send_json_success();
|
}
|
||||||
|
|
||||||
|
public function ajax_migrate_try_again() {
|
||||||
|
check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
|
||||||
|
|
||||||
|
if (!current_user_can('manage_options')) {
|
||||||
|
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->migrate_add_is_try_again_column();
|
||||||
|
|
||||||
|
wp_send_json_success(['message' => __('Migration completed successfully. The is_try_again column has been added to the database.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajax_reset_spins_wheel() {
|
||||||
|
check_ajax_referer('wheel_admin_nonce', '_ajax_nonce');
|
||||||
|
|
||||||
|
if (!current_user_can('manage_options')) {
|
||||||
|
wp_send_json_error(['message' => __('You do not have permission to perform this action.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$wheel_id = isset($_POST['wheel_id']) ? intval($_POST['wheel_id']) : 0;
|
||||||
|
|
||||||
|
if (!$wheel_id) {
|
||||||
|
wp_send_json_error(['message' => __('Wheel ID is required.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
$wheels_table = $wpdb->prefix . 'wof_wheels';
|
||||||
|
$spins_table = $wpdb->prefix . 'wheel_spins';
|
||||||
|
|
||||||
|
// Preveri, če kolo obstaja
|
||||||
|
$wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $wheels_table WHERE id = %d", $wheel_id));
|
||||||
|
|
||||||
|
if (!$wheel_exists) {
|
||||||
|
wp_send_json_error(['message' => __('Selected wheel does not exist.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ponastavi spine na 0 za vse uporabnike na tem kolesu
|
||||||
|
$result = $wpdb->update(
|
||||||
|
$spins_table,
|
||||||
|
array('spins_available' => 0),
|
||||||
|
array('wheel_id' => $wheel_id),
|
||||||
|
array('%d'),
|
||||||
|
array('%d')
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result !== false) {
|
||||||
|
wp_send_json_success([
|
||||||
|
'message' => sprintf(__('All spins for wheel ID %d have been successfully reset to 0.', 'wheel-of-fortune'), $wheel_id),
|
||||||
|
'affected_users' => $result
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
wp_send_json_error(['message' => __('An error occurred while resetting spins.', 'wheel-of-fortune')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- NOVE METODE ZA CRON ---
|
||||||
|
public function add_custom_cron_schedules($schedules) {
|
||||||
|
// Lahko pustiš custom interval, če ga uporabljaš še kje drugje, sicer ni potreben
|
||||||
|
// $schedules['every_2_minutes'] = array(
|
||||||
|
// 'interval' => 120,
|
||||||
|
// 'display' => __('Every 2 minutes', 'wheel-of-fortune')
|
||||||
|
// );
|
||||||
|
return $schedules;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute_daily_spin_cron() {
|
||||||
|
wheel_of_fortune_debug_log('CRON: "wof_daily_spin_event" triggered.');
|
||||||
|
$wheel_id = get_option('wof_daily_spin_wheel_id');
|
||||||
|
if (empty($wheel_id)) {
|
||||||
|
wheel_of_fortune_debug_log('CRON: No wheel selected for daily spin. Aborting.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$users = get_users(array('fields' => 'ID'));
|
||||||
|
wheel_of_fortune_debug_log('CRON: Found ' . count($users) . ' users to process for wheel ID ' . $wheel_id);
|
||||||
|
foreach ($users as $user_id) {
|
||||||
|
$last_given_meta_key = '_wof_daily_spin_last_given_' . $wheel_id;
|
||||||
|
$last_given_timestamp = get_user_meta($user_id, $last_given_meta_key, true);
|
||||||
|
// Sprememba: 24 ur (23*HOUR_IN_SECONDS)
|
||||||
|
if (empty($last_given_timestamp) || (time() - $last_given_timestamp > 23 * HOUR_IN_SECONDS)) {
|
||||||
|
$ok = wheel_of_fortune_add_spins($user_id, 1, $wheel_id);
|
||||||
|
if ($ok) {
|
||||||
|
update_user_meta($user_id, $last_given_meta_key, time());
|
||||||
|
wheel_of_fortune_debug_log("CRON: Assigned spin to user $user_id for wheel $wheel_id. Result: " . var_export($ok, true));
|
||||||
|
} else {
|
||||||
|
wheel_of_fortune_debug_log("CRON: Failed to assign spin to user $user_id for wheel $wheel_id.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
wheel_of_fortune_debug_log("CRON: User $user_id already received a spin recently. Skipping.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wp_send_json_error(__('Napaka pri brisanju.', 'wheel-of-fortune'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize plugin
|
// Initialize plugin
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue