Estou utilizando um sistema de Ambiente Virtual de Aprendizagem chamado E-Front. Excelente Sistema.
Instalei um módulo para gerar certificados de conclusão, mas ele não gera caso o título do curso ou nome do aluno possuam acentos (áéíóú, ãõ, etc).
Já tentei de tudo, verifiquei que existe um arquivo chamado encryt.php que reconhece como caracteres inválidos caso o nome possua acento.
Será que alguém pode me ajudar a resolver isso?
Segue os códigos do módulo (module_pdfcert):
encrypt.php
<?php
// ******************************************************************************
// A reversible password encryption routine by:
// Copyright 2003-2009 by A J Marston <http://www.tonymarston.net>
// Distributed under the GNU General Public Licence
// Modification: May 2007, M. Kolar <http://mkolar.org>:
// No need for repeating the first character of scramble strings at the end;
// instead using the exact inverse function transforming $num2 to $num1.
// Modification: Jan 2009, A J Marston <http://www.tonymarston.net>:
// Use mb_substr() if it is available (for multibyte characters).
// ******************************************************************************
class encryption_class {
var $scramble1; // 1st string of ASCII characters
var $scramble2; // 2nd string of ASCII characters
var $errors; // array of error messages
var $adj; // 1st adjustment value (optional)
var $mod; // 2nd adjustment value (optional)
// ****************************************************************************
// class constructor
// ****************************************************************************
function encryption_class ()
{
$this->errors = array();
// Each of these two strings must contain the same characters, but in a different order.
// Use only printable characters from the ASCII table.
// Do not use single quote, double quote or backslash as these have special meanings in PHP.
// Each character can only appear once in each string.
$this->scramble1 = '! #$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$this->scramble2 = 'f^jAE]okIOzU[2&q1{3`h5w_794p@6s8?BgP>dFV=m D<TcS%Ze|r:lGK/uCy.Jx)HiQ!#$~(;Lt-R}Ma,NvW+Ynb*0X';
if (strlen($this->scramble1) <> strlen($this->scramble2)) {
trigger_error('** SCRAMBLE1 is not same length as SCRAMBLE2 **', E_USER_ERROR);
} // if
$this->adj = 1.75; // this value is added to the rolling fudgefactors
$this->mod = 3; // if divisible by this the adjustment is made negative
} // constructor
// ****************************************************************************
function decrypt ($key, $source)
// decrypt string into its original form
{
$this->errors = array();
// convert $key into a sequence of numbers
$fudgefactor = $this->_convertKey($key);
if ($this->errors) return;
if (empty($source)) {
$this->errors[] = 'No value has been supplied for decryption';
return;
} // if
$target = null;
$factor2 = 0;
for ($i = 0; $i < strlen($source); $i++) {
// extract a (multibyte) character from $source
if (function_exists('mb_substr')) {
$char2 = mb_substr($source, $i, 1);
} else {
$char2 = substr($source, $i, 1);
} // if
// identify its position in $scramble2
$num2 = strpos($this->scramble2, $char2);
if ($num2 === false) {
$this->errors[] = "Source string contains an invalid character ($char2)";
return;
} // if
// get an adjustment value using $fudgefactor
$adj = $this->_applyFudgeFactor($fudgefactor);
$factor1 = $factor2 + $adj; // accumulate in $factor1
$num1 = $num2 - round($factor1); // generate offset for $scramble1
$num1 = $this->_checkRange($num1); // check range
$factor2 = $factor1 + $num2; // accumulate in $factor2
// extract (multibyte) character from $scramble1
if (function_exists('mb_substr')) {
$char1 = mb_substr($this->scramble1, $num1, 1);
} else {
$char1 = substr($this->scramble1, $num1, 1);
} // if
// append to $target string
$target .= $char1;
//echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";
} // for
return rtrim($target);
} // decrypt
// ****************************************************************************
function encrypt ($key, $source, $sourcelen = 0)
// encrypt string into a garbled form
{
$this->errors = array();
// convert $key into a sequence of numbers
$fudgefactor = $this->_convertKey($key);
if ($this->errors) return;
if (empty($source)) {
$this->errors[] = 'No value has been supplied for encryption';
return;
} // if
// pad $source with spaces up to $sourcelen
$source = str_pad($source, $sourcelen);
$target = null;
$factor2 = 0;
for ($i = 0; $i < strlen($source); $i++) {
// extract a (multibyte) character from $source
if (function_exists('mb_substr')) {
$char1 = mb_substr($source, $i, 1);
} else {
$char1 = substr($source, $i, 1);
} // if
// identify its position in $scramble1
$num1 = strpos($this->scramble1, $char1);
if ($num1 === false) {
$this->errors[] = "Source string contains an invalid character ($char1)";
return;
} // if
// get an adjustment value using $fudgefactor
$adj = $this->_applyFudgeFactor($fudgefactor);
$factor1 = $factor2 + $adj; // accumulate in $factor1
$num2 = round($factor1) + $num1; // generate offset for $scramble2
$num2 = $this->_checkRange($num2); // check range
$factor2 = $factor1 + $num2; // accumulate in $factor2
// extract (multibyte) character from $scramble2
if (function_exists('mb_substr')) {
$char2 = mb_substr($this->scramble2, $num2, 1);
} else {
$char2 = substr($this->scramble2, $num2, 1);
} // if
// append to $target string
$target .= $char2;
//echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n";
} // for
return $target;
} // encrypt
// ****************************************************************************
function getAdjustment ()
// return the adjustment value
{
return $this->adj;
} // setAdjustment
// ****************************************************************************
function getModulus ()
// return the modulus value
{
return $this->mod;
} // setModulus
// ****************************************************************************
function setAdjustment ($adj)
// set the adjustment value
{
$this->adj = (float)$adj;
} // setAdjustment
// ****************************************************************************
function setModulus ($mod)
// set the modulus value
{
$this->mod = (int)abs($mod); // must be a positive whole number
} // setModulus
// ****************************************************************************
// private methods
// ****************************************************************************
function _applyFudgeFactor (&$fudgefactor)
// return an adjustment value based on the contents of $fudgefactor
// NOTE: $fudgefactor is passed by reference so that it can be modified
{
$fudge = array_shift($fudgefactor); // extract 1st number from array
$fudge = $fudge + $this->adj; // add in adjustment value
$fudgefactor[] = $fudge; // put it back at end of array
if (!empty($this->mod)) { // if modifier has been supplied
if ($fudge % $this->mod == 0) { // if it is divisible by modifier
$fudge = $fudge * -1; // make it negative
} // if
} // if
return $fudge;
} // _applyFudgeFactor
// ****************************************************************************
function _checkRange ($num)
// check that $num points to an entry in $this->scramble1
{
$num = round($num); // round up to nearest whole number
$limit = strlen($this->scramble1);
while ($num >= $limit) {
$num = $num - $limit; // value too high, so reduce it
} // while
while ($num < 0) {
$num = $num + $limit; // value too low, so increase it
} // while
return $num;
} // _checkRange
// ****************************************************************************
function _convertKey ($key)
// convert $key into an array of numbers
{
if (empty($key)) {
$this->errors[] = 'No value has been supplied for the encryption key';
return;
} // if
$array[] = strlen($key); // first entry in array is length of $key
$tot = 0;
for ($i = 0; $i < strlen($key); $i++) {
// extract a (multibyte) character from $key
if (function_exists('mb_substr')) {
$char = mb_substr($key, $i, 1);
} else {
$char = substr($key, $i, 1);
} // if
// identify its position in $scramble1
$num = strpos($this->scramble1, $char);
if ($num === false) {
$this->errors[] = "Key contains an invalid character ($char)";
return;
} // if
$array[] = $num; // store in output array
$tot = $tot + $num; // accumulate total for later
} // for
$array[] = $tot; // insert total as last entry in array
return $array;
} // _convertKey
// ****************************************************************************
} // end encryption_class
// ****************************************************************************
?>
module_pdfcert.class.php
<?php
//===================
// For debugging, do the following:
// Open /libraries/globals.php
//
// comment error_reporting(E_ERROR);
// uncomment error_reporting(E_ALL); ini_set("display_errors",true);
//
// On about line 130 change define("G_DEBUG",0); to a value of 1
// comment out the line: $GLOBALS['db'] -> debug = true;
//
// smsoa / placitas
// Christine / nicks
//===================
require 'encrypt.php';
class module_pdfcert extends EfrontModule {
//--------------------------------------------------------
// Mandatory functions required for module function
//--------------------------------------------------------
public function getName() {
return _PDFCERT_TITLE;
}
//--------------------------------------------------------
// getPermittedRoles
// The certificate page will only appear
//--------------------------------------------------------
public function getPermittedRoles() {
return array('professor','student');
}
//--------------------------------------------------------
// Optional functions
// What should happen on installing the module
//--------------------------------------------------------
public function onInstall() {
return true;
}
//--------------------------------------------------------
// onUninstall
// When the module is uninstalled, delete the corresponding
// database tables.
//--------------------------------------------------------
public function onUninstall() {
return true;
}
//--------------------------------------------------------
// onDeleteLesson
// When a lesson is deleted, this method will delete the
// pdfcert records for the specified lesson.
//--------------------------------------------------------
public function onDeleteLesson($lessonId) {
return false;
}
//--------------------------------------------------------
// OnExportLesson
// This method is called when the user exports a lesson.
//--------------------------------------------------------
public function onExportLesson($lessonId) {
return false;
}
//--------------------------------------------------------
// onImportLesson
// This method is called when the user imports a lesson
//--------------------------------------------------------
public function onImportLesson($lessonId, $data) {
return false;
}
//--------------------------------------------------------
// getCenterLinkInfo
// Defines any links for the Administrator menu
//--------------------------------------------------------
public function getCenterLinkInfo() {
$optionArray = array('title' => _PDFCERT_TITLE,
'image' => $this -> moduleBaseDir.'images/certificate32.png',
'link' => $this -> moduleBaseUrl);
$centerLinkInfo = $optionArray;
return $centerLinkInfo;
}
//--------------------------------------------------------
// getLessonCenterLinkInfo
// Returns links for the defined users control panel.
//--------------------------------------------------------
public function getLessonCenterLinkInfo() {
return false;
}
//--------------------------------------------------------
// getSidebarLinkInfo
// This method defines the Menu Links that will appear by
// user and what menu they appear in. This code displays
// in the sidebar for professor and student.
//--------------------------------------------------------
public function getSidebarLinkInfo() {
$currentUser = $this -> getCurrentUser();
if($currentUser->getType() == "administrator"){}
if($currentUser->getType() == "professor"){}
else
{
//Menu will only appear for the student
$link_of_menu_lessons = array (array ('id' => 'other_link_id1',
'title' => 'Certificates',
'image' => $this -> moduleBaseDir . 'images/certificate16',
'eFrontExtensions' => '1',
'link' => $this -> moduleBaseUrl));
}
return array ( "tools" => $link_of_menu_lessons);
}
//--------------------------------------------------------
// getNavigationLinks
//--------------------------------------------------------
public function getNavigationLinks() {
return array (array ('title' => 'Meus Cursos',
'link' => 'student.php?ctg=lessons'),
array ('title' => _PDFCERT,
'link' => $this -> moduleBaseUrl));
}
//--------------------------------------------------------
// getLinkToHighlight
//--------------------------------------------------------
public function getLinkToHighlight() {
return 'module_pdfcert';
}
public function isLessonModule(){
return false;
}
//--------------------------------------------------------
// onCompleteLesson
//--------------------------------------------------------
public function onCompleteLesson($lessonId, $login) {
return false;
}
//--------------------------------------------------------
// getModule
// This method handles the all of the logic for the module.
//--------------------------------------------------------
public function getModule() {
// Get smarty variable
$smarty = $this -> getSmartyVar();
$currentLesson = $this -> getCurrentLesson();
$currentUser = $this -> getCurrentUser();
$currentLogin = $currentUser->login;
$smarty -> assign("T_PDFCERT_GENERATOR", $this->moduleBaseLink."certificates/certificate.php");
$smarty -> assign("T_PDFCERT_TARGET", $this->moduleBaseLink);
try {
$crypt = new encryption_class;
//Get the users Course
$aCourse = eF_getTableData("users_to_courses u inner join courses c on u.courses_ID = c.id",
"c.id as course_id, c.name, u.completed",
"users_LOGIN='".$currentLogin."' and u.archive = 0");
//print_r($aCourse);
//exit;
/*
$coursekey = null;
if($aCourse[0]['completed'] == 1)
{
$coursekey = $crypt->encrypt('ZIPPITYDOODAH', $currentUser->user['name'].'|'.$currentUser->user['surname'].'|'.$aCourse[0]['name'], 80);
$smarty -> assign("T_PDFCERT_COURSE_KEY", $coursekey);
}
*/
// Create an array to hold the courses this individual is in.
// If the course is marked as completed, encrypt the
for($cnt = 0; $cnt < count($aCourse); $cnt++)
{
if(intval($aCourse[$cnt][completed]) == 1)
{
$aTmp = array(
'id' => $aCourse[$cnt]['course_id'],
'name' => $aCourse[$cnt]['name'],
'enc' => $crypt->encrypt('ZIPPITYDOODAH', $currentUser->user['name'].'|'.$currentUser->user['surname'].'|'.$aCourse[0]['name'], 80)
);
}
else
{
$aTmp = array(
'id' => $aCourse[$cnt]['course_id'],
'name' => $aCourse[$cnt]['name'],
'enc' => ''
);
}
$aCourses[] = $aTmp;
}
$smarty -> assign("T_PDFCERT_COURSES", $aCourses); //Pass in the array of courses
//print_r($aCourses);
//echo "Get All Lessons";
//exit;
//$allLessons = eF_getTableData("courses as c inner join lessons_to_courses lc on c.id = lc.courses_ID inner join lessons as l on lc.lessons_ID = l.id inner join tests as t on t.lessons_ID = l.id left join completed_tests as ct on ct.tests_ID = t.id and ct.status != 'deleted' and ct.users_LOGIN = '".$currentLogin."'",
// "lc.courses_ID, lc.lessons_ID, l.name, t.mastery_score, ct.status, ct.score",
// "order by c.id, l.name asc");
//$sql = "select ".
// " uc.courses_ID,lc.lessons_ID , l.`name`, t.mastery_score, completed_tests.score ".
// "from ".
// " users_to_courses AS uc ".
// " INNER JOIN lessons_to_courses AS lc ON uc.courses_ID = lc.courses_ID ".
// " INNER JOIN lessons AS l ON l.id = lc.lessons_ID ".
// " LEFT JOIN tests AS t ON t.lessons_ID = lc.lessons_ID ".
// " LEFT JOIN completed_tests ON completed_tests.users_LOGIN = uc.users_LOGIN ".
// "where ".
// " uc.users_LOGIN = '".$currentLogin."' and uc.archive = 0 ".
// "order by ".
// " courses_ID, l.name asc";
//belen/1954, erma/bobby20, will_gina/tafoya5659
$sql = "SELECT ".
"users_to_courses.courses_ID, lessons.`name`, s.* ".
"FROM ".
"users_to_courses ".
"INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = '".$currentLogin."' AND users_to_courses.archive = 0 ".
"INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID ".
"left join ".
"(SELECT completed_tests.score, tests.mastery_score, completed_tests.archive, tests.lessons_ID FROM completed_tests INNER JOIN tests ON tests.id = completed_tests.tests_ID where users_LOGIN = '".$currentLogin."' and completed_tests.archive=0) AS s ".
"on lessons_to_courses.lessons_ID = s.lessons_ID ".
"order by ".
"users_to_courses.courses_ID, lessons.`name` asc";
$allLessons = $GLOBALS['db'] -> GetAll($sql);
//echo "Query for Lessons";
//print_r($allLessons);
//exit;
/* -----------------------------------------------------------------------------------
Note: Per periklis uc.archive = 0 means the student is in the course. A value in this
field indicates a timestamp when they were removed
SELECT
uc.courses_ID,
lc.lessons_ID,
l.`name`,
t.mastery_score,
completed_tests.score
FROM
users_to_courses AS uc
INNER JOIN lessons_to_courses AS lc ON uc.courses_ID = lc.courses_ID
INNER JOIN lessons AS l ON l.id = lc.lessons_ID
LEFT JOIN tests AS t ON t.lessons_ID = lc.lessons_ID
LEFT JOIN completed_tests ON completed_tests.users_LOGIN = uc.users_LOGIN
where
uc.users_LOGIN = 'student' and uc.active = 1
order by
courses_ID, l.name asc
SELECT DISTINCT
users_to_courses.courses_ID,
lessons.`name`, s.*
FROM
users_to_courses
INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = 'student' AND users_to_courses.archive = 0
INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID ,
(select completed_tests.score, tests.mastery_score, completed_tests.archive from completed_tests, tests where users_LOGIN = 'student' and completed_tests.archive=0) AS s
order by
users_to_courses.courses_ID, lessons.`name` asc
SELECT DISTINCT
users_to_courses.courses_ID,
lessons.`name`,
s.*
FROM
users_to_courses
INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = 'student' AND users_to_courses.archive = 0
INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID
left join
(SELECT completed_tests.score, tests.mastery_score, completed_tests.archive, tests.lessons_ID FROM completed_tests INNER JOIN tests ON tests.id = completed_tests.tests_ID where users_LOGIN = 'student' and completed_tests.archive=0) AS s
on lessons_to_courses.lessons_ID = s.lessons_ID
order by
users_to_courses.courses_ID, lessons.`name` asc
---------------------------------------------------------------------------------------*/
//print_r($allLessons);
//exit;
$aLessons = array();
foreach ($allLessons as $student_lesson)
{
$genkey = null;
if($student_lesson['score'] != "")
{
if(intval($student_lesson['score']) >= intval($student_lesson['mastery_score']))
{
$fname = str_replace("'","$",$currentUser->user['name']);
$smarty -> assign("T_FNAME",$fname);
$lname = str_replace("'","$",$currentUser->user['surname']);
$smarty -> assign("T_LNAME",$lname);
$crs = str_replace("'","$",$student_lesson['name']);
$genkey = $crypt->encrypt('ZIPPITYDOODAH', $fname.'|'.$lname.'|'.$crs, 80);
}
else
{
$genkey = null;
}
}
$errors = $crypt->errors;
$lsson = str_replace(" EXAM",'',$student_lesson['name']);
$aLessons[] = array("courses_ID"=>$student_lesson['courses_ID'],
"lessons_ID"=>$student_lesson['lessons_ID'],
"users_LOGIN"=>$student_lesson['users_LOGIN'],
"name"=>$lsson,
"score"=>$student_lesson['score'],
"genkey"=>$genkey);
}
//print_r($aLessons);
//exit;
$smarty -> assign("T_PDFCERT_LESSONS", $aLessons);
$smarty -> assign("T_STUDENT_NAME", $currentUser-> user['name'].' '.$currentUser-> user['surname']);
$err = '';
foreach($errors as $error)
{
$err = $err.$error.'<br/>';
}
$smarty -> assign("T_PDFCERT_GENERR", $err);
return true;
}
catch (Exception $e){
$currentUser = EfrontUserFactory :: factory($_SESSION['s_login']);
$role = $currentUser -> getRole($this -> getCurrentLesson());
}
}
//--------------------------------------------------------
// getSmartyTpl
// Used to return the Smarty Template. In this case,
// module.tpl is selected. Values are passed into the
// smarty template.
//--------------------------------------------------------
public function getSmartyTpl() {
$smarty = $this -> getSmartyVar();
$smarty -> assign("T_PDFCERT_MODULE_BASEDIR" , $this -> moduleBaseDir);
$smarty -> assign("T_PDFCERT_MODULE_BASELINK" , $this -> moduleBaseLink);
return $this -> moduleBaseDir . "module.tpl";
}
//--------------------------------------------------------
// getLessonModule
//--------------------------------------------------------
public function getLessonModule() {
return false;
}
//--------------------------------------------------------
// getControlPanelSmartyTpl
//--------------------------------------------------------
public function getControlPanelSmartyTpl() {
return false;
}
//--------------------------------------------------------
// getControlPanelModuleS
//--------------------------------------------------------
public function getControlPanelModule() {
return false;
}
//--------------------------------------------------------
// getLessonSmartyTpl
//--------------------------------------------------------
public function getLessonSmartyTpl() {
return false;
}
//--------------------------------------------------------
// getModuleCSS
//--------------------------------------------------------
public function getModuleCSS()
{
return false;
}
}
?>
Pergunta
fabio.schneider
Estou utilizando um sistema de Ambiente Virtual de Aprendizagem chamado E-Front. Excelente Sistema.
Instalei um módulo para gerar certificados de conclusão, mas ele não gera caso o título do curso ou nome do aluno possuam acentos (áéíóú, ãõ, etc).
Já tentei de tudo, verifiquei que existe um arquivo chamado encryt.php que reconhece como caracteres inválidos caso o nome possua acento.
Será que alguém pode me ajudar a resolver isso?
Segue os códigos do módulo (module_pdfcert):
encrypt.php
<?php // ****************************************************************************** // A reversible password encryption routine by: // Copyright 2003-2009 by A J Marston <http://www.tonymarston.net> // Distributed under the GNU General Public Licence // Modification: May 2007, M. Kolar <http://mkolar.org>: // No need for repeating the first character of scramble strings at the end; // instead using the exact inverse function transforming $num2 to $num1. // Modification: Jan 2009, A J Marston <http://www.tonymarston.net>: // Use mb_substr() if it is available (for multibyte characters). // ****************************************************************************** class encryption_class { var $scramble1; // 1st string of ASCII characters var $scramble2; // 2nd string of ASCII characters var $errors; // array of error messages var $adj; // 1st adjustment value (optional) var $mod; // 2nd adjustment value (optional) // **************************************************************************** // class constructor // **************************************************************************** function encryption_class () { $this->errors = array(); // Each of these two strings must contain the same characters, but in a different order. // Use only printable characters from the ASCII table. // Do not use single quote, double quote or backslash as these have special meanings in PHP. // Each character can only appear once in each string. $this->scramble1 = '! #$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'; $this->scramble2 = 'f^jAE]okIOzU[2&q1{3`h5w_794p@6s8?BgP>dFV=m D<TcS%Ze|r:lGK/uCy.Jx)HiQ!#$~(;Lt-R}Ma,NvW+Ynb*0X'; if (strlen($this->scramble1) <> strlen($this->scramble2)) { trigger_error('** SCRAMBLE1 is not same length as SCRAMBLE2 **', E_USER_ERROR); } // if $this->adj = 1.75; // this value is added to the rolling fudgefactors $this->mod = 3; // if divisible by this the adjustment is made negative } // constructor // **************************************************************************** function decrypt ($key, $source) // decrypt string into its original form { $this->errors = array(); // convert $key into a sequence of numbers $fudgefactor = $this->_convertKey($key); if ($this->errors) return; if (empty($source)) { $this->errors[] = 'No value has been supplied for decryption'; return; } // if $target = null; $factor2 = 0; for ($i = 0; $i < strlen($source); $i++) { // extract a (multibyte) character from $source if (function_exists('mb_substr')) { $char2 = mb_substr($source, $i, 1); } else { $char2 = substr($source, $i, 1); } // if // identify its position in $scramble2 $num2 = strpos($this->scramble2, $char2); if ($num2 === false) { $this->errors[] = "Source string contains an invalid character ($char2)"; return; } // if // get an adjustment value using $fudgefactor $adj = $this->_applyFudgeFactor($fudgefactor); $factor1 = $factor2 + $adj; // accumulate in $factor1 $num1 = $num2 - round($factor1); // generate offset for $scramble1 $num1 = $this->_checkRange($num1); // check range $factor2 = $factor1 + $num2; // accumulate in $factor2 // extract (multibyte) character from $scramble1 if (function_exists('mb_substr')) { $char1 = mb_substr($this->scramble1, $num1, 1); } else { $char1 = substr($this->scramble1, $num1, 1); } // if // append to $target string $target .= $char1; //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n"; } // for return rtrim($target); } // decrypt // **************************************************************************** function encrypt ($key, $source, $sourcelen = 0) // encrypt string into a garbled form { $this->errors = array(); // convert $key into a sequence of numbers $fudgefactor = $this->_convertKey($key); if ($this->errors) return; if (empty($source)) { $this->errors[] = 'No value has been supplied for encryption'; return; } // if // pad $source with spaces up to $sourcelen $source = str_pad($source, $sourcelen); $target = null; $factor2 = 0; for ($i = 0; $i < strlen($source); $i++) { // extract a (multibyte) character from $source if (function_exists('mb_substr')) { $char1 = mb_substr($source, $i, 1); } else { $char1 = substr($source, $i, 1); } // if // identify its position in $scramble1 $num1 = strpos($this->scramble1, $char1); if ($num1 === false) { $this->errors[] = "Source string contains an invalid character ($char1)"; return; } // if // get an adjustment value using $fudgefactor $adj = $this->_applyFudgeFactor($fudgefactor); $factor1 = $factor2 + $adj; // accumulate in $factor1 $num2 = round($factor1) + $num1; // generate offset for $scramble2 $num2 = $this->_checkRange($num2); // check range $factor2 = $factor1 + $num2; // accumulate in $factor2 // extract (multibyte) character from $scramble2 if (function_exists('mb_substr')) { $char2 = mb_substr($this->scramble2, $num2, 1); } else { $char2 = substr($this->scramble2, $num2, 1); } // if // append to $target string $target .= $char2; //echo "char1=$char1, num1=$num1, adj= $adj, factor1= $factor1, num2=$num2, char2=$char2, factor2= $factor2<br />\n"; } // for return $target; } // encrypt // **************************************************************************** function getAdjustment () // return the adjustment value { return $this->adj; } // setAdjustment // **************************************************************************** function getModulus () // return the modulus value { return $this->mod; } // setModulus // **************************************************************************** function setAdjustment ($adj) // set the adjustment value { $this->adj = (float)$adj; } // setAdjustment // **************************************************************************** function setModulus ($mod) // set the modulus value { $this->mod = (int)abs($mod); // must be a positive whole number } // setModulus // **************************************************************************** // private methods // **************************************************************************** function _applyFudgeFactor (&$fudgefactor) // return an adjustment value based on the contents of $fudgefactor // NOTE: $fudgefactor is passed by reference so that it can be modified { $fudge = array_shift($fudgefactor); // extract 1st number from array $fudge = $fudge + $this->adj; // add in adjustment value $fudgefactor[] = $fudge; // put it back at end of array if (!empty($this->mod)) { // if modifier has been supplied if ($fudge % $this->mod == 0) { // if it is divisible by modifier $fudge = $fudge * -1; // make it negative } // if } // if return $fudge; } // _applyFudgeFactor // **************************************************************************** function _checkRange ($num) // check that $num points to an entry in $this->scramble1 { $num = round($num); // round up to nearest whole number $limit = strlen($this->scramble1); while ($num >= $limit) { $num = $num - $limit; // value too high, so reduce it } // while while ($num < 0) { $num = $num + $limit; // value too low, so increase it } // while return $num; } // _checkRange // **************************************************************************** function _convertKey ($key) // convert $key into an array of numbers { if (empty($key)) { $this->errors[] = 'No value has been supplied for the encryption key'; return; } // if $array[] = strlen($key); // first entry in array is length of $key $tot = 0; for ($i = 0; $i < strlen($key); $i++) { // extract a (multibyte) character from $key if (function_exists('mb_substr')) { $char = mb_substr($key, $i, 1); } else { $char = substr($key, $i, 1); } // if // identify its position in $scramble1 $num = strpos($this->scramble1, $char); if ($num === false) { $this->errors[] = "Key contains an invalid character ($char)"; return; } // if $array[] = $num; // store in output array $tot = $tot + $num; // accumulate total for later } // for $array[] = $tot; // insert total as last entry in array return $array; } // _convertKey // **************************************************************************** } // end encryption_class // **************************************************************************** ?>module_pdfcert.class.php<?php //=================== // For debugging, do the following: // Open /libraries/globals.php // // comment error_reporting(E_ERROR); // uncomment error_reporting(E_ALL); ini_set("display_errors",true); // // On about line 130 change define("G_DEBUG",0); to a value of 1 // comment out the line: $GLOBALS['db'] -> debug = true; // // smsoa / placitas // Christine / nicks //=================== require 'encrypt.php'; class module_pdfcert extends EfrontModule { //-------------------------------------------------------- // Mandatory functions required for module function //-------------------------------------------------------- public function getName() { return _PDFCERT_TITLE; } //-------------------------------------------------------- // getPermittedRoles // The certificate page will only appear //-------------------------------------------------------- public function getPermittedRoles() { return array('professor','student'); } //-------------------------------------------------------- // Optional functions // What should happen on installing the module //-------------------------------------------------------- public function onInstall() { return true; } //-------------------------------------------------------- // onUninstall // When the module is uninstalled, delete the corresponding // database tables. //-------------------------------------------------------- public function onUninstall() { return true; } //-------------------------------------------------------- // onDeleteLesson // When a lesson is deleted, this method will delete the // pdfcert records for the specified lesson. //-------------------------------------------------------- public function onDeleteLesson($lessonId) { return false; } //-------------------------------------------------------- // OnExportLesson // This method is called when the user exports a lesson. //-------------------------------------------------------- public function onExportLesson($lessonId) { return false; } //-------------------------------------------------------- // onImportLesson // This method is called when the user imports a lesson //-------------------------------------------------------- public function onImportLesson($lessonId, $data) { return false; } //-------------------------------------------------------- // getCenterLinkInfo // Defines any links for the Administrator menu //-------------------------------------------------------- public function getCenterLinkInfo() { $optionArray = array('title' => _PDFCERT_TITLE, 'image' => $this -> moduleBaseDir.'images/certificate32.png', 'link' => $this -> moduleBaseUrl); $centerLinkInfo = $optionArray; return $centerLinkInfo; } //-------------------------------------------------------- // getLessonCenterLinkInfo // Returns links for the defined users control panel. //-------------------------------------------------------- public function getLessonCenterLinkInfo() { return false; } //-------------------------------------------------------- // getSidebarLinkInfo // This method defines the Menu Links that will appear by // user and what menu they appear in. This code displays // in the sidebar for professor and student. //-------------------------------------------------------- public function getSidebarLinkInfo() { $currentUser = $this -> getCurrentUser(); if($currentUser->getType() == "administrator"){} if($currentUser->getType() == "professor"){} else { //Menu will only appear for the student $link_of_menu_lessons = array (array ('id' => 'other_link_id1', 'title' => 'Certificates', 'image' => $this -> moduleBaseDir . 'images/certificate16', 'eFrontExtensions' => '1', 'link' => $this -> moduleBaseUrl)); } return array ( "tools" => $link_of_menu_lessons); } //-------------------------------------------------------- // getNavigationLinks //-------------------------------------------------------- public function getNavigationLinks() { return array (array ('title' => 'Meus Cursos', 'link' => 'student.php?ctg=lessons'), array ('title' => _PDFCERT, 'link' => $this -> moduleBaseUrl)); } //-------------------------------------------------------- // getLinkToHighlight //-------------------------------------------------------- public function getLinkToHighlight() { return 'module_pdfcert'; } public function isLessonModule(){ return false; } //-------------------------------------------------------- // onCompleteLesson //-------------------------------------------------------- public function onCompleteLesson($lessonId, $login) { return false; } //-------------------------------------------------------- // getModule // This method handles the all of the logic for the module. //-------------------------------------------------------- public function getModule() { // Get smarty variable $smarty = $this -> getSmartyVar(); $currentLesson = $this -> getCurrentLesson(); $currentUser = $this -> getCurrentUser(); $currentLogin = $currentUser->login; $smarty -> assign("T_PDFCERT_GENERATOR", $this->moduleBaseLink."certificates/certificate.php"); $smarty -> assign("T_PDFCERT_TARGET", $this->moduleBaseLink); try { $crypt = new encryption_class; //Get the users Course $aCourse = eF_getTableData("users_to_courses u inner join courses c on u.courses_ID = c.id", "c.id as course_id, c.name, u.completed", "users_LOGIN='".$currentLogin."' and u.archive = 0"); //print_r($aCourse); //exit; /* $coursekey = null; if($aCourse[0]['completed'] == 1) { $coursekey = $crypt->encrypt('ZIPPITYDOODAH', $currentUser->user['name'].'|'.$currentUser->user['surname'].'|'.$aCourse[0]['name'], 80); $smarty -> assign("T_PDFCERT_COURSE_KEY", $coursekey); } */ // Create an array to hold the courses this individual is in. // If the course is marked as completed, encrypt the for($cnt = 0; $cnt < count($aCourse); $cnt++) { if(intval($aCourse[$cnt][completed]) == 1) { $aTmp = array( 'id' => $aCourse[$cnt]['course_id'], 'name' => $aCourse[$cnt]['name'], 'enc' => $crypt->encrypt('ZIPPITYDOODAH', $currentUser->user['name'].'|'.$currentUser->user['surname'].'|'.$aCourse[0]['name'], 80) ); } else { $aTmp = array( 'id' => $aCourse[$cnt]['course_id'], 'name' => $aCourse[$cnt]['name'], 'enc' => '' ); } $aCourses[] = $aTmp; } $smarty -> assign("T_PDFCERT_COURSES", $aCourses); //Pass in the array of courses //print_r($aCourses); //echo "Get All Lessons"; //exit; //$allLessons = eF_getTableData("courses as c inner join lessons_to_courses lc on c.id = lc.courses_ID inner join lessons as l on lc.lessons_ID = l.id inner join tests as t on t.lessons_ID = l.id left join completed_tests as ct on ct.tests_ID = t.id and ct.status != 'deleted' and ct.users_LOGIN = '".$currentLogin."'", // "lc.courses_ID, lc.lessons_ID, l.name, t.mastery_score, ct.status, ct.score", // "order by c.id, l.name asc"); //$sql = "select ". // " uc.courses_ID,lc.lessons_ID , l.`name`, t.mastery_score, completed_tests.score ". // "from ". // " users_to_courses AS uc ". // " INNER JOIN lessons_to_courses AS lc ON uc.courses_ID = lc.courses_ID ". // " INNER JOIN lessons AS l ON l.id = lc.lessons_ID ". // " LEFT JOIN tests AS t ON t.lessons_ID = lc.lessons_ID ". // " LEFT JOIN completed_tests ON completed_tests.users_LOGIN = uc.users_LOGIN ". // "where ". // " uc.users_LOGIN = '".$currentLogin."' and uc.archive = 0 ". // "order by ". // " courses_ID, l.name asc"; //belen/1954, erma/bobby20, will_gina/tafoya5659 $sql = "SELECT ". "users_to_courses.courses_ID, lessons.`name`, s.* ". "FROM ". "users_to_courses ". "INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = '".$currentLogin."' AND users_to_courses.archive = 0 ". "INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID ". "left join ". "(SELECT completed_tests.score, tests.mastery_score, completed_tests.archive, tests.lessons_ID FROM completed_tests INNER JOIN tests ON tests.id = completed_tests.tests_ID where users_LOGIN = '".$currentLogin."' and completed_tests.archive=0) AS s ". "on lessons_to_courses.lessons_ID = s.lessons_ID ". "order by ". "users_to_courses.courses_ID, lessons.`name` asc"; $allLessons = $GLOBALS['db'] -> GetAll($sql); //echo "Query for Lessons"; //print_r($allLessons); //exit; /* ----------------------------------------------------------------------------------- Note: Per periklis uc.archive = 0 means the student is in the course. A value in this field indicates a timestamp when they were removed SELECT uc.courses_ID, lc.lessons_ID, l.`name`, t.mastery_score, completed_tests.score FROM users_to_courses AS uc INNER JOIN lessons_to_courses AS lc ON uc.courses_ID = lc.courses_ID INNER JOIN lessons AS l ON l.id = lc.lessons_ID LEFT JOIN tests AS t ON t.lessons_ID = lc.lessons_ID LEFT JOIN completed_tests ON completed_tests.users_LOGIN = uc.users_LOGIN where uc.users_LOGIN = 'student' and uc.active = 1 order by courses_ID, l.name asc SELECT DISTINCT users_to_courses.courses_ID, lessons.`name`, s.* FROM users_to_courses INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = 'student' AND users_to_courses.archive = 0 INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID , (select completed_tests.score, tests.mastery_score, completed_tests.archive from completed_tests, tests where users_LOGIN = 'student' and completed_tests.archive=0) AS s order by users_to_courses.courses_ID, lessons.`name` asc SELECT DISTINCT users_to_courses.courses_ID, lessons.`name`, s.* FROM users_to_courses INNER JOIN lessons_to_courses ON lessons_to_courses.courses_ID = users_to_courses.courses_ID AND users_to_courses.users_LOGIN = 'student' AND users_to_courses.archive = 0 INNER JOIN lessons ON lessons.id = lessons_to_courses.lessons_ID left join (SELECT completed_tests.score, tests.mastery_score, completed_tests.archive, tests.lessons_ID FROM completed_tests INNER JOIN tests ON tests.id = completed_tests.tests_ID where users_LOGIN = 'student' and completed_tests.archive=0) AS s on lessons_to_courses.lessons_ID = s.lessons_ID order by users_to_courses.courses_ID, lessons.`name` asc ---------------------------------------------------------------------------------------*/ //print_r($allLessons); //exit; $aLessons = array(); foreach ($allLessons as $student_lesson) { $genkey = null; if($student_lesson['score'] != "") { if(intval($student_lesson['score']) >= intval($student_lesson['mastery_score'])) { $fname = str_replace("'","$",$currentUser->user['name']); $smarty -> assign("T_FNAME",$fname); $lname = str_replace("'","$",$currentUser->user['surname']); $smarty -> assign("T_LNAME",$lname); $crs = str_replace("'","$",$student_lesson['name']); $genkey = $crypt->encrypt('ZIPPITYDOODAH', $fname.'|'.$lname.'|'.$crs, 80); } else { $genkey = null; } } $errors = $crypt->errors; $lsson = str_replace(" EXAM",'',$student_lesson['name']); $aLessons[] = array("courses_ID"=>$student_lesson['courses_ID'], "lessons_ID"=>$student_lesson['lessons_ID'], "users_LOGIN"=>$student_lesson['users_LOGIN'], "name"=>$lsson, "score"=>$student_lesson['score'], "genkey"=>$genkey); } //print_r($aLessons); //exit; $smarty -> assign("T_PDFCERT_LESSONS", $aLessons); $smarty -> assign("T_STUDENT_NAME", $currentUser-> user['name'].' '.$currentUser-> user['surname']); $err = ''; foreach($errors as $error) { $err = $err.$error.'<br/>'; } $smarty -> assign("T_PDFCERT_GENERR", $err); return true; } catch (Exception $e){ $currentUser = EfrontUserFactory :: factory($_SESSION['s_login']); $role = $currentUser -> getRole($this -> getCurrentLesson()); } } //-------------------------------------------------------- // getSmartyTpl // Used to return the Smarty Template. In this case, // module.tpl is selected. Values are passed into the // smarty template. //-------------------------------------------------------- public function getSmartyTpl() { $smarty = $this -> getSmartyVar(); $smarty -> assign("T_PDFCERT_MODULE_BASEDIR" , $this -> moduleBaseDir); $smarty -> assign("T_PDFCERT_MODULE_BASELINK" , $this -> moduleBaseLink); return $this -> moduleBaseDir . "module.tpl"; } //-------------------------------------------------------- // getLessonModule //-------------------------------------------------------- public function getLessonModule() { return false; } //-------------------------------------------------------- // getControlPanelSmartyTpl //-------------------------------------------------------- public function getControlPanelSmartyTpl() { return false; } //-------------------------------------------------------- // getControlPanelModuleS //-------------------------------------------------------- public function getControlPanelModule() { return false; } //-------------------------------------------------------- // getLessonSmartyTpl //-------------------------------------------------------- public function getLessonSmartyTpl() { return false; } //-------------------------------------------------------- // getModuleCSS //-------------------------------------------------------- public function getModuleCSS() { return false; } } ?>module.tpl{literal} <style> .pdfcert_hdr{ color:#222222; font-weight:bold; background:#ffffff url('{$T_PDFCERT_TARGET}../../images/others/gradient.jpg') repeat-x bottom; border-bottom: 1px solid #cccccc; } </style> {/literal} {if isset($T_PDFCERT_COURSES)} {capture name = 't_pdfcert_lessons'} {assign var='rowon' value = '#ecf6f9'} {assign var='rowoff' value = '#ffffff'} <div style="width:100%;"> <table class="directionsTable" id="direction_7" > {foreach item=course key=id from=$T_PDFCERT_COURSES} {assign var='cide' value = $course.id} <tr class = "lessonsList"> <td class="listPadding" style="width:1px"><div style="width:0px;"> </div></td> <td class="listToggle"><img id="subtree_img{$course.id}" src='images/others/transparent.gif' class='visible sprite16 sprite16-navigate_up' alt="Click to toggle" title="Click to toggle" onclick="Element.extend(this);showHideDirections(this, '', '{$course.id}', (this.hasClassName('visible')) ? 'hide' : 'show');"></td> <td> <img src='images/others/transparent.gif' class='sprite32 sprite32-categories' > <span style="display:none" id="subtree_children_7"></span> <span style="display:none" id="subtree_children_7"></span> <span class="listName">{$course.name}</span> </td> </tr> <!-- Display this section is the student completed the course --> {if strlen($course.enc) > 1} <tr> <td></td> <td></td> <td colspan=2 style="height:25px; margin-top:-2px; border-left:dashed 1px #ff0000; border-bottom:dashed 1px #ff0000; border-right:dashed 1px #ff0000;"> <table border="0" cellpadding="0" cellspacing="0"> <tr valign="top" > <td style="width:30px;"><a href="{$T_PDFCERT_GENERATOR}?c={$course.enc}" target="_blank"><img src="{$T_PDFCERT_TARGET}images/certificate32.png" style="padding-left:3px; padding-bottom:5px;" alt="Click To Display"></a></td> <td> </td> <td><span style="padding-top:1px; font-size:12px; line-height:14px;"><b style="color:#d9030b;">Curso Integralizado!</b> <br />Gere o certificado clicando no icone vermelho.</span></td> </tr> </table> </td> </tr> {/capture} {eF_template_printBlock title = 'Certificados' data = $smarty.capture.t_pdfcert_lessons image = '32x32/certificate.gif'} {/if} </td> </tr> {/foreach} {/if}Tem outros códigos no módulo, mas eu acredito que o erro esteja no "encrypt.php".
Por favor me ajudem a corrigir isso. Obrigado
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.