Support for Cron Jobs and Multiple sql in db exec
This commit is contained in:
parent
c77e89ddcc
commit
c831de323a
|
@ -180,24 +180,37 @@ class database{
|
|||
$this->connection = null;
|
||||
}
|
||||
|
||||
public function exec($sql, $fetch=false, $param=null){
|
||||
public function exec($sql1, $fetch=false, $param=null, ...$others_params){
|
||||
try{
|
||||
$this->connection->beginTransaction();
|
||||
$this->stmt = $this->connection->prepare(str_replace("%PREFIX%", DB_PREFIX, $sql));
|
||||
if(!is_null($param)){
|
||||
$this->query = $this->stmt->execute($param);
|
||||
} else {
|
||||
$this->query = $this->stmt->execute();
|
||||
//$this->connection->beginTransaction();
|
||||
array_unshift($others_params,$sql1);
|
||||
bdump($others_params);
|
||||
$toReturn = [];
|
||||
foreach($others_params as $sql){
|
||||
$sql = str_replace("%PREFIX%", DB_PREFIX, $sql);
|
||||
bdump($sql);
|
||||
$this->stmt = $this->connection->prepare($sql);
|
||||
if(!is_null($param)){
|
||||
$this->query = $this->stmt->execute($param);
|
||||
} else {
|
||||
$this->query = $this->stmt->execute();
|
||||
}
|
||||
bdump($this->query);
|
||||
|
||||
if($fetch == true){
|
||||
if(count($others_params) > 1) {
|
||||
$toReturn[] = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
$toReturn = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
}
|
||||
bdump($this->query);
|
||||
$this->connection->commit();
|
||||
if($fetch == true){
|
||||
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
$this->stmt->closeCursor();
|
||||
//$this->connection->commit();
|
||||
//$this->stmt->closeCursor();
|
||||
return $toReturn;
|
||||
} catch (PDOException $e) {
|
||||
print "Error!: " . $e->getMessage() . "<br/>";
|
||||
$this->connection->rollBack();
|
||||
//$this->connection->rollBack();
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -389,7 +389,7 @@ function initOptions($name, $visible, $password, $report_email, $owner){
|
|||
$auth = new \Delight\Auth\Auth($connection, $_SERVER['REMOTE_ADDR'], $prefix."_");
|
||||
$userId = $auth->register($report_email, $password, $name);
|
||||
$auth->admin()->addRoleForUserById($userId, Role::SUPER_ADMIN);
|
||||
$option_check_cf_ip = empty($_SERVER['HTTP_CF_CONNECTING_IP']) ? "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'check_cf_ip', 1, '1', current_timestamp(), current_timestamp(), '1');" : "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'check_cf_ip', 0, '1', current_timestamp(), current_timestamp(), '1');";
|
||||
$option_check_cf_ip = empty($_SERVER['HTTP_CF_CONNECTING_IP']) ? "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('11', 'check_cf_ip', 1, '1', current_timestamp(), current_timestamp(), '1');" : "INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'check_cf_ip', 0, '1', current_timestamp(), current_timestamp(), '1');";
|
||||
$prep = $connection->prepare("
|
||||
INSERT INTO `".$prefix."_profiles` (`id`, `hidden`) VALUES (NULL, :hidden);
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('1', 'report_email', :report_email, '1', current_timestamp(), current_timestamp(), '1');
|
||||
|
@ -401,11 +401,14 @@ INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_ti
|
|||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('7', 'intrusion_save_info', 1, '1', current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('8', 'enable_technical_support', 0, '1', current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('9', 'technical_support_key', '', '1', current_timestamp(), current_timestamp(), '1');
|
||||
INSERT INTO `".$prefix."_options` (`id`, `name`, `value`, `enabled`, `created_time`, `last_edit`, `user_id`) VALUES ('10', 'cron_job_code', :cron_job_code, '1', current_timestamp(), current_timestamp(), '1');
|
||||
$option_check_cf_ip");
|
||||
mt_srand(10);
|
||||
$prep->bindValue(':hidden', ($visible ? 0 : 1), PDO::PARAM_INT);
|
||||
$prep->bindValue(':report_email', $report_email, PDO::PARAM_STR);
|
||||
$prep->bindValue(':owner', $owner, PDO::PARAM_STR);
|
||||
$prep->bindValue(':web_url', str_replace("install/install.php", "", full_path()), PDO::PARAM_STR);
|
||||
$prep->bindValue(':cron_job_code', uniqid().mt_rand(), PDO::PARAM_STR);
|
||||
$prep->execute();
|
||||
} catch (Exception $e) {
|
||||
if(is_cli()){
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
include_once 'core.php';
|
||||
|
||||
init_class();
|
||||
$day = 19;
|
||||
$ore = 1;
|
||||
|
||||
|
@ -8,52 +11,31 @@ $minuti = 5;
|
|||
setlocale(LC_TIME, 'ita', 'it_IT');
|
||||
echo date('i') . " - " . date('H') . " - " . date("d") . "<br>";
|
||||
|
||||
include_once 'core.php';
|
||||
|
||||
init_class();
|
||||
|
||||
function resetminuti(){
|
||||
global $profiles_tot;
|
||||
global $database;
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles"; // Pesco i dati della table e li ordino in base alla disponibilità
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles";
|
||||
$risultato = $database->exec($sql, true);
|
||||
$disp = array();
|
||||
foreach($risultato as $row){
|
||||
$disp[$row['name']] = $row['minuti_dispo'];
|
||||
$disp[$row['id']] = $row['minuti_dispo'];
|
||||
}
|
||||
print("<br><pre>" . print_r($disp, true) . "</pre><br>");
|
||||
|
||||
|
||||
// pre-5.3:
|
||||
// 5.3:
|
||||
$list = implode(', ', array_map(
|
||||
create_function('$k,$v', 'return "$k => $v";'),
|
||||
function ($k, $v) { return "$k = $v;"; },
|
||||
array_keys($disp),
|
||||
array_values($disp)
|
||||
));
|
||||
$a1 = implode(" - ", array_keys($disp));
|
||||
$a2 = implode(" - ", array_values($disp));
|
||||
echo "<p style='color:red;'>" . $list . "</p><br><p style='color:green;'>" . $a1 . "</p><br><p style='color:blue;'>" . $a2 . "</p><br>";
|
||||
$a1 = implode(";", array_keys($disp));
|
||||
$a2 = implode(";", array_values($disp));
|
||||
$mese = strftime("%B");
|
||||
$anno = strftime("%Y");
|
||||
echo $mese . " - " . $anno . "<br>";
|
||||
|
||||
|
||||
$sql = "INSERT INTO `%PREFIX%_minuti` (`id`, `mese`, `anno`, `list`, `a1`, `a2`) VALUES (NULL, '$mese', '$anno', '$list', '$a1', '$a2')"; // Pesco i dati della table e li ordino in base alla disponibilità
|
||||
$risultato = $database->exec($sql);
|
||||
|
||||
foreach($risultato as $row){
|
||||
$sql = "UPDATE %PREFIX%_profiles SET minuti_dispo = '0' WHERE name ='" . $user . "'";
|
||||
$risultato = $database->exec($sql);
|
||||
echo "reset effettuato: " . $user . "<br>";
|
||||
}
|
||||
|
||||
if($risultato){
|
||||
echo <<<EOT
|
||||
<img src='https://media1.tenor.com/images/768840dae0d91bbc9f215d9255af8170/tenor.gif?itemid=8706004'></img>
|
||||
<img src='https://media1.tenor.com/images/4d41eec52c39344dd87e1022cc0eb98c/tenor.gif?itemid=4572479'></img>
|
||||
<img src='https://thumbs.gfycat.com/FinishedSnarlingAfricanelephant-max-1mb.gif'></img>
|
||||
EOT;
|
||||
}
|
||||
$sql = "INSERT INTO `%PREFIX%_minuti` (`id`, `mese`, `anno`, `list`, `a1`, `a2`) VALUES (NULL, '$mese', '$anno', '$list', '$a1', '$a2')";
|
||||
$risultato = $database->exec($sql, false, null, "UPDATE %PREFIX%_profiles SET minuti_dispo = '0' WHERE 1;");
|
||||
}
|
||||
|
||||
//Per quando dovrò (forse) reinserire i valori in table o generare un array
|
||||
|
@ -65,35 +47,35 @@ function array_combine_($keys, $values){
|
|||
array_walk($result, create_function('&$v', '$v = (count($v) == 1)? array_pop($v): $v;'));
|
||||
return $result;
|
||||
}
|
||||
//print("<br><pre>" . print_r(array_combine_(explode(" - ", $a1), explode(" - ", $a2)), true) . "</pre><br>");
|
||||
|
||||
if($start && isset($_POST['cron']) && $_POST['cron'] == "cron_job-".$database->getOption("cron_job_code")){
|
||||
if($start && isset($_POST['reset']) && $_POST['reset'] == "cron_job-".$database->getOption("cron_job_code")){
|
||||
echo("reset");
|
||||
resetminuti();
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles ORDER BY available DESC, caposquadra DESC, services ASC, name ASC"; // Pesco i dati della table e li ordino in base alla disponibilità
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles ORDER BY name ASC";
|
||||
$risultato = $database->exec($sql, true);
|
||||
|
||||
$profiles_tot = array();
|
||||
$incremento = array();
|
||||
$minuti_dispo_old = array();
|
||||
foreach($risultato as $row){
|
||||
$profiles_tot[] = $row['name'];
|
||||
$profiles_tot[] = $row['id'];
|
||||
if($row['available'] == "1"){
|
||||
$incremento[] = $row['name'];
|
||||
$incremento[] = $row['id'];
|
||||
$minuti_dispo_old[] = $row['minuti_dispo'];
|
||||
}
|
||||
}
|
||||
print_r($incremento);
|
||||
|
||||
if($start && isset($_POST['cron']) && $_POST['cron'] == "cron-job"){
|
||||
if($start && isset($_POST['reset']) && $_POST['reset'] == "cron-job"){
|
||||
resetminuti();
|
||||
}
|
||||
|
||||
foreach($incremento as $key=>$user){
|
||||
foreach($incremento as $key=>$id){
|
||||
$minuti_dispo = $minuti_dispo_old[$key] + $minuti;
|
||||
$sql = "UPDATE %PREFIX%_profiles SET minuti_dispo = '" . $minuti_dispo . "' WHERE name ='" . $user . "'";
|
||||
$sql = "UPDATE %PREFIX%_profiles SET minuti_dispo = '" . $minuti_dispo . "' WHERE id ='" . $id . "'";
|
||||
echo $sql;
|
||||
$risultato = $database->exec($sql, true);
|
||||
}
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles ORDER BY available DESC, caposquadra DESC, services ASC, name ASC"; // Pesco i dati della table e li ordino in base alla disponibilità
|
||||
$sql = "SELECT * FROM %PREFIX%_profiles ORDER BY available DESC, caposquadra DESC, services ASC, name ASC";
|
||||
$risultato = $database->exec($sql, true);
|
||||
$minuti_dispo = array();
|
||||
foreach($risultato as $row){
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
require("ui.php");
|
||||
echo("<pre>");
|
||||
var_dump($translations);
|
||||
echo("</pre>");
|
|
@ -7,7 +7,7 @@ $user->requirelogin();
|
|||
|
||||
function arraynum(){
|
||||
global $database;
|
||||
$risultato = $database->exec("SELECT * FROM `%PREFIX%_profiles` ORDER BY available DESC, caposquadra DESC, services ASC, name ASC", true); // Pesco i dati della table e li ordino in base alla disponibilità
|
||||
$risultato = $database->exec("SELECT * FROM `%PREFIX%_profiles` ORDER BY available DESC, caposquadra DESC, services ASC, name ASC", true);
|
||||
$incremento = array();
|
||||
$minuti_dispo_old = array();
|
||||
foreach($risultato as $row){
|
||||
|
|
Loading…
Reference in New Issue