setLanguage("et_EE.UTF-8", "et_EE.UTF-8"); $tr->addDomain('kesa', 'i18n'); $tr->useDomain('kesa'); $this->translator = $tr; } function finalize() { $templ = new PHPTAL(); $templ->setTemplateRepository("templates/"); $templ->setTemplate($this->page); $templ->setTranslator($this->getTranslator()); $templ->here = $this; $templ->request = $_GET; $templ->data = $this->data; $templ->choices = $this->choices; print $templ->execute(); } function getTranslator() { return $this->translator; } function getCategories() { global $kdb; return $kdb->getCategories(); } function getQuestions() { global $kdb; return $kdb->getQuestions(); } } if ( isset($_POST['actionCreateCategory']) ) { $cnr = $_POST['nr']; $category = $_POST['title']; $kdb->query("INSERT INTO categories (nr, title) VALUES (".$cnr.", '".$category."')"); } if ( isset($_POST['actionSave']) ) { global $kdb; $qnr = $_POST['qnr']; $category = $_POST['category']; $q_ind = $_POST['q_ind']; $q_org = $_POST['q_org']; $q_type = $_POST['q_type']; $kdb->setQuestion($qnr, $category, $q_org, $q_ind, $q_type); for ($i=1; $i<=5; $i++) { $variants = false; if ($q_type == 1 || $q_type == 2) { if (isset($_POST['q_type_'.$q_type.'_'.$i]) && $_POST['q_type_'.$q_type.'_'.$i]!=""){ $variants = array('answer'=>$_POST['q_type_'.$q_type.'_'.$i], 'prefix'=>'', 'sufix'=>'', 'next'=>$_POST['q_type_n_'.$q_type.'_'.$i]); } } else if ($q_type == 3 || $q_type == 4) { if (isset($_POST['q_type_p_'.$q_type.'_'.$i]) || isset($_POST['q_type_s_'.$q_type.'_'.$i])){ if ( $_POST['q_type_p_'.$q_type.'_'.$i]!="" || $_POST['q_type_s_'.$q_type.'_'.$i]!="" ){ $variants = array('answer'=>'', 'prefix'=>$_POST['q_type_p_'.$q_type.'_'.$i], 'sufix'=>$_POST['q_type_s_'.$q_type.'_'.$i], 'next'=>$_POST['q_type_n_'.$q_type.'_'.$i]); } } } $kdb->setChoices($qnr, $i, $variants); } if (isset($_POST['delete_image'])) { $ret = $kdb->query("DELETE FROM images WHERE questionnr=".$qnr); } $imgfile = ""; if ( isset($_FILES['imgfile']) && is_uploaded_file($_FILES['imgfile']['tmp_name']) ) { $imsize = getimagesize($_FILES['imgfile']['tmp_name']); if ( $imsize != false ) { $filename = basename($_FILES['imgfile']['name']); $ulfile = $_FILES['imgfile']['tmp_name']; $hndl=fopen($_FILES['imgfile']['tmp_name'],"r"); $imgdata=""; while(!feof($hndl)){ $imgdata.=fread($hndl,$imsize); }; fclose($hndl); // resize $maxwidth=200; $maxheight=150; $imm = imagecreatefromstring($imgdata); $currwidth=imagesx($imm); $currheight=imagesy($imm); if ( $currheight > $maxheight ) { $zoom = $maxheight/$currheight; $newwidth = $currwidth*$zoom; $newheight = $currheight*$zoom; } if ( $newwidth > $maxwidth ) { $zoom = $maxwidth/$newwidth; $newwidth = $currwidth*$zoom; $newheight = $currheight*$zoom; } $t_im = imageCreateTrueColor($newwidth,$newheight); imageCopyResampled($t_im, $imm, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); imagejpeg($t_im, $ulfile."_thumb"); $nhndl=fopen($ulfile."_thumb","r"); $nimsize = getimagesize($ulfile."_thumb"); $nimgdata=""; while(!feof($nhndl)){ $nimgdata.=fread($nhndl,$nimsize); }; $nimgdata=addslashes($nimgdata); fclose($nhndl); $ret = $kdb->query("SELECT questionnr FROM images WHERE questionnr=".$qnr); if (mysql_num_rows($ret)>0) { $kdb->query("UPDATE images SET filename='".$filename."', imgfile='".$nimgdata."' WHERE questionnr=".$qnr); } else { $kdb->query("INSERT INTO images (questionnr, filename, imgfile) VALUES (".$qnr.", '".$filename."', '".$nimgdata."')"); } } } } $kesaadmin = new KesaAdmin(); if ( isset( $_GET['category'] ) ) { $kesaadmin->page = "categories.html"; } else if ( isset($_GET['question']) && is_numeric($_GET['question']) ) { global $kdb; $kesaadmin->data = $kdb->getQuestionByNr($_GET['question']); $kesaadmin->choices = $kdb->getChoicesByQuestion($_GET['question']); $kesaadmin->page = "question.html"; } else { $kesaadmin->page = "admin.html"; } $kesaadmin->finalize(); ?>