tipo_usuario_id == "admin"); else return false; } function calificacion($c) { return (defined("DECIMAL_TEST_SCORE") && DECIMAL_TEST_SCORE) ? round($c / 10, 1) : $c; } function get_bullet_link($name, $display, $url="#", $class="top_menu", $link=true, $on_img="bullet.gif", $target=NULL) { if (is_admin() && $on_img == "bullet.gif" && defined("ADMIN")) $on_img = "bullet_3.gif"; if (!is_null($class)) $class = "class=\"$class\""; $ret = NULL; $img = "bullet_2.gif"; if (!is_null($target)) $target = "target=\"$target\""; if ($link) $ret .= ""; else { $display = (!is_null($class)) ? "$display" : "$display"; $img = "bullet_1.gif"; } $ret .= "$display"; if ($link) $ret .= ""; return $ret; } function login_user($usuario, $md5_passwd, $session_expire=false) { $usuario = strtolower($usuario); $row = get_login_details($usuario, $md5_passwd); if ($row !== false) { $exp = ($session_expire ? 0 : (time() + COOKIE_EXPIRE)); setcookie("c_usuario", $usuario, $exp); setcookie("c_password", $md5_passwd, $exp); $_COOKIE['c_usuario'] = $usuario; $_COOKIE['c_password'] = $md5_passwd; return $row; } else return false; } function force_return($var) { if (defined("FORCE_UPDATE") && FORCE_UPDATE && debug()) return true; else return $var; } function is_user_logged_in() { return $GLOBALS['is_user_logged_in']; } function s($cnt) { return ($cnt != 1) ? "s" : ""; } function get_fieldset($title, $content) { $ret = "
"; $ret .= "$title"; $ret .= $content; $ret .= "
"; return $ret; } function error_redirect($p) { if (debug()) print_error("Redirecting to '$p'"); else redirect($err); } function set_globals_from_row($row) { foreach ($row as $k=>$v) { $GLOBALS[$k] = $v; } } function check_arg($arg, $err) { if (!@check_var($_REQUEST[$arg])) { if (debug()) print_error("Falta el argumento '$arg'"); error_redirect($err); } } function logout_user() { setcookie("c_usuario", "", 1); setcookie("c_password", "", 1); unset($_COOKIE['c_usuario']); unset($_COOKIE['c_password']); } function get_login_details($usuario, $md5_passwd) { $usuario = strtodb(strtolower($usuario)); if (check_var($usuario) && check_var($md5_passwd)) { do_mysql_connect(); $qry = "SELECT *, md5(password) AS md5_passwd, tipo_usuario.tipo_usuario FROM usuarios JOIN tipo_usuario ON usuarios.tipo_usuario_id = tipo_usuario.tipo_usuario_id WHERE usuario=$usuario"; $res = mysql_query($qry); if ($res && mysql_num_rows($res) > 0) { $row = mysql_fetch_object($res); mysql_free_result($res); if ($row->md5_passwd == $md5_passwd) return $row; } logout_user(); } return false; } function do_reset() { foreach($_COOKIE as $k=>$v) { setcookie($k, "", 1); unset($_COOKIE[$k]); } } function check_var($var) { return (isset($var) && strlen(trim($var)) > 0 && !is_null($var)); } function encrypt_decrypt($str, $key="some_secret_key") { if (empty($key)) return $str; $key = str_replace(chr(32), '', $key); if (strlen($key) < 8) return false; $kl = strlen($key)<32 ? strlen($key) : 32; $k=array(); for ($i=0; $i<$kl; $i++) $k[$i] = ord($key{$i}) & 0x1F; $j=0; for ($i=0; $i$t) { if ($c == $cnt++) $ret .= "$t"; else $ret .= "$t > "; } $ret .= "

" . $GLOBALS['page_title'] . "

\n"; return $ret; } function get_simple_table($title, $content, $width="100%", $bgcolor=TABLE_HEADER_COLOR, $style="solid_border") { $bgcolor = check_var($bgcolor) ? "bgcolor=\"" . $bgcolor . "\"" : NULL; $width = check_var($width) ? "width=\"$width\"" : NULL; $style = check_var($style) ? "class=\"$style\"" : NULL; $ret = "\n"; $ret .= "\n"; $ret .= "
"; $ret .= "\n"; $ret .="
$title
"; $ret .= "
$content
"; return $ret; } function get_parent_page($navigation_arr) { $t = count($navigation_arr); if ($t == 0) return NULL; $cnt = 1; foreach ($navigation_arr as $k=>$v) { if ($cnt == $t) return $k; $cnt++; } return "index.php"; } function stripped_filename($fname) { return array_shift(explode('?', basename($fname))); } function print_links_from_query($qry, $href_callback, $columns="1", $bottom_line=true, $show_error=true, $space_tr=false, $td_class="top_menu") { global $mysql; $res = mysql_query($qry); $results = get_table_from_results($res, $href_callback, $columns, $bottom_line, $space_tr, $td_class); $ok = $results !== false; if ($ok) echo $results; else if ($show_error) print_error(NO_TOPICS_FOUND); return $ok; } function q($f) { return "'" . $f . "'"; } function todb($f) { return strtodb($_REQUEST[$f], ENT_QUOTES); } function strtodb($str) { return q(trim(htmlentities($str, ENT_QUOTES))); } function get_notice($text, $width=NULL, $color=NOTICE_COLOR) { $ret = ""; if (!is_null($width)) $width = "width=\"$width\""; if (check_var($text)) { $ret .= "

\n"; $ret .= "
$text


"; } return $ret; } function get_first_row($table, $where=NULL) { if (check_var($where)) $where = "WHERE $where"; $qry = "SELECT * FROM $table $where LIMIT 1"; $res = mysql_query($qry); if ($res) { if (mysql_num_rows($res) == 1) return mysql_fetch_object($res); else return false; } else print_error(mysql_error()); return false; } function print_notice($e, $width=NULL, $color=NOTICE_COLOR) { echo get_notice($e, $width, $color); } function get_error($e, $width=NULL, $color=NOTICE_COLOR) { return get_notice("ERROR: " . $e, $width, $color); } function print_error($e, $width=NULL, $color=ERROR_COLOR) { echo get_error($e, $width, $color); } function get_table_from_array($arr, $content_callback, $columns="1", $auto_width=false, $space_tr=false) { $ret = ""; $td_width = floor(100 / $columns); if (count($arr) > 0) { $first = true; $cnt=1; $ret .= "\n\n"; $td_width = $auto_width ? "width=\"$td_width%\"" : ""; foreach ($arr as $k=>$v) { $content_cb = $content_callback($k, $v); if ($content_cb === false) continue; if ($cnt == 1) $ret .= "\n"; $ret .= "\n"; $cnt++; if ($cnt > $columns) { $ret .= "\n"; if ($space_tr) $ret .= "\n"; $cnt = 1; } } if ($cnt > 1 && $cnt < $columns) { for ($i=$cnt; $i <= $columns; $i++) $ret .= "\n"; $ret .= "\n"; } $ret .= "
$content_cb
 
 

\n"; return $ret; } else return false; } function get_table_from_results($res, $content_callback, $columns="1", $auto_width=false, $space_tr=false) { $ret = ""; $td_width = floor(100 / $columns); if ($res && (mysql_num_rows($res) > 0)) { $first = true; $cnt=1; $ret .= "\n\n"; $td_width = $auto_width ? "width=\"$td_width%\"" : ""; while ($row = mysql_fetch_object($res)) { $content_cb = $content_callback($row); if ($content_cb === false) continue; if ($cnt == 1) $ret .= "\n"; $ret .= "\n"; $cnt++; if ($cnt > $columns) { $ret .= "\n"; if ($space_tr) $ret .= "\n"; $cnt = 1; } } if ($cnt > 1 && $cnt < $columns) { for ($i=$cnt; $i <= $columns; $i++) $ret .= "\n"; $ret .= "\n"; } $ret .= "
$content_cb
 
 

\n"; return $ret; } else return false; } if (!function_exists("stripos")) { function stripos($str, $needle, $offset=0) { return strpos(strtolower($str), strtolower($needle), $offset); } } if (!function_exists("auto_title")) { function auto_title($file) { return PAGE_TITLE; } } function is_connected_to_mysql() { global $mysql; return ($mysql == false) ? false : true; } function do_mysql_disconnect() { if (is_connected_to_mysql()) { global $mysql; mysql_close($mysql); } } function debug() { return (defined("DEBUG") && DEBUG == "true"); } function do_mysql_connect() { /* Establish a connection to the database server using the defined constants in "config.inc" */ global $mysql; if (!is_connected_to_mysql()) { if (debug()) $mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD); else $mysql = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD); } else return true; if ($mysql) { if (debug()) return (mysql_select_db(DATABASE)); else return (@mysql_select_db(DATABASE)); } else $mysql = false; return false; } function get_month_name($month) { $month_arr = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); return $month_arr[$month - 1]; } function get_week_day($day, $month, $year) { $d_var = getdate(mktime(0, 0, 0, $month, $day, $year)); $es_days_arr = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"); $t = ($d_var[wday] - 1); if ($t < 0) $t = 6; return $es_days_arr[$t]; } function mailto($email) { $ret = "$email"; return $ret; } function get_page_title($t="") { $ret = TITLE; if (strlen($t) > 0) $ret = $t; if (defined("TITLE_PREFIX")) $ret = TITLE_PREFIX . " - " . $ret; if (defined("DEBUG") && DEBUG == "true") $ret = "DEBUG - " . $ret; return $ret; } function get_content_fnc($fnc, $file) { $ret = ""; if (!function_exists($fnc)) $fnc = "default_" . $fnc; if (function_exists($fnc)) { ob_start(); $fnc($file); $ret .= ob_get_contents(); ob_end_clean(); } return $ret; } function set_export_headers($ext) { $file = basename($_SERVER['PHP_SELF']); $file = substr($file, 0, strpos($file, ".")) . ".$ext"; header("Content-Disposition: attachment;filename=\"$file\""); header("Content-Transfer-Encoding: binary"); header('Accept-Ranges: bytes'); header("Cache-control: private"); header('Pragma: private'); } function set_xls_export_headers() { set_export_headers("csv"); header("Content-type: application/vnd.ms-excel"); } function set_txt_export_headers() { set_export_headers("txt"); header("Content-type: application/vnd.ms-word"); } function get_print_link() { $print_url = basename($_SERVER['PHP_SELF']) . "?print=true&" . $_SERVER['QUERY_STRING']; $print = "Imprimir"; return $print; } function get_txt_link() { $txt_url = basename($_SERVER['PHP_SELF']) . "?xls=true&" . $_SERVER['QUERY_STRING']; $txt = "Descargar"; return $txt; } function get_xls_link() { $xls_url = basename($_SERVER['PHP_SELF']) . "?xls=true&" . $_SERVER['QUERY_STRING']; $xls = "Descargar"; return $xls; } function get_print_xls_links() { $ret = "
"; $ret .= get_xls_link(); $ret .= "     "; $ret .= get_print_link(); $ret .= "
"; return $ret; } function get_print_txt_links() { $ret = "
"; $ret .= get_txt_link(); $ret .= "     "; $ret .= get_print_link(); $ret .= "
"; return $ret; } function ifai_template1($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $images = IMAGES_PATH; $tags = array( "title"=>get_page_title($page_title), "meta_description"=>$description, "meta_keywords"=>$keywords, "style"=>$style, "javascript"=>$global_javascript, "local_javascript"=>get_content_fnc($local_javascript_fnc, $parent_file), "images"=>$images, "content"=>get_content_fnc($contents_fnc, $parent_file), "copyright"=>$copyright ); return $tags; } function ifai_template3($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $images = IMAGES_PATH; $tags = array( "title"=>get_page_title($page_title), "meta_description"=>$description, "meta_keywords"=>$keywords, "style"=>$style, "javascript"=>$global_javascript, "local_javascript"=>get_content_fnc($local_javascript_fnc, $parent_file), "images"=>$images, "content"=>get_content_fnc($contents_fnc, $parent_file), "copyright"=>$copyright ); return $tags; } function ifai_template2($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $images = IMAGES_PATH; $tags = array( "title"=>get_page_title($page_title), "meta_description"=>$description, "meta_keywords"=>$keywords, "style"=>$style, "javascript"=>$global_javascript, "local_javascript"=>get_content_fnc($local_javascript_fnc, $parent_file), "images"=>$images, "top"=>get_content_fnc("top", $parent_file), "top_menu"=>get_content_fnc("top_menu", $parent_file), "left_menu"=>get_content_fnc("left_menu", $parent_file), "content"=>get_content_fnc($contents_fnc, $parent_file), "copyright"=>$copyright ); return $tags; } function admin_template($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $w = (@check_var($GLOBALS['disable_width']) && $GLOBALS['disable_width'] === true) ? NULL : ("width=\"" . MAIN_CONTENT_WIDTH . "\""); $images = IMAGES_PATH; $sp = NULL; if (is_null($w)) $sp = ""; $open_content_table = "$sp
"; $close_content_table = "
"; $tags = array( "title"=>get_page_title($page_title), "meta_description"=>$description, "meta_keywords"=>$keywords, "style"=>$style, "javascript"=>$global_javascript, "local_javascript"=>get_content_fnc($local_javascript_fnc, $parent_file), "images"=>$images, "header"=>get_content_fnc($header_fnc, $parent_file), "content"=>$open_content_table . get_content_fnc($contents_fnc, $parent_file) . $close_content_table, "footer"=>get_content_fnc($footer_fnc, $parent_file), "copyright"=>$copyright ); return $tags; } function print_template($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $w = (@check_var($GLOBALS['disable_width']) && $GLOBALS['disable_width'] === true) ? NULL : ("width=\"" . MAIN_CONTENT_WIDTH . "\""); $images = IMAGES_PATH; $sp = NULL; if (is_null($w)) $sp = ""; $open_content_table = "$sp
"; $close_content_table = "
"; $tags = array( "title"=>get_page_title($page_title), "meta_description"=>$description, "meta_keywords"=>$keywords, "style"=>$style, "javascript"=>$global_javascript, "local_javascript"=>get_content_fnc($local_javascript_fnc, $parent_file), "images"=>$images, "header"=>get_content_fnc("print_header", $parent_file), "content"=>$open_content_table . get_content_fnc($contents_fnc, $parent_file) . $close_content_table, "footer"=>get_content_fnc($footer_fnc, $parent_file) ); return $tags; } function xls_template($page_title, $description, $keywords, $style, $global_javascript, $local_javascript_fnc, $parent_file, $header_fnc, $contents_fnc, $footer_fnc, $copyright) { $tags = array("content"=>get_content_fnc($contents_fnc, $parent_file) ); return $tags; } function show_page($parent_file, $page_title=NULL, $template_fnc="admin_template") { require_once("ctemplate_parser.inc"); header("Cache-Control: no-cache"); do_mysql_connect(); if (function_exists("on_page_load")) on_page_load(); if (!defined("PAGE_TITLE")) define("PAGE_TITLE", ""); $GLOBALS["parent_file"] = basename($parent_file); $keywords = SHORT_COMPANY_NAME . ", " . (defined("META_KEYWORDS") ? META_KEYWORDS : PAGE_TITLE); $keywords .= ", " . DEFAULT_KEYWORDS . ", " . SHORT_COMPANY_NAME; $description = SHORT_COMPANY_NAME . " - " . (defined("META_DESCRIPTION") ? META_DESCRIPTION : PAGE_TITLE); if ((isset($_GET['reset']) && $_GET['reset'] == "true") || (isset($_GET['logout']) && $_GET['logout'] == "true")) do_reset(); if (!check_var($page_title)) $page_title = PAGE_TITLE; $GLOBALS["page_title"] = $page_title; $tags = $template_fnc($GLOBALS["page_title"], $description, $keywords, "style.css.inc", "javascript.js.inc", "local_javascript", $parent_file, "content_header", "contents", "content_footer", COPYRIGHT); $tp = &new ctemplate_parser($template_fnc . ".html", false); $tp->parseTemplate($tags); echo $tp->display(); do_mysql_disconnect(); } function space_to_nbsp($str) { return str_replace(" ", " ", $str); } function redirect($url) { header("location: $url"); exit(); } ?> width = $width; $this->align = $align; } function get_width() { return (check_var($this->width)) ? "width=\"$this->width\"" : ""; } function get_align() { return (check_var($this->align)) ? "align=\"$this->align\"" : ""; } }; class ctable_display { var $header_callback = NULL; var $content_callback = NULL; var $tr_color_callback = NULL; var $add_row_callback = NULL; var $bgcolor = NULL; var $csv = false; var $main_table_style = "solid_border"; var $content_td_style = NULL; var $display_fields = NULL; var $main_item_name; var $male=true; var $alt_row_color = ALT_ROW_COLOR; var $table_header_color = TABLE_HEADER_COLOR; var $table_width=NULL; var $query; var $show_found_rows; var $res = false; var $num_rows = 0; function __construct($query, $main_item_name, $display_fields=array(), $table_width=NULL) { $this->query = $query; $this->main_item_name = $main_item_name; $this->display_fields = $display_fields; $this->table_width = $table_width; $this->show_found_rows = true; $this->csv = false; } function display() { $ret = ""; $this->num_rows = 0; $this->res = mysql_query($this->query); if ($this->res) { $this->num_rows = mysql_num_rows($this->res); if ($this->csv) $ret = $this->get_csv_content(); else $ret = $this->get_content(); } else $ret = get_error(mysql_error()); return $ret; } function get_content() { if (!$this->res) return NULL; $ret = ""; $num_fields = mysql_num_fields($this->res); if ($num_fields < 1) return NULL; $width = check_var($this->table_width) ? "width=\"$this->table_width\"" : ""; $ret .= ""; $main_item_name = strtolower($this->main_item_name); $display_fields_idx_arr = array(); $s = s($this->num_rows); $f = $this->male ? "encontrado" : "encontrada"; if ($this->show_found_rows) { $ret .= ""; $ret .= ""; } $ret .= "\n"; if (!is_null($this->add_row_callback) && function_exists($this->add_row_callback)) { $fnc = $this->add_row_callback; $custom_td = $fnc($row); if (!is_null($custom_td)) { $nf = $num_fields + 1; $ret .= ""; $ret .= "\n"; } } $row_cnt++; } } $ret .= "
\n"; $ret .= "$this->num_rows "; $ret .= "$main_item_name$s $f$s
"; } $style = ""; if (check_var($this->main_table_style)) $style = "class=\"$this->main_table_style\""; $bgcolor = check_var($this->bgcolor) ? "bgcolor=\"$this->bgcolor\"" : NULL; $ret .= "\n"; $ret .= "table_header_color\">\n"; for ($i = 0; $i < $num_fields; $i++) { $header_label = mysql_field_name($this->res, $i); if (!array_key_exists($header_label, $this->display_fields)) continue; $display_fields_idx_arr[$i] = $header_label; $tmp = $header_label; if (!is_null($this->header_callback) && function_exists($this->header_callback)) { $fnc = $this->header_callback; $header_label = $fnc($header_label, $i); if (is_null($header_label)) $header_label = ""; else if ($header_label === false) $header_label = $tmp; } else $header_label = "$header_label"; $cs = $this->display_fields[$tmp]; $width = $cs->get_width(); $align = $cs->get_align(); $ret .= ""; } $ret .= ""; if ($this->num_rows > 0 && count($display_fields_idx_arr) > 0) { $row_cnt = 0; $style = (check_var($this->content_td_style)) ? "class=\"$this->content_td_style\"" : ""; while ($row = mysql_fetch_object($this->res)) { $bgcolor = ""; if (check_var($this->alt_row_color) && ($row_cnt % 2)) $bgcolor = $this->alt_row_color; if (!is_null($this->tr_color_callback) && function_exists($this->tr_color_callback)) { $fnc = $this->tr_color_callback; $bgcolor = $fnc($row, $bgcolor); } if (strlen($bgcolor) > 0) $bgcolor = "bgcolor=\"$bgcolor\""; $ret .= "\n"; for ($i = 0; $i < $num_fields; $i++) { if (!array_key_exists($i, $display_fields_idx_arr)) continue; $fname = $display_fields_idx_arr[$i]; $tmp = $content_cb = $row->$fname; if (!is_null($this->content_callback) && function_exists($this->content_callback)) { $fnc = $this->content_callback; $content_cb = $fnc($row, $fname); if (is_null($content_cb)) $content_cb = ""; else if ($content_cb === false) $content_cb = $tmp; } $cs = $this->display_fields[$fname]; $align = $cs->get_align(); $qs = "next=".(($i == ($num_fields-1) ? "false" : "true")); $qs .= "&refe=". ($row->num - 1); $qs .= "&submodulo_id=" . $row->id; $qs .= "&submodulos_usuario_id=" . $row->uid; $qs .= "&c_grupo_id=" . $_REQUEST['c_grupo_id']; $qs .= "&modulo_id=" . $_REQUEST['modulo_id']; $ret .= "
"; $ret .= "\n"; $ret .= "
$header_label
"; $ret .= "
"; $ret .= "\n"; if($row->completo == 1 || $sgte == "si") { $sgte = "si"; $url = "despliega_curso.php?$qs"; $filnksty ="style=\"color:#8c37b9; font-family:Arial; font-weight:700;\""; $ret .= "
$content_cb
"; if ($row->completo == 0) { $sgte = "no"; } } else { $ret .= "
$content_cb
"; } $ret .= "
"; $ret .= "\n"; $ret .= "
$custom_td
"; $ret .= "
\n"; return $ret; } function do_replace($str) { //$str = str_replace(",", " ", $str); //$str = str_replace("\r", "", $str); //$str = str_replace("\n", "", $str); $str = html_entity_decode($str); $str = strip_tags($str); $str = str_replace("\"", "'", $str); return "\"$str\""; } function get_csv_content() { if (!$this->res) return NULL; $ret = ""; $num_fields = mysql_num_fields($this->res); if ($num_fields < 1) return NULL; $nl = "\r\n"; $main_item_name = strtolower($this->main_item_name); $display_fields_idx_arr = array(); $s = s($this->num_rows); $f = $this->male ? "encontrado" : "encontrada"; if ($this->show_found_rows) $ret .= $this->do_replace("$this->num_rows $main_item_name$s $f$s") . $nl; for ($i = 0; $i < $num_fields; $i++) { $header_label = mysql_field_name($this->res, $i); if (!array_key_exists($header_label, $this->display_fields)) continue; $display_fields_idx_arr[$i] = $header_label; $tmp = $header_label; if (!is_null($this->header_callback) && function_exists($this->header_callback)) { $fnc = $this->header_callback; $header_label = $fnc($header_label, $i); if (is_null($header_label)) $header_label = ""; else if ($header_label === false) $header_label = $tmp; } $ret .= $this->do_replace($header_label) . ","; } $ret[strlen($ret) - 1] = $nl; if ($this->num_rows > 0 && count($display_fields_idx_arr) > 0) { $row_cnt = 0; while ($row = mysql_fetch_object($this->res)) { for ($i = 0; $i < $num_fields; $i++) { if (!array_key_exists($i, $display_fields_idx_arr)) continue; $fname = $display_fields_idx_arr[$i]; $tmp = $content_cb = $row->$fname; if (!is_null($this->content_callback) && function_exists($this->content_callback)) { $fnc = $this->content_callback; $content_cb = $fnc($row, $fname); if (is_null($content_cb)) $content_cb = ""; else if ($content_cb === false) $content_cb = $tmp; } $cs = $this->display_fields[$fname]; $ret .= $this->do_replace($content_cb) . ","; } $ret[strlen($ret) - 1] = $nl; $row_cnt++; } } $ret .= $nl; return $ret; } }; ?>