function txtonimg($src, $str, $color, $x, $y) { $font = 'ANGSAZ.TTF'; $string = $str; // String $filename = basename($src); $ext = getExtension($filename); if (strtolower($ext) == "gif") { $im = imagecreatefromgif($src); } elseif (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg") { $im = imagecreatefromjpeg($src); } elseif (strtolower($ext) == "png") { $im = imagecreatefrompng($src); } // Path Images $color = ImageColorAllocate($im, 255, 255, 255); // Text Color $pxX = (Imagesx($im) - 4 * strlen($string)) / 2; // X $pxY = Imagesy($im) - 10; // Y ImagettfText($im, 20, 0, $pxX, $pxY, $color, $font, $string); if (strtolower($ext) == "gif") { imagegif($src); } elseif (strtolower($ext) == "jpg" || strtolower($ext) == "jpeg") { imagejpeg($src); } elseif (strtolower($ext) == "png") { imagepng($src); } ImageDestroy($im); }
/** * make_captcha * Make the captcha picture * * @return string Captcha image (relative path) */ function make_captcha() { // Delete expired captcha pictures $this->_delete_expired_files(); // Get the turing key string $turing_key = $this->generate_turing_key(); $image = $this->_imagecreate($this->width, $this->height); // Background color $back = ImageColorAllocate($image, intval(mt_rand($this->background_color_start, $this->background_color_end)), intval(mt_rand($this->background_color_start, $this->background_color_end)), intval(mt_rand($this->background_color_start, $this->background_color_end))); ImageFilledRectangle($image, 0, 0, $this->width, $this->height, $back); // Create background image if ($this->background_pattern != 'grid') { for ($i = 0; $i < $this->nb_noise; $i++) { $size = intval(mt_rand(10, 35)); $angle = intval(mt_rand(0, 360)); $x = intval(mt_rand(10, $this->width + 10)); $y = intval(mt_rand(10, $this->height + 10)); $color = ImageColorAllocate($image, intval(mt_rand(180, 220)), intval(mt_rand(180, 220)), intval(mt_rand(180, 220))); $text = chr(intval(mt_rand(32, 255))); ImagettfText($image, $size, $angle, $x, $y, $color, $this->_font, $text); } } else { for ($i = intval(mt_rand(2, 6)); $i < $this->width; $i += intval(mt_rand(5, 12))) { $color = imagecolorallocate($image, intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor)), intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor)), intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor))); imageline($image, $i, 0, $i, $this->height, $color); } for ($i = intval(mt_rand(2, 6)); $i < $this->height; $i += intval(mt_rand(5, 12))) { $color = imagecolorallocate($image, intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor)), intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor)), intval(mt_rand($this->grid_start_rcolor, $this->grid_end_rcolor))); imageline($image, 0, $i, $this->width, $i, $color); } } //Create turing key image for ($i = 0, $x = 3; $i < $this->string_len; $i++) { $r = intval(mt_rand(0, 100)); $g = intval(mt_rand(0, 100)); $b = intval(mt_rand(0, 100)); $color = ImageColorAllocate($image, $r, $g, $b); $shadow = ImageColorAllocate($image, $r + intval(mt_rand(90, 128)), $g + intval(mt_rand(90, 128)), $b + intval(mt_rand(90, 128))); $size = intval(mt_rand($this->font_start_rsize, $this->font_start_rsize)); $angle = intval(mt_rand($this->char_rangle_start, $this->char_rangle_end)); $text = strtoupper(substr($turing_key, $i, 1)); $y = intval(mt_rand(23, 28)); if ($this->shadow == TRUE) { ImagettfText($image, $size, $angle, $x + intval(mt_rand(1, 3)), $y + intval(mt_rand(1, 3)), $shadow, $this->_font, $text); } ImagettfText($image, $size, $angle, $x, $y, $color, $this->_font, $text); $x += $size + intval(mt_rand($this->char_rspace_start, $this->char_rspace_end)); } ImageJPEG($image, $this->get_filename(), 100); ImageDestroy($image); return $this->_captcha_pic_folder . '/' . $this->public_key . '.jpg'; }
public function isepdorPage($param) { $this->setView('isepdor.php'); $questions = $this->model->getquestions(); for ($i = 0; $i < count($questions); $i++) { $type = explode(',', $questions[$i]["type"]); $tab = array("students", "associations", "employees", "events"); $result = array_intersect($type, $tab); if (in_array("students", $result)) { $questions[$i]["students"] = 1; } else { $questions[$i]["students"] = 0; } if (in_array("events", $result)) { $questions[$i]["events"] = 1; } else { $questions[$i]["events"] = 0; } if (in_array("associations", $result)) { $questions[$i]["associations"] = 1; } else { $questions[$i]["associations"] = 0; } if (in_array("employees", $result)) { $questions[$i]["employees"] = 1; } else { $questions[$i]["employees"] = 0; } if ($questions[$i]["extra"] == null) { $questions[$i]["extra"] = " "; } } $events = $this->model->getevents(); for ($i = 0; $i < count($events); $i++) { if ($events[$i]['extra'] == "soiree") { $events[$i]['extra'] = 1; } else { $events[$i]['extra'] = 0; } } $myFile = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "/diplome.json"; $file = fopen($myFile, 'r'); $positions = fread($file, filesize($myFile)); fclose($file); $this->addJSCode(' Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcore.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdata.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxbuttons.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxscrollbar.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxmenu.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.edit.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.selection.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.sort.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.filter.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.columnsresize.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxlistbox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdropdownlist.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcheckbox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcombobox.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxgrid.pager.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdragdrop.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxcalendar.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtooltip.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxdatetimeinput.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.global.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jquery.glob.fr-FR.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/jqx/jqxtabs.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.Jcrop.min.js","js"); Admin.loadjscssfile("' . Config::URL_STATIC . 'js/crop/jquery.color.js","js"); jQuery(document).ready(function () { diplomeData=new Array(); Admin.loadTab(); Admin.loadCrop(); Admin.loadCatGrid(' . json_encode($questions) . '); Admin.loadEventGrid(' . json_encode($events) . '); Admin.loadEmployGrid(' . json_encode($this->model->getemployees()) . '); Admin.loadDate(' . json_encode($this->model->getDate()) . '); jQuery(".jcrop-holder").ready(function () { Admin.loadDiplome(' . $positions . '); }); jQuery("#adminIsepdorTab").removeClass("hidden"); }); '); /* Code qui met à jour le questionnaire pour les ISEP D'or * */ if (isset($_POST['categories'])) { $id = array(); $post = json_decode($_POST['categories'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorQuestions($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteQuestions($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { if ($post[$i]['extra'] == "") { $post[$i]['extra'] = NULL; } if ($post[$i]['id'] != "") { $this->model->updateisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['id'], $post[$i]['position']); } elseif ($post[$i]['id'] == "") { $this->model->insertisepdor($post[$i]['type'], $post[$i]['extra'], $post[$i]['questions'], $post[$i]['position']); } } } /*Code qui met à jour la table isepdor_employees * */ if (isset($_POST['employees'])) { $id = array(); $post = json_decode($_POST['employees'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorEmployees($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteEmployees($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { $username = $this->makeusername($post[$i]['lastname'], $post[$i]['firstname']); if ($post[$i]['id'] != "") { $this->model->updateEmployees($post[$i]['lastname'], $post[$i]['firstname'], $post[$i]['id'], $username); } elseif ($post[$i]['id'] == "") { $this->model->insertemployees($post[$i]['lastname'], $post[$i]['firstname'], $username); } } } /*Code qui met à jour la table isepdor_event * */ if (isset($_POST['events'])) { $id = array(); $post = json_decode($_POST['events'], true); for ($i = 0; $i < count($post); $i++) { if (is_numeric($post[$i]['id'])) { array_push($id, $post[$i]['id']); } } $toDelete = $this->model->checkIsepdorEvents($id); if (count($toDelete) > 0) { for ($i = 0; $i < count($toDelete); $i++) { $this->model->deleteEvents($toDelete[$i]); } } for ($i = 0; $i < count($post); $i++) { if ($post[$i]['extra'] == 1) { $post[$i]['extra'] = "soiree"; } else { $post[$i]['extra'] = NULL; } if ($post[$i]['id'] != "") { $this->model->updateEvent($post[$i]['name'], $post[$i]['id'], $post[$i]['extra']); } elseif ($post[$i]['id'] == "") { $this->model->insertEvent($post[$i]['name'], $post[$i]['extra']); } } } /*Code qui met à jour les date de vote des isep d'or * */ if (isset($_POST['dates'])) { $post = json_decode($_POST['dates'], true); $this->model->insertDate($post[0][0], $post[0][1], $post[1][0], $post[1][1], $post[2][0], $post[2][1]); } /* * Change l'image diplome */ if (isset($_FILES['diplome']) && !is_array($_FILES['diplome']['name'])) { if ($_FILES['diplome']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) { throw new FormException('size'); } if ($avatarpath = File::upload('diplome')) { $uploaded_files[] = $avatarpath; try { $img = new Image(); $img->load($avatarpath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getHeight() != 794 || $img->getWidth() != 1122) { throw new FormException('width'); } $img->setType($type); $img->save($avatarpath); unset($img); if (isset($avatarpath) && File::exists($avatarpath)) { $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png"; $avatar_dir = File::getPath($avatar_path) . "/diplomeIsepDOr9652.png"; File::rename($avatarpath, $avatar_dir); } } catch (FormException $e) { $this->set('form_error', $e->getError()); } foreach ($uploaded_files as $uploaded_file) { File::delete($uploaded_file); } } Post_Model::clearCache(); } /* * Enregistre les coordonnées */ if (isset($_POST['diplomeData'])) { $post = $_POST['diplomeData']; $file = fopen($myFile, 'w'); fwrite($file, $post); fclose($file); } /* * Envoie les diplomes */ if (isset($_GET['getDiplome'])) { $template = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "diplomeIsepDOr9652.png"; $font = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf"; $files = array(); $positions = json_decode($positions, true); //récupere les coordonnées précédament demandées for ($i = 0; $i < count($positions); $i++) { $coord[$positions[$i]['index']] = $positions[$i]; } $questions = IsepOr_Model::fetchQuestions(); foreach ($questions as $value) { if (strpos($value['type'], ',')) { $data = array(); foreach (explode(',', $value['type']) as $type) { $data = IsepOr_Controller::__array_rePad($data, IsepOr_Model::fetchFinals($value['id'], $type, 2)); } $finalList[$value['id']] = array_slice(IsepOr_Controller::__array_orderby($data, 'cmpt', SORT_DESC), 0, 3); } else { $finalList[$value['id']] = IsepOr_Model::fetchFinals($value['id'], $value['type'], 2); } } for ($i = 0; $i < count($questions); $i++) { for ($j = 0; $j < count($finalList[$questions[$i]['id']]); $j++) { File::copy($template, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); array_push($files, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); $im = ImageCreateFromPng(DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png"); // Path Images $color = ImageColorAllocate($im, 0, 0, 0); // Text Color $champs[0] = $questions[$i]['questions']; $champs[1] = $finalList[$questions[$i]['id']][$j]["name"]; $champs[2] = ""; if (!is_numeric($finalList[$questions[$i]['id']][$j]["valid"])) { $champs[2] = $this->model->getBirthDay($finalList[$questions[$i]['id']][$j]["valid"]); } for ($a = 0; $a < 3; $a++) { $pxX = round($coord[$a]['x1']); // X $pxY = round($coord[$a]['y2']); // Y ImagettfText($im, round($coord[$a]['h']), 0, $pxX, $pxY, $color, $font, $champs[$a]); } imagePng($im, DATA_DIR . Config::DIR_DATA_TMP . "diplome" . $i . $j . ".png", 9); ImageDestroy($im); if ($finalList[$questions[$i]['id']][$j]['cmpt'] != $finalList[$questions[$i]['id']][$j + 1]['cmpt']) { break; } } } if (self::create_zip($files, DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip", true)) { foreach ($files as $file) { File::delete($file); } header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); header("Cache-Control: public"); // needed for i.e. header("Content-Type: application/zip"); header("Content-Transfer-Encoding: Binary"); header("Content-Length:" . filesize(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip")); header("Content-Disposition: attachment; filename=diplomesIsepDor.zip"); readfile(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip"); File::delete(DATA_DIR . Config::DIR_DATA_TMP . "diplomesIsepDor.zip"); die; } foreach ($files as $file) { File::delete($file); } } /*Code qui export les résultats des isep d'or * */ if (isset($_GET['export'])) { $db = $this->model->getResult(); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: filename=' . 'Résultats_Isepdor' . '.xls'); header('Pragma: no-cache'); header('Expires: 0'); print '<table border=1 > <!-- impression des titres de colonnes --> <TR> <TD bgcolor="#3366CC">Tour</TD> <TD bgcolor="#3366CC">Nom du votant</TD> <TD bgcolor="#3366CC">Catégorie</TD> <TD bgcolor="#3366CC">Réponse(student)</TD> <TD bgcolor="#3366CC">Réponse(admin)</TD> <TD bgcolor="#3366CC">Réponse(assoce)</TD> <TD bgcolor="#3366CC">Réponse(event)</TD> </TR> '; foreach ($db as $champs) { print '<TR>'; print '<TD>' . $champs['round'] . '</TD>'; print '<TD>' . $champs['username'] . '</TD>'; print '<TD>' . utf8_decode($champs['questions']) . '</TD>'; print '<TD>' . $champs['student_username'] . '</TD>'; print '<TD>' . utf8_decode($champs['admin']) . '</TD>'; print '<TD>' . utf8_decode($champs['assoce']) . '</TD>'; print '<TD>' . utf8_decode($champs['name']) . '</TD>'; print '</TR>'; } print '</table>'; exit; } /* * Ajout de la police */ if (isset($_FILES['font']) && $_FILES['font']['name'] != null) { if ($_FILES['font']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } if ($filepaths = File::upload('font')) { if (!preg_match('#\\.ttf$#i', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $avatar_path = DATA_DIR . Config::DIR_DATA_STORAGE . Config::DIR_DATA_ADMIN . "font2354.ttf"; $avatar_dir = File::getPath($avatar_path) . "/font2354.ttf"; File::rename($filepaths, $avatar_dir); } else { throw new Exception(__('ADMIN_UPLOAD_ERROR')); } } /*Code qui met supprime les champs de la table résultat des isep d'or * */ if (isset($_GET['delete_result'])) { $this->model->deleteresult(); header("Location: " . Config::URL_ROOT . Routes::getPage('admin', array("nav" => "isepdor"))); } }