Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/models/AdminModel.php

77 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2018-10-16 16:28:42 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AdminModel extends CI_Model {
public function __construct() {
parent::__construct();
}
public function insertRedirect($url, $name) {
$result1 = $this->db->query('SELECT * FROM redirects WHERE redirect = ?', [$name])->result_array();
if(empty($result1)) {
$this->db->query('INSERT INTO redirects (url, redirect) VALUES (?, ?)', [$url, $name]);
return ['feedback' => 'success'];
} else {
return ['feedback' => 'error', 'message' => 'Umleitungs-Code ist schon vergeben!'];
}
}
public function getUrl($name) {
$result1 = $this->db->query('SELECT * FROM redirects WHERE redirect = ?', [$name])->result_array();
if(empty($result1)) {
return base_url();
} else {
$result = $result1[0];
return $result['url'];
}
}
public function getItems() {
$result = $this->db->query('SELECT * FROM redirects')->result_array();
return $result;
}
public function getName($url) {
$result = $this->db->query('SELECT * FROM redirects WHERE url = ?', [$url])->result_array();
if(empty($result)) {
return '';
} else {
$result1 = $result[0];
return $result1['redirect'];
}
}
public function addRandomItem($url) {
if($this->redirect->getName($url) == '') {
for($i = 0; $i < 1; $i++) {
$randomName = base64_encode($url);
$name = '';
for($j = 0; $j < 5; $j++) {
$random = rand(0, strlen($randomName) - 1);
$name .= $randomName[$random];
}
if($this->redirect->insertRedirect($url, $name)['feedback'] == 'success') {
return $this->redirect->getName($url);
} else {
$i--;
}
}
} else {
return $this->redirect->getName($url);
}
}
public function getCalendarEvents()
{
return $this->db->query('SELECT * FROM calendar')->result_array();
}
}