/** * 广度便利树形目录,找到code=>学科中文名字和树形结构 */ function trivalIndex($url, &$className) { $isReadCache = false; global $cacheDir; $pattern1 = '/<a.*?onclick="ClickNode\\(\'(.*?)\',.*?>(.*?)<\\/a>/'; //目录的根节点 $pattern2 = '/<input type="checkbox" id="selectbox" value="(.*?)".*?name="(.*?)" .*?>/'; //有子目录的节点 $dir = get_code($url); $fileName = "./index/{$cacheDir}/" . $dir . ".html"; $content = ""; if (file_exists($fileName)) { echo "get file {$fileName} from cache\n"; $content = file_get_contents($fileName); $isReadCache = true; } else { echo "get file {$fileName} from network\n"; $content = @file_get_contents($url); save($fileName, $content); $isReadCache = false; } $match = array(); $ret = preg_match_all($pattern1, $content, $match); if (!$ret) { $ret = preg_match_all($pattern2, $content, $match); echo "[WARNNING] use pattern 2\n {$content}\n"; if (!$ret) { //echo "not found $url\n"; save("./index/{$cacheDir}/{$cacheDir}.log", $url . "\n" . $content . "\n\n", "a+"); return; } } $code = $match[1]; $name = $match[2]; for ($i = 0; $i < count($code); $i++) { $namei = $name[$i]; $codei = $code[$i]; //var_dump($codei); echo "\n{$namei} => {$codei}\n"; addCode($namei, $codei); $className[$namei] = array(); $url = replace_code($codei); trivalIndex($url, $className[$namei]); if ($isReadCache == false) { sleep(4); } } }
if (!isset($method)) { $method = 'get'; } $id = $_REQUEST['id']; $email = $_REQUEST['email']; $con = mysql_connect($dbhost, $dbuser, $dbpasswd); if (!$con) { die('{"status":false,"message":"Error connection to db"}'); } mysql_select_db($dbname); switch ($method) { case 'get': get($id); break; case 'post': addCode($email); break; case 'reset': resetUsed($id); break; case 'delete': delete($id); break; } function resetUsed($id) { $query = "UPDATE registration SET used = '0' where id = " . $id; if (mysql_query($query)) { echo '{"status":true}'; } else { echo '{"status":false,"message":"Error executing query to db"}';
function codeDispatch($op) { checkPerm('view'); if (Get::req('undo_group', DOTY_MIXED, '') || Get::req('cancelselector', DOTY_MIXED, '')) { $op = 'list'; } if (Get::req('undo_code', DOTY_MIXED, '')) { $op = 'code_list'; } switch ($op) { case 'add_group_code': addGroupCode(); break; case 'mod_group_code': modGroupCode(); break; case 'del_group_code': delGroupCode(); break; case 'code_list': codeList(); break; case 'add_code': addCode(); break; case 'mod_code': modCode(); break; case 'del_code': delCode(); break; case 'assign_course': assignCourse(); break; case 'assign_tree': assignTree(); break; case 'generate_code': generateCode(); break; case 'import_code': importCode_step1(); break; case 'import_code_2': importCode_step2(); break; case 'export': export(); break; default: case 'list': groupCodeList(); break; } }