connect_error) { die('Connect Error (' . $this->connect_errno . ')' . $this->connect_error); } $this->set_charset("utf8"); } /** * */ public function reset() { if (!$this->checkTable($this->_t_debug)) { $this->safequery("CREATE TABLE `_MySQL_debug` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `data` datetime NOT NULL, `query` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin"); } else { $this->safequery("TRUNCATE TABLE $this->_t_debug"); } } /** * @param $table * @return bool */ public function checkTable($table) { if ($this->safequery("SHOW TABLES LIKE '$table'")->num_rows == 1) { return true; } return false; } /** * @param $query * @return bool|mysqli_result */ public function safequery($query) { if (!($result = $this->query($query))) { $query = $this->real_escape_string($query); $log = "INSERT INTO $this->_t_debug VALUES (NULL, NOW(),'$query')"; $this->query($log); } return $result; } /** * @param $str * @param int $wait_for * @return bool */ public function lock($str, $wait_for = 1000) { $res = $this->query("SELECT GET_LOCK('$str', $wait_for)"); if ($res) { $arr = $res->fetch_row(); return $arr[0]; } return false; } /** * @param $str */ public function unlock($str) { $this->query("SELECT RELEASE_LOCK('$str')"); } public function showTable($table) { $res = $this->safequery("SHOW CREATE TABLE $table"); $res = $res->fetch_array(); return $res[1]; } } /** * @return string */ function get_client_ip() { if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if (getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if (getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if (getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if (getenv('HTTP_FORWARDED')) $ipaddress = getenv('HTTP_FORWARDED'); else if (getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } /** * @param int $length * @return string */ function get_random_string($length = 25) { $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $string = ''; for ($i = 0; $i < $length; $i++) { $string .= $characters[rand(0, strlen($characters) - 1)]; } return $string; } /** * @param $to * @param $subject * @param $message * @param null $attachment * @param null $stringAttachment * @return bool */ function mail_html($to, $subject, $message, $attachment = NULL, $stringAttachment = NULL) { $mail = new PHPMailer(); $mail->addAddress($to); $mail->setFrom("copedev@gidev.it", "NoReply Copedev"); $mail->msgHTML("$message"); $mail->Subject = $subject; $mail->AddCustomHeader( "X-Confirm-Reading-To: pincoluca1@gmail.com" ); if($attachment){ if($stringAttachment){ $mail->addStringAttachment($stringAttachment, $attachment); }else{ $mail->addAttachment($attachment); } } /*$headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From: NoReply Copedev' . "\r\n"; return mail($to, $subject, $message, $headers);*/ $return = $mail->send(); if(!$return){ $msg = $mail->ErrorInfo; throw_error("Mail non inviata: $msg"); } return $return; } /** * @param $message * @param int $duration * @param bool $plainText */ function throw_success($message, $duration = 5000, $plainText = true) { if($plainText){ $message = htmlspecialchars($message, ENT_QUOTES); } $message = json_encode($message); $_SESSION['info'][] = ['message' => $message, 'duration' => $duration, 'class' => "green"]; } /** * @param $message * @param int $duration * @param bool $plainText */ function throw_error($message, $duration = 5000, $plainText = true) { if($plainText){ $message = htmlspecialchars($message, ENT_QUOTES); } $message = json_encode($message); $_SESSION['info'][] = ['message' => $message, 'duration' => $duration, 'class' => "red"]; } /** * @param $message * @param int $duration * @param bool $plainText */ function throw_msg($message, $duration = 5000, $plainText = true) { if($plainText){ $message = htmlspecialchars($message, ENT_QUOTES); } $message = json_encode($message); $_SESSION['info'][] = ['message' => $message, 'duration' => $duration, 'class' => ""]; } /** * @return bool */ function check_params(){ for ($i = 0; $i < func_num_args(); $i++) { if(!func_get_arg($i)) { throw_error("E_INVALID_ARGS: $i"); return false; } } return true; } /** * @return mixed */ function get_msg() { return $_SESSION['info']; } /** * */ function clear_msg() { $_SESSION['info'] = NULL; } /** * @param $string * @return mixed */ function cleanString($string) { $string = preg_replace("/[^.A-Za-z0-9]/", "", $string); return $string; }