setGlobals(); setlocale(LC_ALL,"de_DE"); } public function setClient(){ $kunde = new kunde(); if($kunde->select('"'.filter_var($_SERVER['HTTP_HOST'],FILTER_SANITIZE_URL).'"',"domain")){ $this->id_client = $kunde->getid(); //error_log('ID-CLIENT: '.$this->id_client); }else{ die("Unbekannte Domain: ".filter_var($_SERVER['HTTP_HOST'],FILTER_SANITIZE_URL)); } return $kunde; } private function setGlobals(){ $kunde = $this->setClient(); //error_log("Kunde ist ".$this->id_client); $this->rights = array( 'landing'=>KK_ACCESS_PUBLIC, 'fruehere'=>KK_ACCESS_PUBLIC, 'wahlen'=>KK_ACCESS_PUBLIC, 'home'=>KK_ACCESS_PUBLIC, 'login'=>KK_ACCESS_PUBLIC, 'listen'=>KK_ACCESS_PUBLIC, 'kandidaten'=>KK_ACCESS_PUBLIC, 'faq'=>KK_ACCESS_PUBLIC, 'not_found'=>KK_ACCESS_PUBLIC, 'register_candidate'=>KK_ACCESS_PUBLIC, 'register_user'=>KK_ACCESS_PUBLIC, 'media'=>KK_ACCESS_PUBLIC, 'profil'=>KK_ACCESS_PUBLIC, 'parteiprofil'=>KK_ACCESS_PUBLIC, 'impressum'=>KK_ACCESS_PUBLIC, 'datenschutz'=>KK_ACCESS_PUBLIC, 'fb'=>KK_ACCESS_PUBLIC, 'fragen'=>KK_ACCESS_FRONTEND, 'vergleichen'=>KK_ACCESS_PUBLIC, 'antworten'=>KK_ACCESS_CANDIDATE, 'user_fragen'=>KK_ACCESS_FRONTEND, 'admin'=>KK_ACCESS_ADMINAREA, 'admin_wahlen'=>KK_ACCESS_ADMINAREA, 'admin_wahlen_new'=>KK_ACCESS_ADMINAREA, 'admin_kandidaten'=>KK_ACCESS_ADMINAREA, 'admin_kandidaten_new'=>KK_ACCESS_ADMINAREA, 'admin_user'=>KK_ACCESS_ADMINAREA, 'admin_user_new'=>KK_ACCESS_ADMINAREA, 'admin_fragen'=>KK_ACCESS_ADMINAREA, 'admin_fragen_new'=>KK_ACCESS_ADMINAREA, 'admin_mail'=>KK_ACCESS_ADMINAREA, 'admin_faq'=>KK_ACCESS_ADMINAREA, 'admin_faq_new'=>KK_ACCESS_ADMINAREA, 'admin_video'=>KK_ACCESS_ADMINAREA, 'admin_video_new'=>KK_ACCESS_ADMINAREA, 'admin_parteien'=>KK_ACCESS_ADMINAREA, 'admin_parteien_new'=>KK_ACCESS_ADMINAREA, 'regeln'=>KK_ACCESS_PUBLIC, 'user_profil'=>KK_ACCESS_FRONTEND, 'account'=>KK_ACCESS_FRONTEND, 'ergebnisse'=>KK_ACCESS_PUBLIC, 'abstimmen'=>KK_ACCESS_PUBLIC, ); $smartypath = KK_SYSTEM_PATH."smarty/libs/"; define('SMARTY_PATH',$smartypath); $this->template_path = KK_SYSTEM_PATH."smarty/"; $template_path = $this->template_path; require_once(SMARTY_PATH.'Smarty.class.php'); $this->smarty = new Smarty(); $this->smarty->caching=Smarty::CACHING_OFF; $this->smarty->left_delimiter = '{'; $this->smarty->right_delimiter = '}'; //$this->smarty->debugging=true; $this->smarty->template_dir = $template_path.'templates/'; $this->smarty->compile_dir = $template_path.'templates_c/'; $this->smarty->cache_dir = $template_path.'cache/'; $this->smarty->config_dir = $template_path.'configs/'; if($this->isLoggedIn()){ $this->smarty->assign("user_realname",$_SESSION['user']->getuser_firstname()." ".$_SESSION['user']->getuser_lastname()); $this->smarty->assign("logged_in_user",$_SESSION['user']); } $this->smarty->assign("loggedin",$this->isLoggedIn()); $this->smarty->assign("host",$kunde->getdomain()); $id_wahl = $this->getActiveWahl(); $wahl = new wahl(); if($wahl->load($id_wahl)){ $this->smarty->assign("wahl",$wahl); $this->smarty->assign("isParty",($wahl->getenable_lists() ==1)); } if($this->isLoggedIn()){ $this->smarty->assign("is_dev",($_SESSION['user']->getuser_email() == "mail@kevinkempfer.de")); if($_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA)){ //$this->smarty->debugging=true; } // if($_SESSION['user']->hasRight(KK_ACCESS_PARTY)){ // $partei = new partei(); // $kandidat = $_SESSION['user']->getKandidat(); // $partei->load($kandidat->getid_partei()); // $this->smarty->assign("token",$partei->getToken()); // } // else if($_SESSION['user']->hasRight(KK_ACCESS_CANDIDATE)){ $kandidat = new kandidat(); $kandidat->select($_SESSION['user']->getid(),'id_user'); // $user= new user(); // $user->load($kandidat->getid_user()); // $user->setuser_rights($user->getuser_rights() | KK_ACCESS_FRONTEND); // $user->Save(); error_log("assigning token ".$kandidat->getToken()." for ".$kandidat->getkandidat_firstname()." ".$kandidat->getkandidat_lastname()); $this->smarty->assign("token",$kandidat->getToken()); } } require_once(KK_SYSTEM_PATH."xajax/xajax_core/xajax.inc.php"); if(isset($_SESSION['user'])){ $this->smarty->assign('logged_in',true); //if($_SESSION['user']->getlevel() >= USER_LEVEL_ADMIN) // $this->smarty->assign('show_admin',true); }else { if(isset($_COOKIE['uid'])){ $this->tryLogin($_COOKIE['uid']); } if(!isset($_SESSION['board_guest_login'])){ // $this->loginBoardGuest(); } } if(isset($_COOKIE['consent'])){ // error_log('looking for cookie'); $data = json_decode($_COOKIE['consent'],true); // error_log('cookie: '.print_r($data,true)); if($data){ // error_log('saving cookie to session'); $_SESSION['consent'] = $data['services']; // error_log(print_r($_SESSION['consent'],true)); }else{ // error_log('no cookie data'); } } } public function redirect($pagename){ $pagename = 'page_'.$pagename; $page = new $pagename; $page->display(); } public function logout(){ session_destroy(); setcookie("uid",null,strtotime("yesterday")); } public function tryLogin($uid){ } /** * * @param frage $frage * @return boolean */ public function approveQuestion($frage){ $thema = new thema(); $thema->load($frage->getid_thema()); $id_forum = $thema->getforum_id(); $message = $frage->getfrage_text(false); $subject = $frage->getfrage_betreff(); $r_user = new user(); $r_user->load($frage->getid_user()); global $phpbb_root_path; global $phpbb_container; global $phpbb_dispatcher; global $table_prefix; global $phpEx; global $db; global $config; global $user; global $auth; global $cache; global $template; $kbuser = $_SESSION['user']; // define('IN_PHPBB', true); // define('ROOT_PATH', KK_HTDOCS_PATH."forum/"); // $phpbb_root_path = KK_HTDOCS_PATH."forum/"; // // if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) { // exit(); // } // // $phpEx = "php"; // //$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/'; // include_once($phpbb_root_path . 'common.' . $phpEx); // include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); // // generate_text_for_storage($message, $uid, $bitfield,$flags,true,true); // // New Topic Example // $data = array( // // General Posting Settings // 'forum_id' => $id_forum, // The forum ID in which the post will be placed. (int) // 'topic_id' => 0, // Post a new topic or in an existing one? Set to 0 to create a new one, if not, specify your topic ID here instead. // 'icon_id' => false, // The Icon ID in which the post will be displayed with on the viewforum, set to false for icon_id. (int) // // // Defining Post Options // 'enable_bbcode' => true, // Enable BBcode in this post. (bool) // 'enable_smilies' => true, // Enabe smilies in this post. (bool) // 'enable_urls' => true, // Enable self-parsing URL links in this post. (bool) // 'enable_sig' => true, // Enable the signature of the poster to be displayed in the post. (bool) // // // Message Body // 'message' => $message, // Your text you wish to have submitted. It should pass through generate_text_for_storage() before this. (string) // 'message_md5' => md5($message),// The md5 hash of your message // // // Values from generate_text_for_storage() // 'bbcode_bitfield' => $bitfield, // Value created from the generate_text_for_storage() function. // 'bbcode_uid' => $uid, // Value created from the generate_text_for_storage() function. // // // Other Options // 'post_edit_locked' => 1, // Disallow post editing? 1 = Yes, 0 = No // 'topic_title' => $subject, // Subject/Title of the topic. (string) // // // Email Notification Settings // 'notify_set' => false, // (bool) // 'notify' => true, // (bool) // 'post_time' => 0, // Set a specific time, use 0 to let submit_post() take care of getting the proper time (int) // 'forum_name' => '', // For identifying the name of the forum in a notification email. (string) // // // Indexing // 'enable_indexing' => true, // Allow indexing the post? (bool) // // // 3.0.6 // 'force_approved_state' => true, // Allow the post to be submitted without going into unapproved queue // // // 3.1-dev, overwrites force_approve_state // 'force_visibility' => true, // Allow the post to be submitted without going into unapproved queue, or make it be deleted // ); // $this->loginBoard($r_user); // $furl = submit_post("post",$subject,$kbuser->getuser_firstname()." ".$kbuser->getuser_lastname(),0,$poll,$data); // $this->loginBoard(); $frage->setfrage_status(KK_QUESTION_STATUS_APPROVED); $client = new kunde(); $client->load($this->id_client); // $my_url = "https://".$client->getdomain()."/".str_replace(KK_HTDOCS_PATH, "", $furl); // $frage->setforum_url($my_url); $frage->Save(); $kunde = new kunde(); $kunde->load($this->id_client); $this->smarty->assign("user",$r_user); $this->smarty->assign("host",$kunde->getdomain()); $this->smarty->assign("subject",$frage->getfrage_betreff()); $this->sendMail($r_user->getuser_email(), "Ihre Frage auf ".$kunde->getdomain(). " wurde freigeschalten!", $this->smarty->fetch("mail_question_approved.tpl"),"no-reply@".$kunde->getdomain(), false,false, $kunde->getdomain()." Team",false,true); return true; } public function login($username,$password=null){ if(isset($username)){ $user = new user(); $username = filter_var($username,FILTER_SANITIZE_EMAIL); $users = $user->selectAll('"'.$username.'" AND user_status < '.KK_USER_STATUS_SUSPENDED,"user_email"); //if($user->loadByUsername($username)){ if(sizeof($users) == 1){ foreach ($users as $user){ error_log("trying single user login: ".$user->getuser_email()); if($user->getuser_status() == KK_USER_STATUS_ACTIVE){ if((password_verify($password,$user->getuser_password()) && strtolower($user->getuser_email()) == strtolower($username)) || (isset($_SESSION['user']) && $_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA))){ //ok error_log("login ok, user: ".$user->getuser_email()." ID: ".$user->getid()); $_SESSION['user'] = $user; $settings = new user_settings(); $_SESSION['user_settings'] = $settings->loadByUser($user->getid()); //error_log("Logged in user ".$user->getuser_realname()); //error_log("Logged in user rights: ".$user->getuser_rights()); // $this->loginBoard(); return true; }else{ error_log("wrong password $password for user $username in DB: ".$user->getuser_password()); } }else{ error_log("user not active: $username"); } } }else{ //mehrere Accounts gefunden, Passwort checken $ok=0; foreach ($users as $user){ error_log("trying multi-user login: ".$user->getuser_email()); if($user->getuser_status() == KK_USER_STATUS_ACTIVE){ if((password_verify($password,$user->getuser_password()) && strtolower($user->getuser_email()) == strtolower($username)) || (isset($_SESSION['user']) && $_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA))){ //ok $_SESSION['user'] = $user; $settings = new user_settings(); $_SESSION['user_settings'] = $settings->loadByUser($user->getid()); //error_log("Logged in user ".$user->getuser_realname()); //error_log("Logged in user rights: ".$user->getuser_rights()); // $this->loginBoard(); $ok++; error_log("login ok, correct credentials: ".$ok); }else{ error_log("MULTI-USER: wrong password $password for user $username in DB: ".$user->getid()); error_log("Login failed for user ".$username); //return false; } }else{ error_log("user ".$user->getid()." not active: $username"); return false; } } error_log("finished: correct credentials: ".$ok); if($ok > 1){ //alle ok, User fragen error_log('multiple accounts found, redirecting to accounts page'); header('Location: /account'); exit(); }elseif ($ok == 1){ error_log('exactly one valid login found, returning true'); return true; } } } error_log("Login failed for user ".$username); return false; } public function loginBoard($r_user=false){ global $phpbb_root_path; global $phpbb_container; global $phpbb_dispatcher; global $table_prefix; global $phpEx; global $db; global $config; global $user; global $auth; global $cache; global $template; if(!$r_user){ $kbuser = $_SESSION['user']; }else{ $kbuser = $r_user; } define('IN_PHPBB', true); define('ROOT_PATH', KK_HTDOCS_PATH."forum/"); $phpbb_root_path = KK_HTDOCS_PATH."forum/"; if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) { exit(); } $phpEx = "php"; //$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/'; // include_once ($phpbb_root_path . 'common.' . $phpEx); $user->session_begin(); $auth->acl($user->data); error_log("logging in to Board as ".$kbuser->getuser_firstname(). " ".$kbuser->getuser_lastname()); $auth->login($kbuser->getuser_firstname(). " ".$kbuser->getuser_lastname(), $kbuser->getuser_password(), true, 1, 0); } public function loginBoardGuest(){ global $phpbb_root_path; global $phpbb_container; global $phpbb_dispatcher; global $table_prefix; global $phpEx; global $db; global $config; global $user; global $auth; global $cache; global $template; $wahl = new wahl(); $wahl->load($this->getActiveWahl()); define('IN_PHPBB', true); define('ROOT_PATH', KK_HTDOCS_PATH."forum/"); $phpbb_root_path = KK_HTDOCS_PATH."forum/"; if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) { exit(); } $phpEx = "php"; //$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/'; // include($phpbb_root_path . 'common.' . $phpEx); $user->session_begin(); $auth->acl($user->data); // error_log("logging guest in to Board"); $auth->login($wahl->getforum_guest_user(), SALT, true, 1, 0); $_SESSION['board_guest_login']=true; } public function isLoggedIn(){ return (isset($_SESSION['user'])); } public function doLogout(){ $objResponse = new xajaxResponse(); $objResponse->redirect("/"); $this->logout(); return $objResponse; } public function checkUsersAccess($page,$user_rights=false){ if(!$user_rights){ if(isset($_SESSION['user'])){ $user_rights =$_SESSION['user']->getuser_rights(); }else{ $user_rights = KK_ACCESS_PUBLIC; } } if ($this->rights[$page] & $user_rights) { return true; }else { error_log($_SERVER['QUERY_STRING']."not enough rights for $page: ".$this->rights[$page]." & $user_rights = ".($this->rights[$page] & $user_rights)); return false; } } public function checkUsersRights($page_rights,$user_rights=false){ if(!$user_rights){ if(isset($_SESSION['user'])){ $user_rights =$_SESSION['user']->getuser_rights(); }else{ $user_rights = KK_ACCESS_PUBLIC; } } if ($page_rights & $user_rights) { return true; }else { return false; } } public function sendMail($to, $subject, $message, $from="no-reply@kandidaten-befragung.de", $cc=false, $bcc=false, $fromName = "DPV Mailer", $replyTo=false, $messageHTML=false, $messageID = false, $attachment=null){ /* $headers = 'From: no-reply@kkdevs.com' . "\r\n" . 'Reply-To: no-reply@kkdevs.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); */ $logto = $to; if(is_array($to)){ $logto = implode(",", $to); } error_log("Sending Mail: $logto,$subject,$from,$cc,$bcc"); $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isMail(); if($cc){ $mail->addCC($cc); } if($bcc){ //error_log("adding bcc:".$bcc); $mail->addBCC($bcc); } if($replyTo){ $mail->addReplyTo($replyTo, $fromName); } //error_log("HTML: ".var_export($messageHTML,true)); $mail->isHTML(($messageHTML !== false)); $mail->setFrom($from, $fromName); if(is_array($to)){ foreach ($to as $t){ $mail->addAddress($t); // Add a recipient } }else{ $mail->addAddress($to); // Add a recipient } $mail->Subject = $subject; $mail->Body = $message; //error_log("HTML: ".$messageHTML); if(!is_bool($messageHTML)){ $mail->Body = $messageHTML; $mail->AltBody = $message; error_log("added alt body to HTML"); } $mail->CharSet = 'UTF-8'; if($messageID){ $mail->MessageID = $messageID; } if(!is_null($attachment)){ if(!is_array($attachment)){ $attachment = [$attachment]; } foreach ($attachment as $a){ $mail->addAttachment($a); } } if(!$mail->send()) { error_log('Message could not be sent.'); error_log('Mailer Error: ' . $mail->ErrorInfo); return false; } else { error_log('Message has been sent'); return true; } } static public function slugify($text) { $text = str_replace(array('ä','ö','ü','Ä','Ö','Ü','ß'), array('ae','oe','ue','Ae','Oe','Ue','ss'), $text); // replace non letter or digits by - $text = preg_replace('~[^\pL\d]+~u', '-', $text); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); // trim $text = trim($text, '-'); // remove duplicate - $text = preg_replace('~-+~', '-', $text); // lowercase $text = strtolower($text); if (empty($text)) { return 'n-a'; } return $text; } /** * easy image resize function * @param $file - file name to resize * @param $string - The image data, as a string * @param $width - new image width * @param $height - new image height * @param $proportional - keep image proportional, default is no * @param $output - name of the new file (include path if needed) * @param $delete_original - if true the original image will be deleted * @param $use_linux_commands - if set to true will use "rm" to delete the image, if false will use PHP unlink * @param $quality - enter 1-100 (100 is best quality) default is 100 * @param $grayscale - if true, image will be grayscale (default is false) * @return boolean|resource */ function smart_resize_image($file, $string = null, $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = true, $use_linux_commands = false, $quality = 100, $grayscale = false ) { if ( $height <= 0 && $width <= 0 ) return false; if ( $file === null && $string === null ) return false; # Setting defaults and meta $info = $file !== null ? getimagesize($file) : getimagesizefromstring($string); $image = ''; $final_width = 0; $final_height = 0; list($width_old, $height_old) = $info; $cropHeight = $cropWidth = 0; # Calculating proportionality if ($proportional) { if ($width == 0) $factor = $height/$height_old; elseif ($height == 0) $factor = $width/$width_old; else $factor = min( $width / $width_old, $height / $height_old ); $final_width = round( $width_old * $factor ); $final_height = round( $height_old * $factor ); //error_log("final size: $final_width x $final_height"); } else { $final_width = ( $width <= 0 ) ? $width_old : $width; $final_height = ( $height <= 0 ) ? $height_old : $height; $widthX = $width_old / $width; $heightX = $height_old / $height; $x = min($widthX, $heightX); $cropWidth = ($width_old - $width * $x) / 2; $cropHeight = ($height_old - $height * $x) / 2; } $image = new Imagick(); $image->readImage($file); //$image->setImageResolution(72,72); $image->resizeimage($final_width, $final_height, imagick::FILTER_LANCZOS,0.9); //$image->resampleImage($final_width,$final_height,imagick::FILTER_UNDEFINED,0); $image->writeImage($output); return true; # Loading image to memory according to type switch ( $info[2] ) { case IMAGETYPE_JPEG: $file !== null ? $image = imagecreatefromjpeg($file) : $image = imagecreatefromstring($string); break; case IMAGETYPE_GIF: $file !== null ? $image = imagecreatefromgif($file) : $image = imagecreatefromstring($string); break; case IMAGETYPE_PNG: $file !== null ? $image = imagecreatefrompng($file) : $image = imagecreatefromstring($string); break; default: return false; } # Making the image grayscale, if needed if ($grayscale) { imagefilter($image, IMG_FILTER_GRAYSCALE); } # This is the resizing/resampling/transparency-preserving magic $image_resized = imagecreatetruecolor( $final_width, $final_height ); if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) { $transparency = imagecolortransparent($image); $palletsize = imagecolorstotal($image); if ($transparency >= 0 && $transparency < $palletsize) { $transparent_color = imagecolorsforindex($image, $transparency); $transparency = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); imagefill($image_resized, 0, 0, $transparency); imagecolortransparent($image_resized, $transparency); } elseif ($info[2] == IMAGETYPE_PNG) { imagealphablending($image_resized, false); $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127); imagefill($image_resized, 0, 0, $color); imagesavealpha($image_resized, true); } } imagecopyresampled($image_resized, $image, 0, 0, $cropWidth, $cropHeight, $final_width, $final_height, $width_old - 2 * $cropWidth, $height_old - 2 * $cropHeight); # Taking care of original, if needed if ( $delete_original ) { if ( $use_linux_commands ) exec('rm '.$file); else @unlink($file); } # Preparing a method of providing result switch ( strtolower($output) ) { case 'browser': $mime = image_type_to_mime_type($info[2]); header("Content-type: $mime"); $output = NULL; break; case 'file': $output = $file; break; case 'return': return $image_resized; break; default: break; } # Writing image according to type to the output destination and image quality $info[2]= IMAGETYPE_PNG; switch ( $info[2] ) { case IMAGETYPE_GIF: imagegif($image_resized, $output); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $output, $quality); break; case IMAGETYPE_PNG: $quality = 9 - (int)((0.9*$quality)/10.0); imagepng($image_resized, $output, $quality); break; default: return false; } return true; } public function getActiveWahl(){ if(!$this->id_client){ $this->setClient(); } $wahl = new wahl(); //error_log("getActiveWahl Kunde ist ".$this->id_client); $wahlen = $wahl->loadByKunde($this->id_client." ORDER BY wahl_termin ASC LIMIT 1");{ if($wahlen){ //no smarty yet: $this->smarty->assign("isParty",(current($wahlen)->getenable_lists() == 1)); //$_SESSION['isParty'] = (current($wahlen)->getenable_lists() == 1); error_log("current wahl is: ".current($wahlen)->getid()); return current($wahlen)->getid(); }else return 1; } } public function selectWahl($val){ $objResponse = new xajaxResponse(); $_SESSION['admin_id_wahl'] = $val; $objResponse->script("location.reload()"); return $objResponse; } public static function getRevision($file){ $file = KK_HTDOCS_PATH.$file; if(file_exists($file)){ return md5_file($file); } return "not-found"; } public function getConsent($service){ $data = $_SESSION['consent']; if($data){ if($data[$service]){ return true; } } } public function registerGlobalXajaxFunctions(){ $this->xajax->register(XAJAX_FUNCTION,array("consent", &$this, "consent")); $this->xajax->register(XAJAX_FUNCTION,array("consentAll", &$this, "consentAll")); $this->xajax->register(XAJAX_FUNCTION,array("consentNone", &$this, "consentNone")); } public function consentNone(){ $objResponse = new xajaxResponse(); $data = new stdClass(); $data->services = ['youtube' => false, "twitter" => false]; setcookie("consent",json_encode($data),time() + 60*60*24*900); $objResponse->script("$('#consentModal').modal('hide');window.location.reload();"); return $objResponse; } public function consentAll(){ $objResponse = new xajaxResponse(); $data = $_COOKIE['consent']; $data = new stdClass(); $data->services = ['youtube' => true, "twitter" => true]; setcookie("consent",json_encode($data),time() + 60*60*24*900); $objResponse->script("$('#consentModal').modal('hide');window.location.reload();"); return $objResponse; } public function consent($services){ $objResponse = new xajaxResponse(); $data = new stdClass(); $data->services = []; foreach ($services as $s) { error_log("adding $s to ".print_r($data,true)); $data->services[$s] = true; } error_log(print_r($data,true)); setcookie("consent",json_encode($data),time() + 60*60*24*900); $objResponse->script("$('#consentModal').modal('hide');window.location.reload();"); return $objResponse; } }checkUsersAccess("profil")){ header("Location:/login"); exit(); } $this->xajax = new xajax(); //$this->xajax->setFlag('debug',true); $this->xajax->configure('javascript URI','/'); $this->xajax->configure('requestURI', "/?p=profil"); $this->registerGlobalXajaxFunctions(); $this->xajax->register(XAJAX_FUNCTION,array("doLogout", &$this, "doLogout")); $this->xajax->register(XAJAX_FUNCTION,array("sayHello", &$this, "sayHello")); $this->xajax->processRequest(); if(isset($_GET['ort'])){ $this->ort_slug = filter_var($_GET['ort'],FILTER_SANITIZE_STRING); } if(isset($_GET['wahl'])){ $this->wahl_slug = filter_var($_GET['wahl'],FILTER_SANITIZE_STRING); } if(isset($_GET['kandidat'])){ $this->kandidat_slug = filter_var($_GET['kandidat'],FILTER_SANITIZE_STRING); } if(isset($_GET['isParty'])){ $this->isParty = true; } } public function sayHello(){ $objResponse = new xajaxResponse(); $objResponse->script("console.log('Hello!')"); return $objResponse; } public function display(){ if($this->enable_display){ $this->smarty->assign("page","profil"); $this->smarty->assign("xajax_js",$this->xajax->getJavascript()); $this->smarty->assign("get",$_GET); //$this->smarty->assign('onload',array('alert("Funktioniert!");')); if(isset($this->id_client)){ $this->id_wahl = $this->getActiveWahl(); }else{ die('Keine Kunden ID vorhanden.'); } $wahl = new wahl(); $wahl->load($this->id_wahl); $this->smarty->assign("wahl",$wahl); $ok=false; if($this->isParty){ $partei = new partei(); $partei = $partei->loadBySlug($this->ort_slug, $this->wahl_slug, $this->kandidat_slug); // if($partei->getstatus() == KK_PARTY_APPROVED || (isset($_SESSION['user']) && $kandidat->getid_user() == $_SESSION['user']->getid()) || (isset($_SESSION['user']) && $_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA)) ){ //TODO: Partei-Admins auch rein lassen if($partei){ if($partei->getstatus() == KK_PARTY_APPROVED || (isset($_SESSION['user']) && ($_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA) || ($_SESSION['user']->hasRight(KK_ACCESS_CANDIDATE) && $_SESSION['user']->getKandidat()->getid_partei() == $partei->getid() ) )) ){ $admins = $partei->getPartyAdmins(); $kandidat = current($admins); $ok= true; $this->smarty->assign("isParty",true); //Direkt-Kandidaten der Liste holen $direct_candidates = $partei->getPartyCandidates($this->id_wahl,true); $this->smarty->assign("party_direct_kandidaten",$direct_candidates); //Kandidaten der Liste holen $candidates = $partei->getPartyCandidates($this->id_wahl); $this->smarty->assign("party_kandidaten",$candidates); } } }else{ $kandidat = new kandidat(); $kandidat = $kandidat->loadBySlug($this->ort_slug, $this->wahl_slug, $this->kandidat_slug); if($kandidat && $wahl->getid() != 7){ if($kandidat->getstatus() == KK_CANDIDATE_APPROVED || (isset($_SESSION['user']) && $kandidat->getid_user() == $_SESSION['user']->getid()) || (isset($_SESSION['user']) && ($_SESSION['user']->hasRight(KK_ACCESS_ADMINAREA) || $_SESSION['user']->hasRight(KK_ACCESS_SEE_INACTIVE) || ($_SESSION['user']->hasRight(KK_ACCESS_PARTY) && $_SESSION['user']->getKandidat()->getid_partei() == $kandidat->getid_partei())) )){ $ok = true; $this->smarty->assign("isParty",false); } } } if($ok){ $this->smarty->assign("k",$kandidat); $additionalPics = $kandidat->getAdditionalMedia(); if(sizeof($additionalPics)){ $this->smarty->assign("additionalPics",$additionalPics); } $this->smarty->assign("token",$kandidat->getToken()); $antwort = new antwort(); $this->smarty->assign("antwort",$antwort); $frage = new frage(); $fragen = $frage->selectAll("2 AND id_wahl = ".$this->id_wahl." ORDER BY reihenfolge ASC","frage_typ"); $answers = array(); foreach ($fragen as $f){ $quote_frage = new frage(); $quote_frage->select($f->getreihenfolge()." AND frage_typ = 4 AND id_wahl = ".$this->id_wahl,"reihenfolge"); $quote_antwort = new antwort(); $quote_antwort->loadByFrageKandidat($quote_frage->getid(), $kandidat->getid()); $ans = new antwort(); if($ans->loadByFrageKandidat($f->getid(), $kandidat->getid()) && !empty($ans->getantwort_text())){ $answers[2][] = array("frage" => $f, "antwort" => $ans, "quote" => $quote_antwort); } } $frage = new frage(); foreach(array(3,5) as $i){ $fragen = $frage->selectAll($i." AND id_wahl = ".$this->id_wahl." ORDER BY reihenfolge ASC","frage_typ"); foreach ($fragen as $f){ $ans = new antwort(); if($ans->loadByFrageKandidat($f->getid(), $kandidat->getid()) && !empty($ans->getantwort_text())){ $answers[$i][] = array("frage" => $f, "antwort" => $ans); } } } //error_log(print_r($answers,true)); $this->smarty->assign("antworten",$answers); }else{ error_log("candidate not approved"); header("Location:/login"); exit(); } $this->smarty->display('profil.tpl'); } } }