public function tisaniere() { $pages = $this->pm->getAll(); $pagesjs = array(); $ind = 0; foreach ($pages as $page) { $pagesjs[$ind] = array($page->idpage, $page->url, "20000", 'frame'); $ind++; } $this->data['pages'] = php2js($pagesjs); $this->load->view('iframe', $this->data); }
/** * @function arr2json * @abstract Creates JSON object when json_encode is missing */ function arr2json($array) { if (is_array($array)) { foreach ($array as $key => $value) { $json[] = $key . ':' . php2js($value); } if (count($json) > 0) { return '{' . implode(',', $json) . '}'; } else { return ''; } } }
function php2js($a = false) { if (is_null($a)) { return 'null'; } if ($a === false) { return 'false'; } if ($a === true) { return 'true'; } if (is_scalar($a)) { if (is_float($a)) { // Always use "." for floats. $a = str_replace(",", ".", strval($a)); } // All scalars are converted to strings to avoid indeterminism. // PHP's "1" and 1 are equal for all PHP operators, but // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend, // we should get the same result in the JS frontend (string). // Character replacements for JSON. static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; } $isList = true; for ($i = 0, reset($a); $i < count($a); $i++, next($a)) { if (key($a) !== $i) { $isList = false; break; } } $result = array(); if ($isList) { foreach ($a as $v) { $result[] = php2js($v); } return '[ ' . join(', ', $result) . ' ]'; } else { foreach ($a as $k => $v) { $result[] = php2js($k) . ': ' . php2js($v); } return '{ ' . join(', ', $result) . ' }'; } }
function php2js($var) { if (is_array($var)) { $res = "["; $array = array(); foreach ($var as $a_var) { $array[] = php2js($a_var); } return "[" . join(",", $array) . "]"; } elseif (is_bool($var)) { return $var ? "true" : "false"; } elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) { return $var; } elseif (is_string($var)) { return "\"" . addslashes(stripslashes($var)) . "\""; } // autres cas: objets, on ne les gère pas return FALSE; }
function create() { if ($_POST) { $_POST['user_id'] = $this->user->id; $id = db_insert($this->table, $_POST); if ($id) { foreach (preg_split('/,\\s*/', $_POST['tags']) as $tag) { $tag_id = db_fetch_value('SELECT id FROM tag WHERE name = "' . db_escape($tag) . '"'); if (!$tag_id) { $tag_id = db_insert('tag', array('name' => $tag)); } db_insert('note_to_tag', array('note_id' => $id, 'tag_id' => $tag_id)); } $this->index('notes'); $response->html = $this->tpl->fetch('in.notes_list.tpl'); die(php2js($response)); } else { die('{error: 1}'); } } }
function php2js($a = false) { if (is_null($a)) { return 'null'; } if ($a === false) { return 'false'; } if ($a === true) { return 'true'; } if (is_scalar($a)) { if (is_float($a)) { $a = str_replace(",", ".", strval($a)); } static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; } $isList = true; for ($i = 0, reset($a); $i < count($a); $i++, next($a)) { if (key($a) !== $i) { $isList = false; break; } } $result = array(); if ($isList) { foreach ($a as $v) { $result[] = php2js($v); } return '[' . join(',', $result) . ']'; } else { foreach ($a as $k => $v) { $result[] = php2js($k) . ': ' . php2js($v); } return '{' . join(',', $result) . '}'; } }
function HelpTopic() { /* {{{ */ $n = cm_get('Name', 'str'); // get topic id $r = $db->q2assoc(' SELECT ht.id FROM help_topic ht WHERE name = \'' . $n . '\' LIMIT 1;', true); $topic_id = (int) $r['id']; if (!$topic_id) { echo php2js(array('name' => $n)); break; } // get author's topic content edition $r = $db->q2assoc(' SELECT id FROM help_topic_content WHERE topic_id = ' . $topic_id . ' AND state_id = 1 AND author_id = ' . $_SESSION['user']['id'] . ' LIMIT 1;', true); $max_id = (int) $r['id']; $r = $db->q2assoc(' SELECT ht.*, htc.text as content, ' . $max_id . ' as not_approved FROM help_topic ht INNER JOIN help_topic_content htc ON ' . ($max_id ? 'htc.topic_id = ht.id' : 'htc.id = ht.content_id') . ' WHERE ' . ($max_id ? 'htc.id = ' . $max_id : 'ht.id = ' . $topic_id) . ' LIMIT 1;', true); $r['name'] = $n; echo php2js($r); /* }}} */ }
function php2js($data) { if (is_array($data)) { // Массив if (is_single_array($data)) { // Простой массив [] $ret = "["; $first = true; foreach ($data as $key => $obj) { if (!$first) { $ret .= ','; } $ret .= php2js($obj); $first = false; } $ret .= "]"; } else { // Ассоциативный массив {} $ret = '{'; $first = true; foreach ($data as $key => $obj) { if (!$first) { $ret .= ','; } $ret .= $key . ':' . php2js($obj); $first = false; } $ret .= '}'; } } else { // Просто значение $ret = is_string($data) ? "'" . nl2br(str_normalize($data)) . "'" : $data; } return $ret; }
$zone = $_REQUEST['location']; // Передаём клиенту данные о картах $mapdata = array(); foreach ($gMapCoord as $mapId => $map) { $mapdata['m' . $mapId]['header'] = getMapName($mapId); $mapdata['m' . $mapId]['imageX'] = $map[5]; $mapdata['m' . $mapId]['imageY'] = $map[4]; $mapdata['m' . $mapId]['image'] = "images/map_image/maps/" . $map[6]; } foreach ($gAreaImagesCoord as $areaId => $area) { $mapdata['a' . $areaId]['header'] = $area[1] == 0 ? getMapName($area[0]) : getAreaName($area[1]); $mapdata['a' . $areaId]['imageX'] = 1002; $mapdata['a' . $areaId]['imageY'] = 668; $mapdata['a' . $areaId]['image'] = "images/map_image/areas/" . $area[6]; } echo "<script type=\"text/javascript\">\nvar data=" . php2js($mapdata) . ";\nfunction renderMap(id)\n{\n var m = data[id];\n if (m)\n {\n setMapData(m);\n renderInstance('mapper',0);\n }\n else\n document.getElementById('mapper').innerHTML = 'No map present';\n}\nsetBestScale(1002);\n</script>"; $azeroth = array(14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 39, 40, 301, 341, 382, 480, 462, 463, 499, 502); $kalimdor = array(13, 4, 9, 11, 41, 42, 43, 61, 81, 101, 121, 141, 161, 181, 182, 201, 241, 261, 281, 321, 362, 381, 471, 464, 476); $outland = array(466, 465, 467, 473, 475, 477, 478, 479, 481); $northrend = array(485, 486, 488, 490, 491, 492, 493, 495, 496, 501, 504, 510, 541); $others = array(401, 443, 461, 482, 512, 540); echo "<select onchange=\"renderMap(this.value)\">"; foreach ($azeroth as $id) { echo "<option value=a" . $id . ">" . getAreaNameFromId($id) . "</option>"; } echo "</select>"; echo "<select onchange=\"renderMap(this.value)\">"; foreach ($kalimdor as $id) { echo "<option value=a" . $id . ">" . getAreaNameFromId($id) . "</option>"; } echo "</select><br>";
AND it.displayid = i.id AND it.spellid_1 = s.spellid AND s.effect1id = ?d AND gp.id = s.effect1MiscValue ', $_SESSION['locale'] > 0 ? $_SESSION['locale'] : DBSIMPLE_SKIP, $_SESSION['locale'] > 0 ? 1 : DBSIMPLE_SKIP, 74); $g_glyphs = array(); foreach ($glyphs as $glyph) { $name = localizedName($glyph); if ($_SESSION['locale'] == 0) { $name = str_replace(LOCALE_GLYPH_OF, '', $name); } $g_glyphs[$glyph['entry']] = array('name' => (string) $name, 'description' => (string) spell_desc($glyph['spellid']), 'icon' => (string) $glyph['iconname'], 'type' => (int) ($glyph['typeflags'] & 1 ? 2 : 1), 'classs' => (int) $glyph['subclass'], 'skill' => (int) 2); } save_cache(25, 'x', $g_glyphs); } echo 'var g_glyphs=' . php2js($g_glyphs); break; case 'talent-icon': $iconname = strtolower($_GET['icon']); if (!$DB->selectCell('SELECT 1 FROM ?_spellicons WHERE iconname = ?', $iconname)) { exit; } if ($name = load_cache(21, $iconname)) { header('Content-type: image/jpeg'); imagejpeg(imagecreatefromjpeg('cache/images/' . $iconname . '.jpg')); } else { header('Content-type: image/jpeg'); $im = @imagecreatefromjpeg('images/icons/medium/' . $iconname . '.jpg'); if (!$im) { exit; }
$spec->name = $name; $result[] = $spec; } header('Content-Type: application/json; charset="' . $config['charset'] . '"'); echo php2js($result); exit; break; case 'GetCities': foreach ($job->GetCities($id, $search ? 'search' : '') as $id => $name) { $city = new stdClass(); $city->id = $id; $city->name = $name; $result[] = $city; } header('Content-Type: application/json; charset="' . $config['charset'] . '"'); echo php2js($result); exit; break; case "GetCityEdit": require ENGINE_DIR . "/Core_modules/TemplateAdmin.php"; $tpl = new TemplateAdmin(); $tpl->echo = FALSE; $PHP_SELF = $config['http_home_url'] . "admin.php?mod=job&action=cities&subaction="; $result = $tpl->OTable(array(), 'style="margin-left:30px;width:95%" id="city_' . $id . '"'); foreach ($job->GetCities($id) as $id => $name) { $result .= $tpl->row(array('width="30px" align="center"' => "", $id, $name, "[<a href=\"{$PHP_SELF}edit&type=city&id={$id}\">{$job->lang['action_edit']}</a>][<a OnClick=\"if (confirm('{$job->lang['del_confirm_city']}'))return true; else return false;\" href=\"{$PHP_SELF}del&type=city&id={$id}\">{$job->lang['action_del']}</a>]"), false, false, "id=\"{$id}\""); } $result .= $tpl->CTable(); header('Content-Type: text/html; charset="' . $config['charset'] . '"'); echo $result; break;
function php2js($data) { if (is_array($data)) { // Массив if (array_key_exists(0, $data)) { // Простой массив [] $ret = "["; $first = true; foreach ($data as $key => $obj) { if (!$first) { $ret .= ','; } $ret .= php2js($obj); $first = false; } $ret .= "]"; } else { // Ассоциативный массив {} $ret = "{"; $first = true; foreach ($data as $key => $obj) { if (!$first) { $ret .= ','; } $ret .= $key . ':' . php2js($obj) . ""; $first = false; } $ret .= "}"; } } else { // Просто значение $ret = is_string($data) ? "'" . str_replace("\n", "<br>", str_normalize($data)) . "'" : $data; } return $ret; }
$timeBegin = $sec + $msec; // get and save full path $real_path = empty($_SERVER['PATH_INFO']) ? '' : $_SERVER['PATH_INFO']; $tpl->add('path', $real_path); // define format from characters after last point if (preg_match('/(.*)\\.([^\\.]*)/', $real_path, $m)) { //todo: refactor this regexp $real_path = @$m[1]; $format = @$m[2]; } else { $format = ''; } lg('\\nURL \\033[1;10m' . $_SERVER['PATH_INFO'] . '\\033[00m requested at \\033[0;34m' . strftime('%c') . '\\033[00m'); // log input params if ($_POST) { lg('POST: ' . php2js($_POST)); } // slit path into partitions $path = preg_split('/[\\/\\\\]/', $real_path, null, PREG_SPLIT_NO_EMPTY); $path_prefix = '/'; // zero-component of path may be user key (if it starts from ~) if (isset($path[0]) && $path[0] && $path[0][0] == '~') { // create user by key $path_prefix .= $path[0] . '/'; $user = new user(substr(array_shift($path), 1)); } elseif (isset($_SESSION['user_id'])) { // find another way to init user $user = new user($_SESSION['user_id']); } else { $user = new user(); }
$bestScale = 0.75; } else { if ($bestScale > 0.87 && $bestScale < 1.5) { $bestScale = 1.0; } else { $bestScale = 2.0; } } } } echo "<script type=\"text/javascript\">setScale({$bestScale});</script>"; } // Сюда будет создана карта скриптом echo "<div id=mapper></div>"; // Записываем данные о карте в Java Script и запускаем вывод данных echo "<script type=\"text/javascript\">var data=" . php2js($mapdata) . ";setMapData(data); renderInstance('mapper',0);</script>"; } else { echo $lang['inst_no_map_present'] . getMapName($mapId); } } createReportTab(); if ($dungeon) { //******************************************************************************** // Creatures on map //******************************************************************************** function r_npcDungeon($data) { global $lang; echo '<a href="?map&npc=' . $data['entry'] . '" onClick="changeSelect(\'c' . $data['entry'] . '\'); return false;">' . $lang['map'] . '</a>'; } $creatures =& new CreatureReportGenerator('position');
} break; case 'logout': $Permissions->logout(); break; case 'get_citys': $aCountrys = $Db->query("SELECT id, name FROM " . DB_PREFIX . DB_TBL_CITYS . " \n\t\t\t\tWHERE country_id = '" . mysql_real_escape_string($_POST['country_id']) . "'", '$aList[$row["id"]] = $row["name"];'); $aRet = array(0 => 'Не выбран'); foreach ($aCountrys as $k => $v) { $aRet[$k] = $v; } define('FORCE_QIUT', 1); // отключаем отладчик, чтобы он не мешал ajax`y header('Content-Type: text/html; charset=' . CHARSET); // explorer`y - заголовки! echo php2js($aRet); include_once FLGR_COMMON . '/exit.php'; // и выходим break; // default: // dbg($_POST, 'root post'); // break; } } // Не пускаем незалогиненного пользователя никуда // кроме ограниченного набора страниц if (!$Permissions->bIsLogged()) { // ----------------------- if (isset($aRequest[1])) { switch ($aRequest[1]) { // TODO *** case
<?php include_once 'include/map_data.php'; $areaId = intval(@$_REQUEST['jsarea']); $area_data = getRenderAreaData($areaId); $list = $dDB->select('SELECT \'n\' AS `type`, `guid`, `id`, `map`, `spawnMask`, `phaseMask`, `modelid`, `equipment_id`, `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `spawndist`, `currentwaypoint`, `curhealth`, `curmana`, `DeathState`, `MovementType` FROM `creature` WHERE `map` = ?d AND `position_x` > ?d AND `position_x` < ?d AND `position_y` > ?d AND `position_y` < ?d', $area_data[0], $area_data[5], $area_data[4], $area_data[3], $area_data[2]); $data = get_mapAreaData($areaId, $list); echo php2js($data);
function includeTalentScript($class, $petId, $maxLevel, $header, $ver = "322") { global $wDB, $game_text, $config; $tab_set = 0; // Create tabs list if ($class) { // For players $tab_set = $wDB->selectCol('SELECT `id` FROM `wowd_talent_tab` WHERE `class_mask` & ?d ORDER BY `tab` ', 1 << $class - 1); } else { if ($petId >= 0) { // For pets (need get pet_talent_type from creature_family) $talent_type = $wDB->selectCell('SELECT `pet_talent_type` FROM `wowd_creature_family` WHERE `category` = ?d', $petId); if (isset($talent_type) && $talent_type >= 0) { $tab_set = $wDB->selectCol('SELECT `id` FROM `wowd_talent_tab` WHERE `pet_mask` & ?d ORDER BY `tab`', 1 << $talent_type); } } } if (!$tab_set) { return; } // Создаём кэш для калькулятора (если его нет или устарел) $data_file = "tc_" . $class . $petId . "_" . $config['lang'] . "_" . $ver . ".js"; if (checkUseCacheJs($data_file, 60 * 60 * 24)) { // Подготаливаем данные для скрипта $tab_name = array(); // Имена веток талантов $tid_to_tab = array(); // Преборазователь TalentId => TabId $tabs = array(); // Тут уже будут данные для JS скрипта $spell_desc = array(); // Тут хранятся описания спеллов $t_row = 0; // Максимум строк $t_col = 0; // Максимум колонок // Стрелки зависимосей описаны тут $arrows = array('0_1' => array('img' => 'right', 'x' => -14, 'y' => 12), '0_-1' => array('img' => 'left', 'x' => 40, 'y' => 12), '1_-1' => array('img' => 'down-left', 'x' => 14, 'y' => -40), '1_0' => array('img' => 'down-1', 'x' => 13, 'y' => -12), '2_0' => array('img' => 'down-2', 'x' => 13, 'y' => -70), '2_1' => array('img' => 'down2-right', 'x' => -13, 'y' => -94), '2_-1' => array('img' => 'down2-left', 'x' => 14, 'y' => -94), '3_0' => array('img' => 'down-3', 'x' => 13, 'y' => -128), '4_0' => array('img' => 'down-4', 'x' => 13, 'y' => -188), '1_1' => array('img' => 'down-right', 'x' => -13, 'y' => -40)); // Получаем данные о ветках из базы и переводим их в нужный формат if ($class) { $ppr = 5; $talents = $wDB->select('SELECT `TalentID` AS ARRAY_KEY, `TalentTab`, `Row`, `Col`, `Rank_1`, `Rank_2`, `Rank_3`, `Rank_4`, `Rank_5`, `DependsOn`, `DependsOnRank` FROM `wowd_talents` WHERE `TalentTab` IN (?a)', $tab_set); } else { if ($petId >= 0) { $ppr = 3; $petMask1 = 0; $petMask2 = 0; if ($petId < 32) { $petMask1 = 1 << $petId; } else { $petMask2 = 1 << $petId - 32; } $talents = $wDB->select('SELECT `TalentID` AS ARRAY_KEY, `TalentTab`, `Row`, `Col`, `Rank_1`, `Rank_2`, `Rank_3`, `Rank_4`, `Rank_5`, `DependsOn`, `DependsOnRank` FROM `wowd_talents` WHERE `TalentTab` IN (?a) AND ((`petflag1`=0 AND `petflag2`=0) OR (`petflag1`& ?d) OR (`petflag2`& ?d))', $tab_set, $petMask1, $petMask2); } } // Заполняем преборазователь TalentId => TabId и Имена веток талантов foreach ($tab_set as $id => $tid) { $tid_to_tab[$tid] = $id; $tab_name[$id] = getTalentName($tid); } foreach ($talents as $id => $t) { $tabId = $tid_to_tab[$t['TalentTab']]; $row = $t['Row']; $col = $t['Col']; $spells = array(); $icon = 0; $max = 0; if ($t_row <= $row) { $t_row = $row + 1; } if ($t_col <= $col) { $t_col = $col + 1; } for ($i = 1; $i < 6; $i++) { $spellid = $t['Rank_' . $i]; if ($spellid == 0) { continue; } $max = $i; $spells[$i - 1] = $spellid; $spell = getSpell($spellid); if ($icon == 0) { $icon = getSpellIconName($spell['SpellIconID']); } $name = $spell['SpellName']; $spell_desc[$spellid] = array('name' => $name, 'desc' => getSpellDesc($spell)); } $tabs[$tabId . '_' . $row . '_' . $col] = array('id' => $id, 'spells' => $spells, 'icon' => $icon, 'max' => $max); if ($t['DependsOn'] && isset($talents[$t['DependsOn']])) { $d = $talents[$t['DependsOn']]; $dx = $t['Row'] - $d['Row']; $dy = $t['Col'] - $d['Col']; $a = $arrows[$dx . "_" . $dy]; $tabs[$tabId . '_' . $row . '_' . $col]['depend'] = array('id' => $tid_to_tab[$d['TalentTab']] . "_" . $d['Row'] . "_" . $d['Col'], 'rank' => $t['DependsOnRank'], 'img' => $a['img'], 'x' => intval($a['x']), 'y' => intval($a['y'])); } else { $depend = 0; } } echo ' var tc_showclass ="' . ($class ? $class : $tab_set[0]) . '"; var tc_name = ' . php2js($tab_name) . '; var tc_tabs = ' . count($tab_set) . '; var tc_row = ' . $t_row . '; var tc_col = ' . $t_col . '; var tc_tab = ' . php2js($tabs) . '; var tc_point_per_row = ' . $ppr . '; var tc_spell_desc = ' . php2js($spell_desc) . '; var lang_rank = "' . $game_text['talent_rank'] . '"; var lang_next_rank = "' . $game_text['talent_next_rank'] . '"; var lang_req_points = "' . $game_text['talent_req_points'] . '";'; flushJsCache($data_file); } echo ' <script type="text/javascript" id = "talent_calc"> var tc_maxlevel = ' . $maxLevel . '; var lang_header = \'' . $header . '\'; </script> <script type="text/javascript" src="js/talent_calc_base.js"></script>'; }
/** * Function that add a table to the forma to show the main menu * * @author Serafina Molina Soto * @param $id id for the course * @param $id_ejercicio id del ejercicio a mostrar */ function mostrar_ejercicio_identificar_elementos($id, $id_ejercicio, $buscar, $tipo_origen) { //echo "INICIO MOSTRAR EJERCICIO IDENTIFICAR ELEMENTOS"; global $CFG, $COURSE, $USER; $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); //Los iconos están sacados del tema de gnome que viene con ubuntu 11.04 //inclusion del javascript para las funciones $mform =& $this->_form; //echo "COGIDO FORM"; $mform->addElement('html', '<link rel="stylesheet" type="text/css" href="./style.css">'); $mform->addElement('html', '<link rel="stylesheet" type="text/css" href="./estilo.css">'); $mform->addElement('html', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>'); $mform->addElement('html', '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>'); $mform->addElement('html', '<script type="text/javascript" src="./funciones.js"></script>'); //Cojo el ejercicio de la bd a partir de su id (id_ejercicio) //echo "mostrando formulario identificar elementos"; $ejercicios_bd = new Ejercicios_general(); $ejercicios_leido = $ejercicios_bd->obtener_uno($id_ejercicio); $nombre = $ejercicios_leido->get('name'); $npreg = $ejercicios_leido->get('numpreg'); $creador = $ejercicios_leido->get('id_creador'); $tipo_origen = $ejercicios_leido->get('tipoarchivopregunta'); if ($creador == $USER->id && has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) { $modificable = true; } else { $modificable = false; } //$titulo = '<h1 class="instrucciones" ><u>' . $nombre . '</u><span style="font-size:0.7em;float:right;"><i>' . ucwords(strtolower(htmlentities(get_string('Tipo6','ejercicios')))) . '</i></span></h1>'; $titulo = genera_titulos($nombre, get_string('IE_title', 'ejercicios'), $id); $mform->addElement('html', $titulo); $divdescripcion = '<div style="font-size:1.2em" class=descover>'; $divdescripcion .= '<i>' . nl2br(stripslashes($ejercicios_leido->get('descripcion'))); $divdescripcion .= $parte . '<br/></i>'; $divdescripcion .= '</div>'; $mform->addElement('html', $divdescripcion); switch ($tipo_origen) { case 1: //Si es texto //Añado el texto de origen $el_texto_origen = new Ejercicios_textos(); $el_texto_origen->obtener_uno_id_ejercicio($id_ejercicio); //echo "aki entra"; //echo "por lo que estoy en texto texto"; if ($buscar == 1 || $modificable == false) { //Para que no pueda editarlo $divtexto = '<div class="desctexto" name="texto" id="texto"><div class="margenes">' . nl2br(stripslashes($el_texto_origen->get('texto'))) . '</div></div>'; } else { $divtexto = '<textarea class="adaptHeightInput" name="texto" id="texto">' . $el_texto_origen->get('texto') . '</textarea>'; } $mform->addElement('html', $divtexto); break; case 2: // Es audio //Añado el texto de origen $mform->addElement('html', '<script type="text/javascript" src="./mediaplayer/swfobject.js"></script>'); $divaudio = '<div class="claseaudio" id="player1"></div>'; $mform->addElement('html', $divaudio); $mform->addElement('html', '<script type="text/javascript"> var so = new SWFObject("./mediaplayer/mediaplayer.swf","mpl","350","20","7"); so.addParam("allowfullscreen","true"); so.addVariable("file","./mediaplayer/audios/audio' . $id_ejercicio . '.mp3"); so.addVariable("height","20"); so.addVariable("width","320"); so.write("player1"); </script>'); break; case 3: // Es video //Añado el video de origen $el_video_origen = new Ejercicios_videos(); $el_video_origen->obtener_uno_id_ejercicio($id_ejercicio); $vervideo = '<object width="560" height="315" class="video"> <param name="movie" value="http://www.youtube.com/v/' . $el_video_origen->get('video') . '?hl=es_ES&version=3"> </param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param> <embed src="http://www.youtube.com/v/' . $el_video_origen->get('video') . '?hl=es_ES&version=3" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"> </embed></object>'; if ($buscar == 1 || $modificable == false) { //Para que no pueda editarlo $vervideo .= ""; } else { $yvh = YoutubeVideoHelper::generarVideoUrl($el_video_origen->get('video')); $vervideo .= '<textarea class="video" name="archivovideo" id="archivovideo">' . $yvh . '</textarea>'; } $mform->addElement('html', $vervideo); break; } //El tipo respuesta siempre es texto $tabla_imagenes = '<table width="100%">'; $tabla_imagenes .= '<td>'; #columna $mform->addElement('html', $tabla_imagenes); //Obtengo las preguntas $mis_preguntas = new Ejercicios_texto_texto_preg(); $preguntas = $mis_preguntas->obtener_todas_preguntas_ejercicicio($id_ejercicio); //Matrix de las preguntas $matrix_preguntas = array(); for ($i = 1; $i <= sizeof($preguntas); $i++) { //Pinto la pregunta $divpregunta = '<div id="tabpregunta' . $i . '" >'; $divpregunta .= '<br/><br/>'; $divpregunta .= '<table style="width:100%;">'; $divpregunta .= ' <td style="width:80%;">'; // $divpregunta.='<div id="id_pregunta1" name="pregunta1">'; if ($buscar == 1 || $modificable == false) { //Para que no pueda editarlo $divpregunta .= '<div style="width: 900px;" class="pregunta" name="pregunta' . $i . '" id="pregunta' . $i . '">' . $preguntas[$i - 1]->get('pregunta') . '</div>'; } else { $divpregunta .= '<textarea style="width: 900px;" class="pregunta" name="pregunta' . $i . '" id="pregunta' . $i . '">' . $preguntas[$i - 1]->get('pregunta') . '</textarea>'; } // $divpregunta.='<input name="pregunta1" type="text" style="width:80%; height:100%; margin:1%;">ssss</input>'; // $divpregunta.=$preguntas[0]->get('Pregunta'); //$divpregunta.='</div>'; $divpregunta .= ' </td>'; if ($buscar != 1 && $modificable == true) { $divpregunta .= ' <td style="width:5%;">'; $divpregunta .= '<img id="imgpregborrar' . $i . '" src="./imagenes/delete.gif" alt="eliminar respuesta" height="10px" width="10px" onClick="EliminarPregunta_IE(tabpregunta' . $i . ',' . $i . ')" title="Eliminar Pregunta"></img>'; $divpregunta .= '</br><img id="imgpreganadir' . $i . '" src="./imagenes/añadir.gif" alt="eliminar respuesta" height="15px" width="15px" onClick="anadirRespuesta_IE(respuestas' . $i . ',' . $i . ')" title="Añadir Respuesta"></img>'; $divpregunta .= '</td> '; $divpregunta .= '</br> '; } $divpregunta .= '</table> '; //Obtengo las respuestas a la pregunta $id_pregunta = $preguntas[$i - 1]->get('id'); $mis_respuestas = new Ejercicios_ie_respuestas(); $respuestas = $mis_respuestas->obtener_todos_id_pregunta($id_pregunta); //Recoger el texto de las respuestas del profesor desde la base de datos $respuestas_prof = array(); for ($p = 0; $p < sizeof($respuestas); $p++) { //echo "Respuesta del profesor " . ($p+1) . " : " . $respuestas[$p]->get('respuesta') . "<br/>"; $q = $p + 1; $respuestas_prof[] = $respuestas[$p]->get('respuesta'); } $matrix_preguntas[] = $respuestas_prof; $divpregunta .= '</br><div id="respuestas' . $i . '" class=respuesta>'; for ($p = 0; $p < sizeof($respuestas); $p++) { $q = $p + 1; if ($q % 2 == 0 || $q == sizeof($respuestas)) { $divpregunta .= '<table id="tablarespuesta' . $q . '_' . $i . '" style="width:50%;">'; } else { $divpregunta .= '<table id="tablarespuesta' . $q . '_' . $i . '" style="width:50%;float:left;">'; } $divpregunta .= '<tr id="trrespuesta' . $q . "_" . $i . '"> '; $divpregunta .= ' <td style="width:80%;">'; // $divpregunta.='<div class="resp" name="respuesta'.$q."_".$i.'" id="respuesta'.$q."_".$i.'" contentEditable=true>'; // $divpregunta.=$preguntas[$p]->get('Respuesta'); // $divpregunta.='</div>'; if ($buscar == 1 || $modificable == false) { //$divpregunta.='<div style="width: 700px;" class="resp" name="respuesta' . $q . "_" . $i . '" id="respuesta' . $q . "_" . $i . '" value="' . $respuestas[$p]->get('respuesta') . '">' . $respuestas[$p]->get('respuesta') . '</div>'; $divpregunta .= '<textarea style="width: 300px;" class="resp" name="respuesta' . $q . "_" . $i . '" id="respuesta' . $q . "_" . $i . '"></textarea>'; } else { $divpregunta .= '<textarea style="width: 300px;" class="resp" name="respuesta' . $q . "_" . $i . '" id="respuesta' . $q . "_" . $i . '" value="' . $respuestas[$p]->get('respuesta') . '">' . $respuestas[$p]->get('respuesta') . '</textarea>'; } $divpregunta .= ' </td>'; $divpregunta .= ' <td style="width:5%;" id="tdcorregir' . $q . "_" . $i . '">'; if ($buscar != 1 && $modificable == true) { //La imagen para eliminar las respuestas $divpregunta .= '<img id="eliminarrespuesta' . $q . '_' . $i . '" src="./imagenes/delete.gif" alt="eliminar respuesta" height="10px" width="10px" onClick="EliminarRespuesta_IE(tablarespuesta' . $q . '_' . $i . ',' . $i . ')" title="Eliminar Respuesta"></img>'; } $divpregunta .= '</td> '; $divpregunta .= '<tr>'; $divpregunta .= '</table> '; } $divpregunta .= '</div>'; $divpregunta .= '</div>'; $divpregunta .= '<input type="hidden" value=' . sizeof($respuestas) . ' id="num_res_preg' . $i . '" name="num_res_preg' . $i . '" />'; $mform->addElement('html', $divpregunta); //Introduzco el número de respuestas de la pregunta //$mform->addElement('hidden', 'num_res_preg'.$i,$numero_respuestas); } $divnumpregunta = '<input type="hidden" value=' . sizeof($preguntas) . ' id="num_preg" name="num_preg" />'; $mform->addElement('html', $divnumpregunta); //Si soy el dueño del ejercicio y no estoy buscando boton guardar if ($buscar != 1 && $modificable == true) { //Pinto los botones //boton añadir pregunta $botones = '<center><input type="button" style="margin-top:20px;" id="id_Añadir" value="Añadir Pregunta" onclick="javascript:botonMasPreguntas_IE()">'; $botones .= '<input type="submit" style="" id="submitbutton" name="submitbutton" value="' . get_string('BotonGuardar', 'ejercicios') . '"></center>'; $mform->addElement('html', $botones); /* $buttonarray = array(); $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('BotonGuardar','ejercicios')); $mform->addGroup($buttonarray, 'botones', '', array(' '), false); */ } else { if ($buscar == 1) { //Si estoy buscand $ejercicios_prof = new Ejercicios_prof_actividad(); $ejercicios_del_prof = $ejercicios_prof->obtener_uno_idejercicio($id_ejercicio); if (sizeof($ejercicios_del_prof) == 0) { $noagregado = true; } else { $noagregado = false; } //compruebo si soy profesor if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false) && ($modificable == false || $noagregado == true)) { //boton añadir a mis ejercicios $attributes = 'size="40"'; $mform->addElement('text', 'carpeta_ejercicio', get_string('carpeta', 'ejercicios'), $attributes); $mform->addRule('carpeta_ejercicio', "Carpeta Necesaria", 'required', null, 'client'); $buttonarray = array(); $buttonarray[] =& $mform->createElement('submit', 'submitbutton2', get_string('BotonAñadir', 'ejercicios')); $mform->addGroup($buttonarray, 'botones2', '', array(' '), false); //boton menu principal $tabla_menu = '<center><input type="button" style="margin-top:20px;" id="id_Menu" value="Menu Principal" onClick="javascript:botonPrincipal(' . $id . ')" /></center>'; $mform->addElement('html', $tabla_menu); } else { if ($modificable == true) { // Si el ejercicio era mio y estoy buscando $tabla_menu = '<center><input type="button" style="margin-top:20px;" id="id_Menu" value="Menu Principal" onClick="javascript:botonPrincipal(' . $id . ')" /></center>'; $mform->addElement('html', $tabla_menu); } else { //soy alumno $tabla_menu = '<center><input type="button" name="corregirIE" style="margin-top:20px;" value="Corregir" id="id_corregirIE" onClick="javascript:botonCorregirIE(' . $id . "," . php2js($matrix_preguntas) . ')"/> <input type="button" style="" id="id_Menu" value="Menu Principal" onClick="javascript:botonPrincipal(' . $id . ')" /></center>'; $mform->addElement('html', $tabla_menu); } } } else { //Estoy buscando o no // compruebo si soy profesor if (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)) { $tabla_menu = '<center><input type="button" style="margin-top:20px;" id="id_Menu" value="Menu Principal" onClick="javascript:botonPrincipal(' . $id . ')" /></center>'; $mform->addElement('html', $tabla_menu); } else { $tabla_menu = '<center><input type="button" style="margin-top:20px;" value="Corregir" id="id_corregirIE" onClick="javascript:botonCorregirIE(' . $id . "," . php2js($matrix_preguntas) . ')"/> <input type="button" style="" id="id_Atras" value="Atrás" onClick="javascript:botonAtras(' . $id . ')" /><input type="button" style="" id="id_Menu" value="Menu Principal" onClick="javascript:botonPrincipal(' . $id . ')" /></center>'; $mform->addElement('html', $tabla_menu); } } } $tabla_imagenes = '</td>'; $tabla_imagenes .= '<td width="10%">'; //Para alumnos if ($modificable == false) { //Mis palabras $tabla_imagenes .= '<div><a onclick=JavaScript:sele(' . $id . ')><img src="../vocabulario/imagenes/guardar_palabras.png" id="id_guardar_im" name="guardar_im" title="' . get_string('guardar', 'vocabulario') . '"/></a></div>'; $tabla_imagenes .= '<div><a href="../vocabulario/view.php?id=' . $id . '&opcion=5" target="_blank"><img src="../vocabulario/imagenes/administrar_gramaticas.png" id="id_gram_im" name="gram_im" title="' . get_string('admin_gr', 'vocabulario') . '"/></a></div>'; $tabla_imagenes .= '<div><a href="../vocabulario/view.php?id=' . $id . '&opcion=7" target="_blank"><img src="../vocabulario/imagenes/intenciones_comunicativas.png" id="id_ic_im" name="ic_im" title="' . get_string('admin_ic', 'vocabulario') . '"/></a></div>'; $tabla_imagenes .= '<div><a href="../vocabulario/view.php?id=' . $id . '&opcion=9" target="_blank"><img src="../vocabulario/imagenes/tipologias_textuales.png" id="id_tt_im" name="tt_im" title="' . get_string('admin_tt', 'vocabulario') . '"/> </a></div>'; $tabla_imagenes .= '<div><a href="../vocabulario/view.php?id=' . $id . '&opcion=11" target="_blank"><img src="../vocabulario/imagenes/estrategias_icon.png" id="id_ea_im" name="ea_im" title="' . get_string('admin_ea', 'vocabulario') . '"/> </a></div>'; } $tabla_imagenes .= '</td>'; $tabla_imagenes .= '</table>'; $mform->addElement('html', $tabla_imagenes); }
function arr2json($arr) { foreach ($arr as $k => $val) { $json[] = php2js($val); } if (count($json) > 0) { return '[' . implode(',', $json) . ']'; } else { return ''; } }
/** Function: php2js Преобразует php-массив в JSON объект */ function php2js($a = false) { /* {{{ */ if (is_null($a)) { return 'null'; } if ($a === false) { return 'false'; } if ($a === true) { return 'true'; } if (is_scalar($a)) { if (is_float($a)) { // Always use "." for floats. $a = str_replace(",", ".", strval($a)); return $a; } elseif (is_numeric($a)) { return $a; } elseif (is_string($a)) { $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); if (strlen($a)) { return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; } else { return '""'; } } else { return $a; } } $isList = true; $i = 0; foreach ($a as $k => $v) { if ($k !== $i++) { $isList = false; break; } } /* for($i = 0, reset($a); $i < count($a); $i++, next($a)){ if (key($a) !== $i){ $isList = false; break; } } */ $result = array(); if ($isList) { foreach ($a as $v) { $result[] = php2js($v); } return '[' . join(',', $result) . ']'; } else { foreach ($a as $k => $v) { $result[] = php2js($k) . ':' . php2js($v); } return '{' . join(',', $result) . '}'; } /* }}} */ }
</tr> <tr> <td class="skin_left"> <div style="position: relative;"> <div class="skin_leftimg1"></div> <div class="skin_leftimg2"></div> <!-- Left menu here --> <div class="skin_leftmenu" id="leftmenu" align="right"> <?php $left_menu_file = "left_menu_" . $config['lang'] . ".js"; include_once "include/simple_cacher.php"; if (checkUseCacheJs($left_menu_file, 60 * 60 * 24)) { include "site_menu.php"; echo 'var leftmenu = ' . php2js($menu) . ';'; echo 'generateLeftMenu("leftmenu");'; flushJsCache($left_menu_file); } ?> </div> <!-- Left menu end --> </td> <td class="skin_center"> <table class="body" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="bodyleft"></td>
$sExec = $aMatches[0][0]; } if (preg_match_all('/\\$\\w+/', $_POST['ajax_rpc'], $aMatches)) { //dbg($aMatches, 'parameters'); foreach ($aMatches[0] as $k => $v) { $v = substr($v, 1); $aParams[$v] = $_POST[$v]; } } //dbg($aParams, $sExec); $response = ExecDispatcher($sExec, $aParams); if (is_array($response)) { // Все вызываемые функции должны возвращаеть строку или массив // с числовыми ключами, упорядоченными от нуля, // иначе в js пойдет {объект} а не [массив] $response = php2js($response); } echo $response; include_once FLGR_COMMON . '/exit.php'; } // POST if (isset($_POST['act'])) { //dbg($_POST); switch ($_POST['act']) { case 'new': cComponents::create($_POST['name'], $_POST['descr']); break; case 'del': cComponents::del($_POST['id']); break; case 'update':